[IMP] account: added a test on invoice validation to avoid duplicated reference on vendor bills and refunds, because it's probably a double encoding of the same document

This commit is contained in:
qdp-odoo
2015-09-24 10:33:34 +02:00
parent 21c88933f7
commit 492edf9824
+6
View File
@@ -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