##############################################################################
#
# lhc module for OpenERP, Customize OpenERP for L'Heureux Cyclage Copyright
-# (C) 2013-2020 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
+# (C) 2013-2022 L'Heureux Cyclage (<http://www.heureux-cyclage.org>)
#
# This file is a part of lhc_custom_oe
#
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
+
_columns = {
'usual_contact': fields.boolean(
'Usual contact',
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'),
}
_defaults = {
}
+ _constraints = [
+ (_bikecoop_activity_dates_check, 'Error: Bikecoop activity dates are inconsistent!', ['Bikecoop activity dates']),
+ ]
+
+
class product_template(orm.Model):
_inherit = 'product.template'
v = {}
partners = self.pool.get('res.partner')
partner = partners.browse(cr, uid, partner_id)
- import pdb
- pdb.set_trace()
if partner.email:
v['email'] = partner.email
else:
}
def onchange_contact_id(self, cr, uid, ids, contact, partner, context=None):
- """Concat phone with mobile phone if exist. If mobile exist and not
+ """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
- import pdb
- pdb.set_trace()
if mobile:
if phone:
vals['value']['phone'] = '%s - %s' % (phone, mobile)
vals['value']['phone'] = mobile
return vals
-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: