changeset 7127d66100b8 in modules/account_dunning:default
details: 
https://hg.tryton.org/modules/account_dunning?cmd=changeset&node=7127d66100b8
description:
        Add date and age to dunning

        issue10722
        review352661002
diffstat:

 CHANGELOG                          |   1 +
 dunning.py                         |  35 ++++++++++++++++++++++++++++++++++-
 tests/scenario_account_dunning.rst |   4 ++++
 view/dunning_form.xml              |   6 ++++++
 view/dunning_list.xml              |   2 ++
 5 files changed, 47 insertions(+), 1 deletions(-)

diffs (144 lines):

diff -r 6d04b7396408 -r 7127d66100b8 CHANGELOG
--- a/CHANGELOG Sat Aug 21 09:09:55 2021 +0200
+++ b/CHANGELOG Thu Sep 23 23:10:33 2021 +0200
@@ -1,3 +1,4 @@
+* Add date and age to dunning
 * Add wizard to reschedule dunning
 
 Version 6.0.0 - 2021-05-03
diff -r 6d04b7396408 -r 7127d66100b8 dunning.py
--- a/dunning.py        Sat Aug 21 09:09:55 2021 +0200
+++ b/dunning.py        Thu Sep 23 23:10:33 2021 +0200
@@ -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 @@
             ('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 @@
     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 @@
                 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 @@
 
     @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 -r 6d04b7396408 -r 7127d66100b8 tests/scenario_account_dunning.rst
--- a/tests/scenario_account_dunning.rst        Sat Aug 21 09:09:55 2021 +0200
+++ b/tests/scenario_account_dunning.rst        Thu Sep 23 23:10:33 2021 +0200
@@ -186,6 +186,7 @@
     True
     >>> dunning.state
     'draft'
+    >>> dunning.date
     >>> dunning.line == dunning_line
     True
 
@@ -197,6 +198,8 @@
     >>> dunning.reload()
     >>> dunning.state
     'waiting'
+    >>> dunning.date == today
+    True
 
 Create dunnings on 30 days with blocked dunning::
 
@@ -231,6 +234,7 @@
     True
     >>> dunning.state
     'draft'
+    >>> dunning.date
     >>> dunning.line == dunning_line
     True
 
diff -r 6d04b7396408 -r 7127d66100b8 view/dunning_form.xml
--- a/view/dunning_form.xml     Sat Aug 21 09:09:55 2021 +0200
+++ b/view/dunning_form.xml     Thu Sep 23 23:10:33 2021 +0200
@@ -10,6 +10,12 @@
     <field name="procedure"/>
     <label name="level"/>
     <field name="level"/>
+
+    <label name="date"/>
+    <field name="date"/>
+    <label name="age"/>
+    <field name="age"/>
+
     <label name="amount"/>
     <group id="amounts" col="-1">
         <field name="amount"/>
diff -r 6d04b7396408 -r 7127d66100b8 view/dunning_list.xml
--- a/view/dunning_list.xml     Sat Aug 21 09:09:55 2021 +0200
+++ b/view/dunning_list.xml     Thu Sep 23 23:10:33 2021 +0200
@@ -8,6 +8,8 @@
     <field name="amount_second_currency"/>
     <field name="maturity_date"/>
     <field name="level" expand="1"/>
+    <field name="age"/>
+    <field name="date" tree_invisible="1"/>
     <field name="blocked"/>
     <field name="state"/>
 </tree>

Reply via email to