Add start/end date to tax rule line

issue9505
review317981002
This commit is contained in:
Cédric Krier
2020-09-05 22:12:11 +02:00
parent 28175f11bf
commit 354d99bcb4
8 changed files with 97 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add start/end date to tax rule line
* Test for lines to reconcile before showing the next account
Version 5.6.0 - 2020-05-04
+18
View File
@@ -1418,6 +1418,8 @@ class TaxRuleLineTemplate(sequence_ordered(), ModelSQL, ModelView):
__name__ = 'account.tax.rule.line.template'
rule = fields.Many2One('account.tax.rule.template', 'Rule', required=True,
ondelete='CASCADE')
start_date = fields.Date("Starting Date")
end_date = fields.Date("Ending Date")
group = fields.Many2One('account.tax.group', 'Tax Group',
ondelete='RESTRICT')
origin_tax = fields.Many2One('account.tax.template', 'Original Tax',
@@ -1469,6 +1471,10 @@ class TaxRuleLineTemplate(sequence_ordered(), ModelSQL, ModelView):
Set values for tax rule line creation.
'''
res = {}
if not rule_line or rule_line.start_date != self.start_date:
res['start_date'] = self.start_date
if not rule_line or rule_line.end_date != self.end_date:
res['end_date'] = self.end_date
if not rule_line or rule_line.group != self.group:
res['group'] = self.group.id if self.group else None
if not rule_line or rule_line.sequence != self.sequence:
@@ -1532,6 +1538,8 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
}
rule = fields.Many2One('account.tax.rule', 'Rule', required=True,
select=True, ondelete='CASCADE', states=_states)
start_date = fields.Date("Starting Date")
end_date = fields.Date("Ending Date")
group = fields.Many2One('account.tax.group', 'Tax Group',
ondelete='RESTRICT', states=_states)
origin_tax = fields.Many2One('account.tax', 'Original Tax',
@@ -1597,9 +1605,19 @@ class TaxRuleLine(sequence_ordered(), ModelSQL, ModelView, MatchMixin):
return super(TaxRuleLine, cls).copy(lines, default=default)
def match(self, pattern):
pool = Pool()
Date = pool.get('ir.date')
with Transaction().set_context(company=self.rule.company.id):
today = Date.today()
pattern = pattern.copy()
if 'group' in pattern and not self.group:
if pattern['group']:
return False
date = pattern.pop('date', None) or today
if self.start_date and date < self.start_date:
return False
if self.end_date and date > self.end_date:
return False
return super(TaxRuleLine, self).match(pattern)
def get_taxes(self, origin_tax):
+64
View File
@@ -1286,6 +1286,70 @@ class AccountTestCase(ModuleTestCase):
}])
self.assertListEqual(tax_rule.apply(tax, {}), [target_tax.id])
@with_transaction()
def test_tax_rule_start_date(self):
"Test tax rule start date"
pool = Pool()
TaxRule = pool.get('account.tax.rule')
Tax = pool.get('account.tax')
Date = pool.get('ir.date')
today = Date.today()
yesterday = today - datetime.timedelta(days=1)
tomorrow = today + datetime.timedelta(days=1)
company = create_company()
with set_company(company):
create_chart(company, tax=True)
tax, = Tax.search([])
target_tax, = Tax.copy([tax])
tax_rule, = TaxRule.create([{
'name': "Test",
'kind': 'both',
'lines': [('create', [{
'start_date': today,
'tax': target_tax.id,
}])],
}])
self.assertListEqual(tax_rule.apply(tax, {}), [target_tax.id])
self.assertListEqual(
tax_rule.apply(tax, {'date': yesterday}), [tax.id])
self.assertListEqual(
tax_rule.apply(tax, {'date': tomorrow}), [target_tax.id])
@with_transaction()
def test_tax_rule_end_date(self):
"Test tax rule end date"
pool = Pool()
TaxRule = pool.get('account.tax.rule')
Tax = pool.get('account.tax')
Date = pool.get('ir.date')
today = Date.today()
yesterday = today - datetime.timedelta(days=1)
tomorrow = today + datetime.timedelta(days=1)
company = create_company()
with set_company(company):
create_chart(company, tax=True)
tax, = Tax.search([])
target_tax, = Tax.copy([tax])
tax_rule, = TaxRule.create([{
'name': "Test",
'kind': 'both',
'lines': [('create', [{
'end_date': today,
'tax': target_tax.id,
}])],
}])
self.assertListEqual(tax_rule.apply(tax, {}), [target_tax.id])
self.assertListEqual(
tax_rule.apply(tax, {'date': yesterday}), [target_tax.id])
self.assertListEqual(
tax_rule.apply(tax, {'date': tomorrow}), [tax.id])
@with_transaction()
def test_tax_rule_keep_origin(self):
"Test tax rule keeps origin"
+4
View File
@@ -6,6 +6,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="rule"/>
<label name="template_override"/>
<field name="template_override"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="group"/>
<field name="group"/>
<label name="origin_tax"/>
+4
View File
@@ -5,6 +5,10 @@ this repository contains the full copyright notices and license terms. -->
<label name="rule"/>
<field name="rule"/>
<newline/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="group"/>
<field name="group"/>
<label name="origin_tax"/>
+2
View File
@@ -3,6 +3,8 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="rule" expand="2"/>
<field name="start_date"/>
<field name="end_date"/>
<field name="group"/>
<field name="origin_tax" expand="2"/>
<field name="tax" expand="2"/>
+2
View File
@@ -3,6 +3,8 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="rule" expand="2"/>
<field name="start_date"/>
<field name="end_date"/>
<field name="group"/>
<field name="origin_tax" expand="2"/>
<field name="tax" expand="2"/>
+2
View File
@@ -2,6 +2,8 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree sequence="sequence">
<field name="start_date"/>
<field name="end_date"/>
<field name="group"/>
<field name="origin_tax" expand="2"/>
<field name="tax" expand="2"/>