diff --git a/addons/l10n_fr_pos_cert/models/account_bank_statement.py b/addons/l10n_fr_pos_cert/models/account_bank_statement.py index 31a2647db42..7d9abcd583c 100644 --- a/addons/l10n_fr_pos_cert/models/account_bank_statement.py +++ b/addons/l10n_fr_pos_cert/models/account_bank_statement.py @@ -10,8 +10,12 @@ class AccountBankStatement(models.Model): @api.ondelete(at_uninstall=True) def _unlink_except_created_by_pos(self): - for statement in self.filtered(lambda s: s.company_id._is_accounting_unalterable() and s.journal_id.pos_payment_method_ids): - raise UserError(_('You cannot modify anything on a bank statement (name: %s) that was created by point of sale operations.') % (statement.name,)) + for statement in self: + if not statement.company_id._is_accounting_unalterable() or not statement.s.journal_id.pos_payment_method_ids: + continue + if statement.state != 'open': + raise UserError(_('You cannot modify anything on a bank statement (name: %s) that was created by point of sale operations.') % statement.name) + return super().unlink() class AccountBankStatementLine(models.Model): @@ -19,5 +23,10 @@ class AccountBankStatementLine(models.Model): @api.ondelete(at_uninstall=True) def _unlink_except_created_by_pos(self): - for line in self.filtered(lambda s: s.company_id._is_accounting_unalterable() and s.journal_id.pos_payment_method_ids): - raise UserError(_('You cannot modify anything on a bank statement line (name: %s) that was created by point of sale operations.') % (line.name,)) + for st_line in self: + statement = st_line.statement_id + if not statement.company_id._is_accounting_unalterable() or not statement.s.journal_id.pos_payment_method_ids: + continue + if statement.state != 'open': + raise UserError(_('You cannot modify anything on a bank statement (name: %s) that was created by point of sale operations.') % statement.name) + return super().unlink()