Add date and age to dunning

issue10722
review352661002
This commit is contained in:
Cédric Krier
2021-09-23 23:10:33 +02:00
parent 1d843bd7cd
commit 44825fc673
5 changed files with 47 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add date and age to dunning
* Add wizard to reschedule dunning
Version 6.0.0 - 2021-05-03
+34 -1
View File
@@ -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
+4
View File
@@ -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
+6
View File
@@ -10,6 +10,12 @@ this repository contains the full copyright notices and license terms. -->
<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"/>
+2
View File
@@ -8,6 +8,8 @@ this repository contains the full copyright notices and license terms. -->
<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>