diff --git a/account_ux/models/account_move.py b/account_ux/models/account_move.py index e2242dba0..9388af72f 100644 --- a/account_ux/models/account_move.py +++ b/account_ux/models/account_move.py @@ -235,3 +235,17 @@ def _recompute_tax_lines(self, recompute_tax_base_amount=False, tax_rep_lines_to tax_line._onchange_amount_currency() tax_line._onchange_balance() return res + + @api.ondelete(at_uninstall=False) + def _unlink_forbid_parts_of_chain(self): + """Delete vendor bills without verifying if they are the last ones of the sequence chain.""" + # Field l10n_latam_use_documents is defined in module l10n_latam_invoice_document but account_ux doesn´t has it as depends. + l10n_latam_invoice_document_installed = self.env['ir.module.module'].search([ + ('name', '=', 'l10n_latam_invoice_document'), + ('state', '=', 'installed'), + ]) + if l10n_latam_invoice_document_installed: + vendor = self.filtered(lambda x: x._is_manual_document_number() and x.l10n_latam_use_documents) + return super(AccountMove, self - vendor)._unlink_forbid_parts_of_chain() + else: + return super()._unlink_forbid_parts_of_chain()