Skip to content

Commit 7b75ed8

Browse files
committed
[FIX] account: tax lock tags
Despite the tax lock date, users are able to modify the tax report by adding tags. Steps to reproduce: Ensure the tax lock date is set 1. Journal Items list view 2. Edit one/many lines that - have a date before the tax lock date, - don't have a tax, - nor tax tags, - and is not a tax line. 3. Add a new tax tag Issue: The tax tags are added and might impact a tax report, when you should have received a user error. Cause: The `write` function calls the `_check_tax_lock_date` which in turn only checks the existing line instead of the values given in the `write` parameters. Since the line has no existing tax tags the check does not fail. Solution: Call the tax lock check both before and after writing the move line. Task-5169152 closes odoo#233317 X-original-commit: e1c37c1 Signed-off-by: William André (wan) <wan@odoo.com> Signed-off-by: Habib Ayob (ayh) <ayh@odoo.com>
1 parent 635f359 commit 7b75ed8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

addons/account/models/account_move_line.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ def write(self, vals):
17011701
matching2lines = None # lazy cache
17021702
lines_to_unreconcile = self.env['account.move.line']
17031703
st_lines_to_unreconcile = self.env['account.bank.statement.line']
1704+
tax_lock_check_ids = []
17041705
for line in self:
17051706
if not any(self.env['account.move']._field_will_change(line, vals, field_name) for field_name in vals):
17061707
line_to_write -= line
@@ -1715,7 +1716,7 @@ def write(self, vals):
17151716

17161717
# Check the tax lock date.
17171718
if line.parent_state == 'posted' and any(self.env['account.move']._field_will_change(line, vals, field_name) for field_name in protected_fields['tax']):
1718-
line._check_tax_lock_date()
1719+
tax_lock_check_ids.append(line.id)
17191720

17201721
# Break the reconciliation.
17211722
if (
@@ -1744,6 +1745,8 @@ def write(self, vals):
17441745
st_lines_to_unreconcile -= st_line
17451746
st_lines_to_unreconcile.action_undo_reconciliation()
17461747

1748+
self.browse(tax_lock_check_ids)._check_tax_lock_date()
1749+
17471750
move_container = {'records': self.move_id}
17481751
with self.move_id._check_balanced(move_container),\
17491752
self.env.protecting(self.env['account.move']._get_protected_vals(vals, self)),\
@@ -1778,6 +1781,9 @@ def write(self, vals):
17781781
if any(field in vals for field in ['account_id', 'currency_id']):
17791782
self._check_constrains_account_id_journal_id()
17801783

1784+
# double check modified lines in case a tax field was changed on a line that didn't previously affect tax
1785+
self.browse(tax_lock_check_ids)._check_tax_lock_date()
1786+
17811787
if not self.env.context.get('tracking_disable', False):
17821788
# Log changes to move lines on each move
17831789
for move_id, modified_lines in move_initial_values.items():

addons/account/tests/test_account_move_out_invoice.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ def setUp(self):
143143
self.term_line_vals_1,
144144
], self.move_vals)
145145

146+
def test_basic_tax_lock(self):
147+
tax_tag = self.env['account.account.tag'].create({'name': 'HiddenFromIRS', 'applicability': 'taxes'})
148+
inv = self.init_invoice('out_invoice', amounts=[10], post=True)
149+
inv.company_id.tax_lock_date = inv.date
150+
with self.assertRaisesRegex(UserError, 'lock date'):
151+
inv.line_ids.tax_tag_ids = tax_tag.ids
152+
146153
@freeze_time('2020-01-15')
147154
def test_out_invoice_onchange_invoice_date(self):
148155
for tax_date, invoice_date, accounting_date in [

0 commit comments

Comments
 (0)