1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # lhc module for OpenERP, Customize OpenERP for L'Heureux Cyclage Copyright
5 # (C) 2013-2023 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
7 # This file is a part of lhc_custom_oe
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.
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.
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/>.
22 ##############################################################################
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
32 class res_partner(orm
.Model
):
33 _inherit
= 'res.partner'
35 def _get_county(self
, cr
, uid
, ids
, name
, args
, context
=None):
36 """docstring for _county_get_fnc"""
38 for obj
in self
.browse(cr
, uid
, ids
, context
=context
):
40 res
[obj
.id] = obj
.zip[0:2]
45 def _bikecoop_activity_dates_check(self
, cr
, uid
, ids
, context
=None):
46 #TODO : check condition and return boolean accordingly
47 currentDateTime
= datetime
.datetime
.now()
48 date
= currentDateTime
.date()
49 year
= date
.strftime("%Y")
54 for partner
in self
.browse(cr
, uid
, ids
, context
=context
):
55 if partner
.bikecoop_activity_start
== 0 and partner
.bikecoop_activity_stop
== 0:
57 if partner
.bikecoop_activity_start
< 0 or partner
.bikecoop_activity_stop
< 0:
59 if partner
.bikecoop_activity_start
== 0 and partner
.bikecoop_activity_stop
> 0:
61 if partner
.bikecoop_activity_stop
> max_date
or partner
.bikecoop_activity_stop
< min_date
:
62 if partner
.bikecoop_activity_stop
!= 0:
64 if partner
.bikecoop_activity_start
> max_date
or partner
.bikecoop_activity_start
< min_date
:
65 if partner
.bikecoop_activity_start
!= 0:
67 if partner
.bikecoop_activity_stop
< partner
.bikecoop_activity_start
:
68 if partner
.bikecoop_activity_stop
!= 0:
73 'usual_contact': fields
.boolean(
75 help="""This contact is a usual contact for L\'Heureux Cyclage
76 employees. This field can be used to discriminated contacts for
79 'kit_sent': fields
.boolean('Welcome kit sent'),
80 'county_code': fields
.function(
88 lambda self
, cr
, uid
, ids
, c
={}: ids
,
91 'email2': fields
.char(
94 help="""One more email. Warning: there are no email notification
95 with this email. Only the main email can receive notifications."""),
96 'bikecoop_activity_start': fields
.integer('Bikecoop activity start year'),
97 'bikecoop_activity_stop': fields
.integer('Bikecoop activity end year'),
101 'kit_sent': lambda *a
: False,
106 (_bikecoop_activity_dates_check
, 'Error: Bikecoop activity dates are inconsistent!', ['Bikecoop activity dates']),
110 class product_template(orm
.Model
):
111 _inherit
= 'product.template'
114 'standard_price': fields
.float(
116 digits_compute
=dp
.get_precision('Product Price'),
117 help="""Cost price of the product used for standard stock valuation
118 in accounting and used as a base price on purchase orders.",
119 groups="base.group_user,lhc.group_volunteer"""
124 class res_users(orm
.Model
):
125 _inherit
= 'res.users'
127 def onchange_partner_id(self
, cr
, uid
, ids
, partner_id
, login
):
128 """Define user email address from partner email address"""
130 partners
= self
.pool
.get('res.partner')
131 partner
= partners
.browse(cr
, uid
, partner_id
)
133 v
['email'] = partner
.email
139 class event_event(orm
.Model
):
140 _inherit
= 'event.event'
143 'duration': fields
.float(
145 digits_compute
=dp
.get_precision('Product Unit of Measure'),
146 help='Duration in hours'
151 class event_registration(orm
.Model
):
152 _inherit
= 'event.registration'
155 'gender': fields
.selection([
156 ('female', 'Female'),
160 'position': fields
.selection([
161 ('employee', 'Employee'),
162 ('individual', 'Invividual'),
163 ('volunteer', 'Volunteer')],
165 'funding_main': fields
.selection([
166 ('individual', 'Individual'),
168 ('company', 'Company'),
169 ('pole_emploi', 'Pole Emploi')],
170 'Main funding', help='Main funding origin'),
171 'fundings_others': fields
.char('Others fundings origins', size
=128),
172 'sale_order_ids': fields
.many2many(
174 'event_registration_sale_order_rel',
175 'event_registration_id',
177 'Related sale order(s)'
179 'invoice_ids': fields
.many2many(
181 'event_registration_invoice_id_rel',
182 'event_registration_id',
188 def onchange_contact_id(self
, cr
, uid
, ids
, contact
, partner
, context
=None):
189 """Contcat phone with mobile phone if exist. If mobile exist and not
190 phone, add mobile number"""
191 vals
= super(event_registration
, self
).onchange_contact_id(cr
, uid
, ids
, contact
, partner
, context
)
192 addr_obj
= self
.pool
.get('res.partner')
193 contact_id
= addr_obj
.browse(cr
, uid
, contact
, context
=context
)
194 phone
= vals
['value']['phone']
195 mobile
= contact_id
.mobile
198 vals
['value']['phone'] = '%s - %s' % (phone
, mobile
)
200 vals
['value']['phone'] = mobile
204 class hr_expense_line(orm
.Model
):
205 _inherit
= 'hr.expense.line'
207 def onchange_product_id(self
, cr
, uid
, ids
, product_id
, context
=None):
208 """Override to manage default name and ref value based on product
211 vals
= super(hr_expense_line
, self
).onchange_product_id(cr
, uid
, ids
, product_id
, context
)
214 product
= self
.pool
.get('product.product').browse(cr
, uid
, product_id
, context
=context
)
216 if product
.description
:
217 description
= product
.description
.split('|')
218 if len(description
) == 1:
219 res
['name'] = description
[0]
220 elif len(description
) >= 2:
221 res
['name'] = description
[0]
222 res
['ref'] = description
[1]
223 return {'value': res
}
225 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: