[Partner] ~year of birth constraints. Must be greater than current year.
[burette/bikecoop.git] / bikecoop.py
1 # -*- coding: utf-8 -*-
2 from osv import fields, osv
3 import openerp.addons.decimal_precision as dp
4 from datetime import date
5
6
7 class Theme(osv.osv):
8 _name = 'bikecoop.partner.theme'
9 _description = 'Themes that could be related to a partner'
10
11 _columns = {
12 'code': fields.char('Code', size=8, help='Code of the occupation'),
13 'name': fields.char('Name', size=128, help='Name of the job or studies', required=True, translate=True),
14 'domain': fields.selection([('gender', 'Gender'), ('occupation', 'Occupation'), ('volunteer', 'Volunteer')], 'Domain', required=True, size=24),
15 'active': fields.boolean('Active', help='If check, this object is always available'),
16 }
17
18 _defaults = {
19 'active': lambda *a: 1,
20 }
21
22 Theme()
23
24
25 class Partner(osv.osv):
26 _inherit = 'res.partner'
27
28 _columns = {
29 'nationality_id': fields.many2one('res.country', 'Nationality', help='Partner\'s nationality if he is a person'),
30 'year': fields.integer('Year of birth', help='This partner year of birth'),
31 'occupation_id': fields.many2one('bikecoop.partner.theme', 'Occupation', help='Main occupation of this partner'),
32 'volunteer_ids': fields.many2many('bikecoop.partner.theme', 'res_partner_bikecoop_theme_rel', 'partner_id', 'theme_id', 'Want to be volunteer?', help='What kind of volunteer activities you want to do with us?'),
33 'gender_id': fields.many2one('bikecoop.partner.theme', 'Gender'),
34 }
35
36 def _check_year(self, cr, uid, ids, context=None):
37 obj = self.browse(cr, uid, ids[0], context=context)
38 if obj.year:
39 if obj.year < 1900 or obj.year > date.today().year:
40 return False
41 return True
42
43 _constraints = [
44 (_check_year, 'Error: this year is not valid.', ['year']),
45 ]
46 Partner()
47
48
49 class product_template(osv.osv):
50 _inherit = 'product.template'
51
52 _columns = {
53 '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,point_of_sale.group_pos_user"),
54 }
55
56 product_template()
57
58
59 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: