diff --git a/CHANGELOG b/CHANGELOG
index 3fd6618c92..3a118f8a6b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/tax.py b/tax.py
index 4e6fe7b9b2..25800ab45b 100644
--- a/tax.py
+++ b/tax.py
@@ -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):
diff --git a/tests/test_account.py b/tests/test_account.py
index 406ea47235..801039f9e7 100644
--- a/tests/test_account.py
+++ b/tests/test_account.py
@@ -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"
diff --git a/view/tax_rule_line_form.xml b/view/tax_rule_line_form.xml
index ccd0c67719..7aa4e84ece 100644
--- a/view/tax_rule_line_form.xml
+++ b/view/tax_rule_line_form.xml
@@ -6,6 +6,10 @@ this repository contains the full copyright notices and license terms. -->
+
+
+
+
diff --git a/view/tax_rule_line_template_form.xml b/view/tax_rule_line_template_form.xml
index fa36abb5fa..63d9eb06d8 100644
--- a/view/tax_rule_line_template_form.xml
+++ b/view/tax_rule_line_template_form.xml
@@ -5,6 +5,10 @@ this repository contains the full copyright notices and license terms. -->
+
+
+
+
diff --git a/view/tax_rule_line_template_tree.xml b/view/tax_rule_line_template_tree.xml
index 70b5d70a49..5189e78e4c 100644
--- a/view/tax_rule_line_template_tree.xml
+++ b/view/tax_rule_line_template_tree.xml
@@ -3,6 +3,8 @@
this repository contains the full copyright notices and license terms. -->
+
+
diff --git a/view/tax_rule_line_tree.xml b/view/tax_rule_line_tree.xml
index 70b5d70a49..5189e78e4c 100644
--- a/view/tax_rule_line_tree.xml
+++ b/view/tax_rule_line_tree.xml
@@ -3,6 +3,8 @@
this repository contains the full copyright notices and license terms. -->
+
+
diff --git a/view/tax_rule_line_tree_sequence.xml b/view/tax_rule_line_tree_sequence.xml
index f40ab385cb..f49b1f2dd9 100644
--- a/view/tax_rule_line_tree_sequence.xml
+++ b/view/tax_rule_line_tree_sequence.xml
@@ -2,6 +2,8 @@
+
+