[XML][PYTHON][TRANS] +partner county_code field
[burette/lhc.git] / lhc.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # lhc module for OpenERP, Customize OpenERP for L'Heureux Cyclage Copyright
5 # (C) 2013-2020 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
6 #
7 # This file is a part of lhc_custom_oe
8 #
9 # lhc_custom_oe is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # lhc_custom_oe is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ##############################################################################
23
24 from openerp.osv import osv
25 from openerp.osv import orm
26 from openerp.osv import fields
27 import openerp.addons.decimal_precision as dp
28
29
30 class res_partner(orm.Model):
31 _inherit = 'res.partner'
32
33 def _get_county(self, cr, uid, ids, name, args, context=None):
34 """docstring for _county_get_fnc"""
35 res = {}
36 for obj in self.browse(cr, uid, ids, context=context):
37 if obj.zip:
38 res[obj.id] = obj.zip[0:2]
39 else:
40 res[obj.id] = ''
41 return res
42
43 _columns = {
44 'usual_contact': fields.boolean(
45 'Usual contact',
46 help="""This contact is a usual contact for L\'Heureux Cyclage
47 employees. This field can be used to discriminated contacts for
48 differents usages."""
49 ),
50 'kit_sent': fields.boolean('Welcome kit sent'),
51 'county_code': fields.function(
52 _get_county,
53 method=True,
54 string='County code',
55 type='char',
56 size=2,
57 store={
58 'res.partner': (
59 lambda self, cr, uid, ids, c={}: ids,
60 ['zip'], 10)},
61 ),
62 }
63
64 _defaults = {
65 'kit_sent': lambda *a: False,
66 }
67
68
69 class product_template(orm.Model):
70 _inherit = 'product.template'
71
72 _columns = {
73 'standard_price': fields.float(
74 'Cost',
75 digits_compute=dp.get_precision('Product Price'),
76 help="""Cost price of the product used for standard stock valuation
77 in accounting and used as a base price on purchase orders.",
78 groups="base.group_user,lhc.group_volunteer"""
79 ),
80 }
81
82
83 class res_users(orm.Model):
84 _inherit = 'res.users'
85
86 def onchange_partner_id(self, cr, uid, ids, partner_id, login):
87 """Define user email address from partner email address"""
88 v = {}
89 partners = self.pool.get('res.partner')
90 partner = partners.browse(cr, uid, partner_id)
91 if partner.email:
92 v['email'] = partner.email
93 else:
94 v = {}
95 return {'value': v}
96
97
98 class event_event(orm.Model):
99 _inherit = 'event.event'
100
101 _columns = {
102 'duration': fields.float(
103 'Duration',
104 digits_compute=dp.get_precision('Product Unit of Measure'),
105 help='Duration in hours'
106 ),
107 }
108
109
110 class event_registration(orm.Model):
111 _inherit = 'event.registration'
112
113 _columns = {
114 'gender': fields.selection([
115 ('female', 'Female'),
116 ('male', 'Male'),
117 ('other', 'Other')],
118 'Gender'),
119 'position': fields.selection([
120 ('employee', 'Employee'),
121 ('individual', 'Invividual'),
122 ('volunteer', 'Volunteer')],
123 'Position'),
124 'funding_main': fields.selection([
125 ('individual', 'Individual'),
126 ('opco', 'OPCO'),
127 ('company', 'Company'),
128 ('pole_emploi', 'Pole Emploi')],
129 'Main funding', help='Main funding origin'),
130 'fundings_others': fields.char('Others fundings origins', size=128),
131 'sale_order_ids': fields.many2many(
132 'sale.order',
133 'event_registration_sale_order_rel',
134 'event_registration_id',
135 'sale_order_id',
136 'Related sale order(s)'
137 ),
138 'invoice_ids': fields.many2many(
139 'account.invoice',
140 'event_registration_invoice_id_rel',
141 'event_registration_id',
142 'invoice_id',
143 'Related invoice(s)'
144 ),
145 }
146
147 def onchange_contact_id(self, cr, uid, ids, contact, partner, context=None):
148 """Concat phone with mobile phone if exist. If mobile exist and not
149 phone, add mobile number"""
150 vals = super(event_registration, self).onchange_contact_id(cr, uid, ids, contact, partner, context)
151 addr_obj = self.pool.get('res.partner')
152 contact_id = addr_obj.browse(cr, uid, contact, context=context)
153 phone = vals['value']['phone']
154 mobile = contact_id.mobile
155 if mobile:
156 if phone:
157 vals['value']['phone'] = '%s - %s' % (phone, mobile)
158 else:
159 vals['value']['phone'] = mobile
160 return vals
161
162
163 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: