diff --git a/CHANGELOG b/CHANGELOG index c8ff2c8651..476efa805b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add date and age to dunning * Add wizard to reschedule dunning Version 6.0.0 - 2021-05-03 diff --git a/dunning.py b/dunning.py index 6f1694c852..5687b3a6a7 100644 --- a/dunning.py +++ b/dunning.py @@ -3,7 +3,7 @@ from collections import defaultdict import datetime -from sql import Null +from sql import Null, Literal from trytond.model import Model, ModelView, ModelSQL, fields, Unique, \ sequence_ordered @@ -99,6 +99,21 @@ class Dunning(ModelSQL, ModelView): ('procedure', '=', Eval('procedure', -1)), ], states=_STATES, depends=_DEPENDS + ['procedure']) + date = fields.Date( + "Date", readonly=True, + states={ + 'invisible': Eval('state') == 'draft', + }, + depends=['state'], + help="When the dunning reached the level.") + age = fields.Function(fields.TimeDelta( + "Age", + states={ + 'invisible': Eval('state') == 'draft', + }, + depends=['state'], + help="How long the dunning has been at the level."), + 'get_age') blocked = fields.Boolean('Blocked', help="Check to block further levels of the procedure.") state = fields.Selection([ @@ -168,6 +183,19 @@ class Dunning(ModelSQL, ModelView): def default_state(): return 'draft' + def get_age(self, name): + pool = Pool() + Date = pool.get('ir.date') + if self.date: + return Date.today() - self.date + + @classmethod + def order_age(cls, tables): + pool = Pool() + Date = pool.get('ir.date') + table, _ = tables[None] + return [Literal(Date.today()) - table.date] + def get_active(self, name): return not self.line.reconciliation @@ -262,10 +290,12 @@ class Dunning(ModelSQL, ModelView): to_write.extend((dunnings, { 'level': level.id, 'state': 'draft', + 'date': None, })) else: to_write.extend((dunnings, { 'state': 'final', + 'date': Date.today(), })) if to_write: cls.write(*to_write) @@ -294,9 +324,12 @@ class Dunning(ModelSQL, ModelView): @classmethod def process(cls, dunnings): + pool = Pool() + Date = pool.get('ir.date') cls.write([d for d in dunnings if not d.blocked and d.state == 'draft'], { 'state': 'waiting', + 'date': Date.today(), }) @classmethod diff --git a/tests/scenario_account_dunning.rst b/tests/scenario_account_dunning.rst index cd9ee4630f..ec14bfb901 100644 --- a/tests/scenario_account_dunning.rst +++ b/tests/scenario_account_dunning.rst @@ -186,6 +186,7 @@ Create dunnings on 30 days with draft dunning:: True >>> dunning.state 'draft' + >>> dunning.date >>> dunning.line == dunning_line True @@ -197,6 +198,8 @@ Process dunning:: >>> dunning.reload() >>> dunning.state 'waiting' + >>> dunning.date == today + True Create dunnings on 30 days with blocked dunning:: @@ -231,6 +234,7 @@ Create dunnings on 30 days:: True >>> dunning.state 'draft' + >>> dunning.date >>> dunning.line == dunning_line True diff --git a/view/dunning_form.xml b/view/dunning_form.xml index a08e82e1a8..d4405bc129 100644 --- a/view/dunning_form.xml +++ b/view/dunning_form.xml @@ -10,6 +10,12 @@ this repository contains the full copyright notices and license terms. -->