[PYTHON] ~concatenate partner mobile and phone number on event registration
[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 _columns = {
34 'usual_contact': fields.boolean(
35 'Usual contact',
36 help="""This contact is a usual contact for L\'Heureux Cyclage
37 employees. This field can be used to discriminated contacts for
38 differents usages."""
39 ),
40 'kit_sent': fields.boolean('Welcome kit sent'),
41 }
42
43 _defaults = {
44 'kit_sent': lambda *a: False,
45 }
46
47
48 class product_template(orm.Model):
49 _inherit = 'product.template'
50
51 _columns = {
52 'standard_price': fields.float(
53 'Cost',
54 digits_compute=dp.get_precision('Product Price'),
55 help="""Cost price of the product used for standard stock valuation
56 in accounting and used as a base price on purchase orders.",
57 groups="base.group_user,lhc.group_volunteer"""
58 ),
59 }
60
61
62 class res_users(orm.Model):
63 _inherit = 'res.users'
64
65 def onchange_partner_id(self, cr, uid, ids, partner_id, login):
66 """Define user email address from partner email address"""
67 v = {}
68 partners = self.pool.get('res.partner')
69 partner = partners.browse(cr, uid, partner_id)
70 import pdb
71 pdb.set_trace()
72 if partner.email:
73 v['email'] = partner.email
74 else:
75 v = {}
76 return {'value': v}
77
78
79 class event_event(orm.Model):
80 _inherit = 'event.event'
81
82 _columns = {
83 'duration': fields.float(
84 'Duration',
85 digits_compute=dp.get_precision('Product Unit of Measure'),
86 help='Duration in hours'
87 ),
88 }
89
90
91 class event_registration(orm.Model):
92 _inherit = 'event.registration'
93
94 _columns = {
95 'gender': fields.selection([
96 ('female', 'Female'),
97 ('male', 'Male'),
98 ('other', 'Other')],
99 'Gender'),
100 'position': fields.selection([
101 ('employee', 'Employee'),
102 ('individual', 'Invividual'),
103 ('volunteer', 'Volunteer')],
104 'Position'),
105 'funding_main': fields.selection([
106 ('individual', 'Individual'),
107 ('opco', 'OPCO'),
108 ('company', 'Company'),
109 ('pole_emploi', 'Pole Emploi')],
110 'Main funding', help='Main funding origin'),
111 'fundings_others': fields.char('Others fundings origins', size=128),
112 'sale_order_ids': fields.many2many(
113 'sale.order',
114 'event_registration_sale_order_rel',
115 'event_registration_id',
116 'sale_order_id',
117 'Related sale order(s)'
118 ),
119 'invoice_ids': fields.many2many(
120 'account.invoice',
121 'event_registration_invoice_id_rel',
122 'event_registration_id',
123 'invoice_id',
124 'Related invoice(s)'
125 ),
126 }
127
128 def onchange_contact_id(self, cr, uid, ids, contact, partner, context=None):
129 """Concat phone with mobile phone if exist. If mobile exist and not
130 phone, add mobile number"""
131 vals = super(event_registration, self).onchange_contact_id(cr, uid, ids, contact, partner, context)
132 addr_obj = self.pool.get('res.partner')
133 contact_id = addr_obj.browse(cr, uid, contact, context=context)
134 phone = vals['value']['phone']
135 mobile = contact_id.mobile
136 import pdb
137 pdb.set_trace()
138 if mobile:
139 if phone:
140 vals['value']['phone'] = '%s - %s' % (phone, mobile)
141 else:
142 vals['value']['phone'] = mobile
143 return vals
144
145
146 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: