diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 4828aa333c7..a2ea2ff697d 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -750,6 +750,12 @@ class AccountInvoice(models.Model): @api.multi def invoice_validate(self): + for invoice in self: + #refuse to validate a vendor bill/refund if there already exists one with the same reference for the same partner, + #because it's probably a double encoding of the same bill/refund + if invoice.type in ('in_invoice', 'in_refund') and invoice.reference: + if self.search([('type', 'in', ('in_invoice', 'in_refund')), ('reference', '=', invoice.reference), ('company_id', '=', invoice.company_id.id), ('commercial_partner_id', '=', invoice.commercial_partner_id.id), ('id', '!=', invoice.id)]): + raise UserError(_("Duplicated vendor reference detected. You probably encoded twice the same vendor bill/refund.")) return self.write({'state': 'open'}) @api.model