From 0c052343a7308430f99b39a21705f6c3aa91e27a Mon Sep 17 00:00:00 2001 From: Jake Harr Date: Mon, 11 May 2015 22:08:44 -0400 Subject: [PATCH] [FIX] account_invoice_reference: Fall back to number consistently Without an origin or supplier invoice number, `_ref_from_invoice` could return a falsy value. This was checked when called from `AccountInvoice.action_number`, but not when called from `AccountMove.create`. --- account_invoice_reference/account_invoice.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/account_invoice_reference/account_invoice.py b/account_invoice_reference/account_invoice.py index 8de7a88d..663aaa56 100644 --- a/account_invoice_reference/account_invoice.py +++ b/account_invoice_reference/account_invoice.py @@ -28,10 +28,16 @@ class AccountInvoice(models.Model): @api.v8 def _ref_from_invoice(self): self.ensure_one() - if self.type in ('out_invoice', 'out_refund'): - return self.origin - elif self.type in ('in_invoice', 'in_refund'): - return self.supplier_invoice_number + + def preferred_ref(): + if self.type in ('out_invoice', 'out_refund'): + return self.origin + elif self.type in ('in_invoice', 'in_refund'): + return self.supplier_invoice_number + else: + return None + + return preferred_ref() or self.number @api.v7 def _ref_from_invoice(self, cr, uid, invoice, context=None): @@ -45,8 +51,6 @@ class AccountInvoice(models.Model): for invoice in self: ref = invoice._ref_from_invoice() - if not ref: - ref = invoice.number move_id = invoice.move_id.id if invoice.move_id else False invoice.write({'internal_number': invoice.number})