Commits

kantntreiber committed d4efa26

Reset the dunning status if the dunning procedure is changed

Comments (0)

Files changed (2)

 
         return super(Line, self).create(vals)
 
+    def write(self, ids, vals):
+        '''
+        Reset the dunning status of the line if the dunning procedure is
+        changed.
+        '''
+        dunning_obj = Pool().get('account.dunning.dunning')
+
+        if 'dunning_procedure' in vals:
+            for line in self.browse(ids):
+                if line.dunning_procedure.id != vals['dunning_procedure']:
+                    dunning_ids = dunning_obj.search([('line', '=', line.id)])
+                    dunning_obj.delete(dunning_ids)
+
+        return super(Line, self).write(ids, vals)
+
     def copy(self, ids, default=None):
         if default is None:
             default = {}

tests/test_account_dunning.py

                     .dunning_run(procedure_id, base_date + dt.timedelta(100))
             self.assertEqual(dunned_ids, [])
 
+            # reset the dunning procedure
+            self.line.write([line_id], {'dunning_procedure': None})
+            self.assertEqual(self.dunning.search([]), [])
+
 
 def suite():
     suite = trytond.tests.test_tryton.suite()