X-Git-Url: http://git.cyclocoop.org/?p=burette%2Flhc.git;a=blobdiff_plain;f=lhc.py;h=528034f8f71859943874478d20f10eb1e0bacef7;hp=aefa162d64fbd80382a37d1580bd8a9149f8a652;hb=HEAD;hpb=a1ad8111fe2717ba5fc24c1abfaabf62deaae2fc diff --git a/lhc.py b/lhc.py index aefa162..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-2022 L'Heureux Cyclage () +# (C) 2013-2023 L'Heureux Cyclage () # # This file is a part of lhc_custom_oe # @@ -43,7 +43,7 @@ class res_partner(orm.Model): return res def _bikecoop_activity_dates_check(self, cr, uid, ids, context=None): - #TODO : check condition and return boolean accordingly + # TODO: check condition and return boolean accordingly currentDateTime = datetime.datetime.now() date = currentDateTime.date() year = date.strftime("%Y") @@ -69,6 +69,38 @@ class res_partner(orm.Model): 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', @@ -95,15 +127,18 @@ class res_partner(orm.Model): 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']), ] @@ -200,4 +235,26 @@ class event_registration(orm.Model): 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: