X-Git-Url: http://git.cyclocoop.org/?p=burette%2Flhc.git;a=blobdiff_plain;f=lhc.py;h=528034f8f71859943874478d20f10eb1e0bacef7;hp=8a7435a882e78f3146422afc9da8ac7454df5f8e;hb=HEAD;hpb=15fd6b3f8ebacb75a93256ba4da64a8bdb896e3c diff --git a/lhc.py b/lhc.py index 8a7435a..6d5398e 100644 --- a/lhc.py +++ b/lhc.py @@ -2,7 +2,7 @@ ############################################################################## # # lhc module for OpenERP, Customize OpenERP for L'Heureux Cyclage Copyright -# (C) 2013-2017 L'Heureux Cyclage () +# (C) 2013-2023 L'Heureux Cyclage () # # This file is a part of lhc_custom_oe # @@ -24,23 +24,237 @@ from openerp.osv import osv from openerp.osv import orm from openerp.osv import fields - +from openerp.tools.translate import _ import openerp.addons.decimal_precision as dp +import datetime + class res_partner(orm.Model): _inherit = 'res.partner' + def _get_county(self, cr, uid, ids, name, args, context=None): + """docstring for _county_get_fnc""" + res = {} + for obj in self.browse(cr, uid, ids, context=context): + if obj.zip: + res[obj.id] = obj.zip[0:2] + else: + res[obj.id] = '' + return res + + def _bikecoop_activity_dates_check(self, cr, uid, ids, context=None): + # TODO: check condition and return boolean accordingly + currentDateTime = datetime.datetime.now() + date = currentDateTime.date() + year = date.strftime("%Y") + + min_date = 1950 + max_date = int(year) + + for partner in self.browse(cr, uid, ids, context=context): + if partner.bikecoop_activity_start == 0 and partner.bikecoop_activity_stop == 0: + return True + if partner.bikecoop_activity_start < 0 or partner.bikecoop_activity_stop < 0: + return False + if partner.bikecoop_activity_start == 0 and partner.bikecoop_activity_stop > 0: + return False + if partner.bikecoop_activity_stop > max_date or partner.bikecoop_activity_stop < min_date: + if partner.bikecoop_activity_stop != 0: + return False + if partner.bikecoop_activity_start > max_date or partner.bikecoop_activity_start < min_date: + if partner.bikecoop_activity_start != 0: + return False + if partner.bikecoop_activity_stop < partner.bikecoop_activity_start: + if partner.bikecoop_activity_stop != 0: + return False + return True + + def _rna_check(self, cr, uid, ids, context=None): + """Check if RNA code is well formatted""" + for partner in self.browse(cr, uid, ids, context=context): + if partner.rna: + if len(partner.rna) != 10: + return False + if partner.rna[0] != 'W': + return False + try: + int(partner.rna[1:10]) + except ValueError: + return False + return True + else: + return True + + + def _siret_check(self, cr, uid, ids, context=None): + """Check if SIRET code is well formatted""" + for partner in self.browse(cr, uid, ids, context=context): + if partner.siret: + if len(partner.siret) != 14: + return False + try: + int(partner.siret) + except ValueError: + return False + return True + else: + return True + + _columns = { - 'usual_contact': fields.boolean('Usual contact', help='This contact is a usual contact for L\'Heureux Cyclage employees. This field can be used to discriminated contacts for differents usages.'), + 'usual_contact': fields.boolean( + 'Usual contact', + help="""This contact is a usual contact for L\'Heureux Cyclage + employees. This field can be used to discriminated contacts for + differents usages.""" + ), 'kit_sent': fields.boolean('Welcome kit sent'), + 'county_code': fields.function( + _get_county, + method=True, + string='County code', + type='char', + size=2, + store={ + 'res.partner': ( + lambda self, cr, uid, ids, c={}: ids, + ['zip'], 10)}, + ), + 'email2': fields.char( + 'Secondary email', + size=240, + help="""One more email. Warning: there are no email notification + with this email. Only the main email can receive notifications."""), + 'bikecoop_activity_start': fields.integer('Bikecoop activity start year'), + 'bikecoop_activity_stop': fields.integer('Bikecoop activity end year'), + 'rna': fields.char('RNA code', size=10), + 'siret': fields.char('SIRET', size=14), + } + + _defaults = { + 'kit_sent': lambda *a: False, } + _constraints = [ + (_bikecoop_activity_dates_check, 'Error: Bikecoop activity dates are inconsistent!', ['Bikecoop activity dates']), + (_rna_check, 'Error: RNA code must begin with a "W" followed by exactly 9 digits.', ['RNA']), + (_siret_check, 'Error: SIRET must take exactly 14 digits.', ['SIRET']), + ] + + class product_template(orm.Model): _inherit = 'product.template' _columns = { - 'standard_price': fields.float('Cost', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.", groups="base.group_user,lhc.group_volunteer"), + 'standard_price': fields.float( + 'Cost', + digits_compute=dp.get_precision('Product Price'), + help="""Cost price of the product used for standard stock valuation + in accounting and used as a base price on purchase orders.", + groups="base.group_user,lhc.group_volunteer""" + ), } +class res_users(orm.Model): + _inherit = 'res.users' + + def onchange_partner_id(self, cr, uid, ids, partner_id, login): + """Define user email address from partner email address""" + v = {} + partners = self.pool.get('res.partner') + partner = partners.browse(cr, uid, partner_id) + if partner.email: + v['email'] = partner.email + else: + v = {} + return {'value': v} + + +class event_event(orm.Model): + _inherit = 'event.event' + + _columns = { + 'duration': fields.float( + 'Duration', + digits_compute=dp.get_precision('Product Unit of Measure'), + help='Duration in hours' + ), + } + + +class event_registration(orm.Model): + _inherit = 'event.registration' + + _columns = { + 'gender': fields.selection([ + ('female', 'Female'), + ('male', 'Male'), + ('other', 'Other')], + 'Gender'), + 'position': fields.selection([ + ('employee', 'Employee'), + ('individual', 'Invividual'), + ('volunteer', 'Volunteer')], + 'Position'), + 'funding_main': fields.selection([ + ('individual', 'Individual'), + ('opco', 'OPCO'), + ('company', 'Company'), + ('pole_emploi', 'Pole Emploi')], + 'Main funding', help='Main funding origin'), + 'fundings_others': fields.char('Others fundings origins', size=128), + 'sale_order_ids': fields.many2many( + 'sale.order', + 'event_registration_sale_order_rel', + 'event_registration_id', + 'sale_order_id', + 'Related sale order(s)' + ), + 'invoice_ids': fields.many2many( + 'account.invoice', + 'event_registration_invoice_id_rel', + 'event_registration_id', + 'invoice_id', + 'Related invoice(s)' + ), + } + + def onchange_contact_id(self, cr, uid, ids, contact, partner, context=None): + """Contcat phone with mobile phone if exist. If mobile exist and not + phone, add mobile number""" + vals = super(event_registration, self).onchange_contact_id(cr, uid, ids, contact, partner, context) + addr_obj = self.pool.get('res.partner') + contact_id = addr_obj.browse(cr, uid, contact, context=context) + phone = vals['value']['phone'] + mobile = contact_id.mobile + if mobile: + if phone: + vals['value']['phone'] = '%s - %s' % (phone, mobile) + else: + vals['value']['phone'] = mobile + return vals + + +class hr_expense_line(orm.Model): + _inherit = 'hr.expense.line' + + def onchange_product_id(self, cr, uid, ids, product_id, context=None): + """Override to manage default name and ref value based on product + properties""" + + vals = super(hr_expense_line, self).onchange_product_id(cr, uid, ids, product_id, context) + res = vals['value'] + if product_id: + product = self.pool.get('product.product').browse(cr, uid, product_id, context=context) + res['ref'] = '' + if product.description: + description = product.description.split('|') + if len(description) == 1: + res['name'] = description[0] + elif len(description) >= 2: + res['name'] = description[0] + res['ref'] = description[1] + return {'value': res} + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: