[PYTHON][VIEW] +secondary email for partners
[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-2022 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 from openerp.tools.translate import _
28 import openerp.addons.decimal_precision as dp
29
30
31 class res_partner(orm.Model):
32 _inherit = 'res.partner'
33
34 def _get_county(self, cr, uid, ids, name, args, context=None):
35 """docstring for _county_get_fnc"""
36 res = {}
37 for obj in self.browse(cr, uid, ids, context=context):
38 if obj.zip:
39 res[obj.id] = obj.zip[0:2]
40 else:
41 res[obj.id] = ''
42 return res
43
44 _columns = {
45 'usual_contact': fields.boolean(
46 'Usual contact',
47 help="""This contact is a usual contact for L\'Heureux Cyclage
48 employees. This field can be used to discriminated contacts for
49 differents usages."""
50 ),
51 'kit_sent': fields.boolean('Welcome kit sent'),
52 'county_code': fields.function(
53 _get_county,
54 method=True,
55 string='County code',
56 type='char',
57 size=2,
58 store={
59 'res.partner': (
60 lambda self, cr, uid, ids, c={}: ids,
61 ['zip'], 10)},
62 ),
63 'email2': fields.char(
64 'Secondary email',
65 size=240,
66 help="""One more email. Warning: there are no email notification
67 with this email. Only the main email can receive notifications."""),
68 }
69
70 _defaults = {
71 'kit_sent': lambda *a: False,
72 }
73
74
75 class product_template(orm.Model):
76 _inherit = 'product.template'
77
78 _columns = {
79 'standard_price': fields.float(
80 'Cost',
81 digits_compute=dp.get_precision('Product Price'),
82 help="""Cost price of the product used for standard stock valuation
83 in accounting and used as a base price on purchase orders.",
84 groups="base.group_user,lhc.group_volunteer"""
85 ),
86 }
87
88
89 class res_users(orm.Model):
90 _inherit = 'res.users'
91
92 def onchange_partner_id(self, cr, uid, ids, partner_id, login):
93 """Define user email address from partner email address"""
94 v = {}
95 partners = self.pool.get('res.partner')
96 partner = partners.browse(cr, uid, partner_id)
97 if partner.email:
98 v['email'] = partner.email
99 else:
100 v = {}
101 return {'value': v}
102
103
104 class event_event(orm.Model):
105 _inherit = 'event.event'
106
107 _columns = {
108 'duration': fields.float(
109 'Duration',
110 digits_compute=dp.get_precision('Product Unit of Measure'),
111 help='Duration in hours'
112 ),
113 }
114
115
116 class event_registration(orm.Model):
117 _inherit = 'event.registration'
118
119 _columns = {
120 'gender': fields.selection([
121 ('female', 'Female'),
122 ('male', 'Male'),
123 ('other', 'Other')],
124 'Gender'),
125 'position': fields.selection([
126 ('employee', 'Employee'),
127 ('individual', 'Invividual'),
128 ('volunteer', 'Volunteer')],
129 'Position'),
130 'funding_main': fields.selection([
131 ('individual', 'Individual'),
132 ('opco', 'OPCO'),
133 ('company', 'Company'),
134 ('pole_emploi', 'Pole Emploi')],
135 'Main funding', help='Main funding origin'),
136 'fundings_others': fields.char('Others fundings origins', size=128),
137 'sale_order_ids': fields.many2many(
138 'sale.order',
139 'event_registration_sale_order_rel',
140 'event_registration_id',
141 'sale_order_id',
142 'Related sale order(s)'
143 ),
144 'invoice_ids': fields.many2many(
145 'account.invoice',
146 'event_registration_invoice_id_rel',
147 'event_registration_id',
148 'invoice_id',
149 'Related invoice(s)'
150 ),
151 }
152
153 def onchange_contact_id(self, cr, uid, ids, contact, partner, context=None):
154 """Contcat phone with mobile phone if exist. If mobile exist and not
155 phone, add mobile number"""
156 vals = super(event_registration, self).onchange_contact_id(cr, uid, ids, contact, partner, context)
157 addr_obj = self.pool.get('res.partner')
158 contact_id = addr_obj.browse(cr, uid, contact, context=context)
159 phone = vals['value']['phone']
160 mobile = contact_id.mobile
161 if mobile:
162 if phone:
163 vals['value']['phone'] = '%s - %s' % (phone, mobile)
164 else:
165 vals['value']['phone'] = mobile
166 return vals
167
168 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: