[Partner] +real date type for birthdate field and add to bikecoop membership form...
[burette/velosenville.git] / res_partner.py
diff --git a/res_partner.py b/res_partner.py
new file mode 100644 (file)
index 0000000..db7aa43
--- /dev/null
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    velosenville module for OpenERP, Vélos en Ville specificities
+#    Copyright (C) 2012-2013 Vélos en Ville (<http://www.velosenville.org>)
+#
+#    This file is a part of velosenville
+#
+#    velosenville is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    velosenville is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from openerp.osv import osv
+from openerp.osv import fields
+from datetime import date
+
+
+class res_partner(osv.osv):
+    _inherit = 'res.partner'
+
+    _columns = {
+        #Overload birthdate field to have date format. Don't know why it's char type in mainstream version
+        'birthdate': fields.date('Birthdate'),
+    }
+
+    def _check_birthdate(self, cr, uid, ids, context=None):
+        obj = self.browse(cr, uid, ids[0], context=context)
+        if obj.birthdate:
+            if obj.birthdate < '1900-01-01' or obj.birthdate > str(date.today()):
+                return False
+        return True
+
+    _constraints = [
+        (_check_birthdate, 'Error: this birthdate is not valid.', ['birthdate']),
+    ]
+res_partner()
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: