diff --git a/account_invoice_reference/__openerp__.py b/account_invoice_reference/__openerp__.py index 2ad8758d..cda206a0 100644 --- a/account_invoice_reference/__openerp__.py +++ b/account_invoice_reference/__openerp__.py @@ -141,6 +141,7 @@ Information propagated to the move lines: 'test/out_refund_without_origin.yml', 'test/in_refund_with_supplier_number.yml', 'test/in_refund_without_supplier_number.yml', + 'test/supplier_invoice_number.yml', ], 'installable': True, diff --git a/account_invoice_reference/account_move.py b/account_invoice_reference/account_move.py index b99689b8..9dce2205 100644 --- a/account_invoice_reference/account_move.py +++ b/account_invoice_reference/account_move.py @@ -79,22 +79,25 @@ class AccountInvoice(orm.Model): return True def create(self, cr, uid, vals, context=None): - if (vals.get('supplier_invoice_reference') and not + if (vals.get('supplier_invoice_number') and not vals.get('reference')): - vals['reference'] = vals['supplier_invoice_reference'] + vals = vals.copy() + vals['reference'] = vals['supplier_invoice_number'] return super(AccountInvoice, self).create(cr, uid, vals, context=context) def write(self, cr, uid, ids, vals, context=None): - if vals.get('supplier_invoice_reference'): + if vals.get('supplier_invoice_number'): if isinstance(ids, (int, long)): ids = [ids] for invoice in self.browse(cr, uid, ids, context=context): + loc_vals = None if not invoice.reference: - locvals = vals.copy() - locvals['reference'] = vals['supplier_invoice_reference'] + loc_vals = vals.copy() + loc_vals['reference'] = vals['supplier_invoice_number'] super(AccountInvoice, self).write(cr, uid, [invoice.id], - locvals, context=context) + loc_vals or vals, + context=context) return True else: return super(AccountInvoice, self).write(cr, uid, ids, vals, diff --git a/account_invoice_reference/test/supplier_invoice_number.yml b/account_invoice_reference/test/supplier_invoice_number.yml new file mode 100644 index 00000000..846fc63f --- /dev/null +++ b/account_invoice_reference/test/supplier_invoice_number.yml @@ -0,0 +1,47 @@ +- + In order to check if the reference is populated from the supplier_invoice_number + I create an invoice. +- + !record {model: account.invoice, id: invoice_supplier_invoice_number, view: account.invoice_supplier_form}: + account_id: account.a_pay + check_total: 3000.0 + company_id: base.main_company + currency_id: base.EUR + invoice_line: + - account_id: account.a_expense + name: '[PCSC234] PC Assemble SC234' + price_unit: 300.0 + product_id: product.product_product_3 + quantity: 10.0 + uos_id: product.product_uom_unit + journal_id: account.expenses_journal + partner_id: base.res_partner_12 + reference_type: none + supplier_invoice_number: ZZZ246 + type: in_invoice +- + Set again the type of the invoice (not set on the first one...) +- + !record {model: account.invoice, id: invoice_supplier_invoice_number, view: account.invoice_supplier_form}: + type: in_invoice +- + Ensure that the reference is the same than the supplier_invoice_number +- + !assert {model: account.invoice, id: invoice_supplier_invoice_number}: + - reference == 'ZZZ246' +- + In order to check if the supplier_invoice_number is copied to the supplier_invoice_number + when the reference is empty, I empty the reference +- + !record {model: account.invoice, id: invoice_supplier_invoice_number, view: account.invoice_supplier_form}: + reference: +- + And I write a new supplier_invoice_number +- + !record {model: account.invoice, id: invoice_supplier_invoice_number, view: account.invoice_supplier_form}: + supplier_invoice_number: ABC789 +- + Ensure that the reference is the same than the supplier_invoice_number +- + !assert {model: account.invoice, id: invoice_supplier_invoice_number}: + - reference == 'ABC789'