Change days into timedelta overdue

issue5718
review30421002
This commit is contained in:
Xavier Codinas
2016-09-02 10:56:01 +02:00
parent b65b1177e6
commit e2a1b93c7e
6 changed files with 35 additions and 10 deletions
+2
View File
@@ -1,3 +1,5 @@
* Change days into timedelta overdue
Version 4.0.0 - 2016-05-02
* Bug fixes (see mercurial logs for details)
* Add Python3 support
+26 -3
View File
@@ -1,12 +1,14 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from collections import defaultdict
import datetime
from sql import Null
from sql.conditionals import Case
from trytond.model import Model, ModelView, ModelSQL, fields, Unique
from trytond.pyson import If, Eval
from trytond import backend
from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateView, StateAction, StateTransition, \
Button
@@ -31,7 +33,28 @@ class Level(ModelSQL, ModelView):
sequence = fields.Integer('Sequence')
procedure = fields.Many2One('account.dunning.procedure', 'Procedure',
required=True, select=True)
days = fields.Integer('Number of Overdue Days')
overdue = fields.TimeDelta('Overdue')
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().connection.cursor()
table = TableHandler(cls, module_name)
sql_table = cls.__table__()
super(Level, cls).__register__(module_name)
# Migration from 4.0: change days into timedelta overdue
if table.column_exist('days'):
cursor.execute(*sql_table.select(sql_table.id, sql_table.days,
where=sql_table.days != Null))
for id_, days in cursor:
overdue = datetime.timedelta(days)
cursor.execute(*sql_table.update(
[sql_table.days_duration],
[overdue],
where=sql_table.id == id_))
table.drop_column('days')
@classmethod
def __setup__(cls):
@@ -48,8 +71,8 @@ class Level(ModelSQL, ModelView):
self.procedure.rec_name)
def test(self, line, date):
if self.days is not None:
return (date - line.maturity_date).days >= self.days
if self.overdue is not None:
return (date - line.maturity_date) >= self.overdue
_STATES = {
'readonly': Eval('state') != 'draft',
+3 -3
View File
@@ -78,13 +78,13 @@ Create dunning procedure::
>>> procedure = Procedure(name='Procedure')
>>> level = procedure.levels.new()
>>> level.sequence = 1
>>> level.days = 5
>>> level.overdue = datetime.timedelta(5)
>>> level = procedure.levels.new()
>>> level.sequence = 2
>>> level.days = 20
>>> level.overdue = datetime.timedelta(20)
>>> level = procedure.levels.new()
>>> level.sequence = 3
>>> level.days = 40
>>> level.overdue = datetime.timedelta(40)
>>> procedure.save()
Create parties::
+2 -2
View File
@@ -7,6 +7,6 @@ this repository contains the full copyright notices and license terms. -->
<label name="sequence"/>
<field name="sequence"/>
<newline/>
<label name="days"/>
<field name="days"/>
<label name="overdue"/>
<field name="overdue"/>
</form>
+1 -1
View File
@@ -3,5 +3,5 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="procedure" expand="1"/>
<field name="days" expand="1"/>
<field name="overdue" expand="1"/>
</tree>
+1 -1
View File
@@ -3,5 +3,5 @@
this repository contains the full copyright notices and license terms. -->
<tree sequence="sequence">
<field name="procedure" expand="1"/>
<field name="days" expand="1"/>
<field name="overdue" expand="1"/>
</tree>