[PYTHON][VIEW] +newsletter subscription …
[burette/etudesetchantiersidf.git] / etudesetchantiersidf.py
index d95ee9a..cf00b40 100644 (file)
@@ -72,8 +72,25 @@ class Partner(osv.osv):
                 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['free_member'], 10)
                 }
             ),
+        'newsletter': fields.boolean('Want to subsribe to the newsletter?'),
     }
 
+    _defaults = {
+        'newsletter': lambda *a: True,
+    }
+
+    def _check_email(self, cr, uid, ids, context=None):
+        #TODO : check condition and return boolean accordingly
+        if context is None:
+            context = {}
+        for partner in self.browse(cr, uid, ids, context=context):
+            if partner.newsletter and not partner.email:
+                return False
+        return True
+
+    _constraints = [
+        (_check_email, 'Error: you can\'t subscribe to the newsletter without email!', ['newsletter']),
+    ]
 Partner()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: