[PYTHON] cleanup
[burette/remembership.git] / remembership.py
index ad6438f..ca1070c 100644 (file)
@@ -105,6 +105,35 @@ class Partner(osv.osv):
             list_partner += ids2
         return list_partner
 
+
+    def _membership_state(self, cr, uid, ids, name, args, context=None):
+        res = super(Partner, self)._membership_state(cr, uid, ids, name, args, context)
+        today = time.strftime('%Y-%m-%d')
+
+        # special case when the partner is imported from a file,
+        # in this case is has a valid membership line but
+        # no payment information associated to it, consider it valid
+        for id in ids:
+            if res[id] == 'none':
+
+                partner_data = self.browse(cr, uid, id, context=context)
+
+                no_payment_info_at_all = True
+                valid_line = False
+
+                for mline in partner_data.member_lines:
+                    if mline.date_to >= today:
+                        valid_line = True
+
+                    if mline.account_invoice_line:
+                        no_payment_info_at_all = False
+
+                if no_payment_info_at_all and valid_line:
+                    res[id] = 'paid'
+
+        return res
+
+
     _columns = {
         'member_ident': fields.char('Member identifier', size=64),
         'associate_members': fields.one2many('res.partner', 'associate_member', 'Associate members', help='Members who are associated to this partner.'),