diff --git a/account_invoice_reference/__openerp__.py b/account_invoice_reference/__openerp__.py index 04799a9d..e6b0d90d 100644 --- a/account_invoice_reference/__openerp__.py +++ b/account_invoice_reference/__openerp__.py @@ -54,7 +54,10 @@ Supplier invoices 'website': 'http://www.camptocamp.com', 'data': ['account_invoice_view.xml', ], - 'test': ['test/in_invoice_with_origin.yml', + 'test': ['test/out_invoice_with_origin.yml', + 'test/out_invoice_without_origin.yml', + 'test/in_invoice_with_supplier_number.yml', + 'test/in_invoice_without_supplier_number.yml', ], 'installable': True, 'auto_install': False, diff --git a/account_invoice_reference/account_move.py b/account_invoice_reference/account_move.py index 4bab8987..5d9fc8c5 100644 --- a/account_invoice_reference/account_move.py +++ b/account_invoice_reference/account_move.py @@ -34,9 +34,8 @@ class account_move(orm.Model): assert isinstance(invoice, orm.browse_record) invoice_obj = self.pool['account.invoice'] ref = invoice_obj._ref_from_invoice(cr, uid, invoice, context=context) - if ref: - vals = vals.copy() - vals['ref'] = ref + vals = vals.copy() + vals['ref'] = ref move_id = super(account_move, self).\ create(cr, uid, vals, context=context) return move_id @@ -48,7 +47,7 @@ class account_invoice(orm.Model): def _ref_from_invoice(self, cr, uid, invoice, context=None): if invoice.type in ('out_invoice', 'out_refund'): return invoice.origin - elif invoice.type == ('in_invoice', 'in_refund'): + elif invoice.type in ('in_invoice', 'in_refund'): return invoice.supplier_invoice_number def action_number(self, cr, uid, ids, context=None): diff --git a/account_invoice_reference/test/in_invoice_with_supplier_number.yml b/account_invoice_reference/test/in_invoice_with_supplier_number.yml new file mode 100644 index 00000000..aaba9e44 --- /dev/null +++ b/account_invoice_reference/test/in_invoice_with_supplier_number.yml @@ -0,0 +1,40 @@ +- + In order to check if the reference of the move is the supplier invoice number of + the invoice (supplier invoices), I create an invoice +- + !record {model: account.invoice, id: invoice_reference_supplier_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_reference_supplier_number, view: account.invoice_supplier_form}: + type: in_invoice +- + Ensure that the invoice is a supplier invoice +- + !assert {model: account.invoice, id: invoice_reference_supplier_number}: + - type == 'in_invoice' +- + I create invoice by clicking on Create button +- + !workflow {model: account.invoice, action: invoice_open, ref: invoice_reference_supplier_number} +- + I check that the reference of the move is the supplier invoice number of the invoice +- + !assert {model: account.invoice, id: invoice_reference_supplier_number}: + - move_id.ref == 'ZZZ246' diff --git a/account_invoice_reference/test/in_invoice_without_supplier_number.yml b/account_invoice_reference/test/in_invoice_without_supplier_number.yml new file mode 100644 index 00000000..d2833484 --- /dev/null +++ b/account_invoice_reference/test/in_invoice_without_supplier_number.yml @@ -0,0 +1,39 @@ +- + In order to check if the reference of the move is the supplier invoice number of + the invoice (supplier invoices), I create an invoice +- + !record {model: account.invoice, id: invoice_reference_no_supplier_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 + type: in_invoice +- + Set again the type of the invoice (not set on the first one...) +- + !record {model: account.invoice, id: invoice_reference_supplier_number, view: account.invoice_supplier_form}: + type: in_invoice +- + Ensure that the invoice is a supplier invoice +- + !assert {model: account.invoice, id: invoice_reference_supplier_number}: + - type == 'in_invoice' +- + I create invoice by clicking on Create button +- + !workflow {model: account.invoice, action: invoice_open, ref: invoice_reference_no_supplier_number} +- + I check that the reference of the move is the number of the invoice +- + !assert {model: account.invoice, id: invoice_reference_no_supplier_number}: + - move_id.ref == number diff --git a/account_invoice_reference/test/in_invoice_with_origin.yml b/account_invoice_reference/test/out_invoice_with_origin.yml similarity index 91% rename from account_invoice_reference/test/in_invoice_with_origin.yml rename to account_invoice_reference/test/out_invoice_with_origin.yml index 993c0684..02bae0bc 100644 --- a/account_invoice_reference/test/in_invoice_with_origin.yml +++ b/account_invoice_reference/test/out_invoice_with_origin.yml @@ -1,5 +1,5 @@ - - In order to check if the reference of the invoice is the origin of + In order to check if the reference of the move is the origin of the invoice (customer invoices), I create an invoice - !record {model: account.invoice, id: invoice_reference_origin}: diff --git a/account_invoice_reference/test/out_invoice_without_origin.yml b/account_invoice_reference/test/out_invoice_without_origin.yml new file mode 100644 index 00000000..836d758c --- /dev/null +++ b/account_invoice_reference/test/out_invoice_without_origin.yml @@ -0,0 +1,22 @@ +- + In order to check if the reference of the move is the number of + the invoice (customer invoices) when it has no origin, I create an invoice +- + !record {model: account.invoice, id: invoice_reference_no_origin}: + payment_term: account.account_payment_term_advance + journal_id: account.sales_journal + partner_id: base.res_partner_3 + reference_type: none + name: 'Test Customer Invoice no origin' + invoice_line: + - product_id: product.product_product_5 + quantity: 10.0 +- + I create invoice by clicking on Create button +- + !workflow {model: account.invoice, action: invoice_open, ref: invoice_reference_no_origin} +- + I check that the reference of the move is the number of the invoice +- + !assert {model: account.invoice, id: invoice_reference_no_origin}: + - move_id.ref == number