[Partner] +real date type for birthdate field and add to bikecoop membership form...
authorLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Tue, 12 Mar 2013 19:35:48 +0000 (20:35 +0100)
committerLudovic CHEVALIER <ludovic.chevalier@heureux-cyclage.org>
Tue, 12 Mar 2013 19:35:48 +0000 (20:35 +0100)
__init__.py
__openerp__.py
res_partner.py [new file with mode: 0644]
view/bikecoop.xml [new file with mode: 0644]

index e078f98..e563ffa 100644 (file)
@@ -20,5 +20,6 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
+import res_partner
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
index 7207cc5..d2740fb 100644 (file)
@@ -41,6 +41,7 @@ It installs the profile for bike co-ops to manage some features like:
         'data/bikecoop.xml',
         'data/product.xml',
         'data/res_partner.xml',
+        'view/bikecoop.xml',
     ],
     'installable': True,
     'auto_install': False,
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:
diff --git a/view/bikecoop.xml b/view/bikecoop.xml
new file mode 100644 (file)
index 0000000..f827c9a
--- /dev/null
@@ -0,0 +1,14 @@
+<openerp>
+    <data>
+        <record id="view_bikecoop_members_form" model="ir.ui.view">
+            <field name="name">res.partner.form</field>
+            <field name="model">res.partner</field>
+            <field name="inherit_id" ref="bikecoop.view_bikecoop_members_form"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='year']" position="replace">
+                    <field name="birthdate" attrs="{'required': [('is_company','=', False)]}"/>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>