summaryrefslogtreecommitdiff
path: root/addons/account/models
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2020-07-29 06:40:58 +0000
committerNicolas Martinelli <nim@odoo.com>2020-07-30 08:49:10 +0000
commitdcf1f48ee6729780d1d8a4fb88bf23138744ae76 (patch)
tree63ecb97a9713305943bebdf1b0df803aec42a87b /addons/account/models
parent8b7861ddabf92f85aff7665cb5bd79922676f545 (diff)
[FIX] account: prevent unlink item linked to posted entry
- Create a vendor bill, post it - Go to Accounting > Accounting > Journals > Purchases - Select the items linked to the vendor bill, delete Nothing prevents from deleting the items while a posted entry cannot be modified. opw-2305873 closes odoo/odoo#55187 X-original-commit: 14ef02f73e649b5f8c50f09213f0a0dbddf46217 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons/account/models')
-rw-r--r--addons/account/models/account_bank_statement.py4
-rw-r--r--addons/account/models/account_move.py4
2 files changed, 6 insertions, 2 deletions
diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py
index f500d32886b..dc45bbbd247 100644
--- a/addons/account/models/account_bank_statement.py
+++ b/addons/account/models/account_bank_statement.py
@@ -1187,7 +1187,7 @@ class AccountBankStatementLine(models.Model):
to_delete_commands = [(2, line.id) for line in suspense_lines + other_lines]
# Cleanup previous lines.
- self.move_id.with_context(check_move_validity=False, skip_account_move_synchronization=True).write({
+ self.move_id.with_context(check_move_validity=False, skip_account_move_synchronization=True, force_delete=True).write({
'line_ids': to_delete_commands + to_create_commands,
'to_check': to_check,
})
@@ -1232,7 +1232,7 @@ class AccountBankStatementLine(models.Model):
self.payment_ids.unlink()
for st_line in self:
- st_line.write({
+ st_line.with_context(force_delete=True).write({
'to_check': False,
'line_ids': [(5, 0)] + [(0, 0, line_vals) for line_vals in st_line._prepare_move_line_default_vals()],
})
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 630e29e4427..ab23a2678c9 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -3771,6 +3771,10 @@ class AccountMoveLine(models.Model):
def unlink(self):
moves = self.mapped('move_id')
+ # Prevent deleting lines on posted entries
+ if not self.env.context.get('force_delete', False) and any(m.state == 'posted' for m in moves):
+ raise UserError(_('You cannot delete an item linked to a posted entry.'))
+
# Check the lines are not reconciled (partially or not).
self._check_reconciliation()