[PYTHON][VIEW][TRANS] +rna and siren field for companies
[burette/lhc.git] / lhc.py
diff --git a/lhc.py b/lhc.py
index 27e1462..a862953 100644 (file)
--- a/lhc.py
+++ b/lhc.py
@@ -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 _siren_check(self, cr, uid, ids, context=None):
+        """Check if SIREN code is well formatted"""
+        for partner in self.browse(cr, uid, ids, context=context):
+            if partner.siren:
+                if len(partner.siren) != 9:
+                    return False
+                try:
+                    int(partner.siren)
+                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),
+        'siren': fields.char('SIREN', size=9),
     }
 
     _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']),
+        (_siren_check, 'Error: SIREN must take exactly 10 digits.', ['SIREN']),
     ]