From bb5fd86f733ba3a28e6e95dff8cb6c18837e4c76 Mon Sep 17 00:00:00 2001 From: mdi-odoo Date: Tue, 17 Jun 2014 10:19:18 +0530 Subject: [PATCH] [IMP] tests cases: use float_compare instead of == --- .../account/test/account_fiscalyear_close.yml | 6 +- .../account/test/account_supplier_invoice.yml | 6 +- addons/account/test/test_edi_invoice.yml | 26 +++--- .../test/account_analytic_analysis.yml | 3 +- .../account_anglo_saxon/test/anglo_saxon.yml | 90 ++++++++++++------- .../test/anglo_saxon_avg_fifo.yml | 90 ++++++++++++------- addons/account_voucher/test/case1_usd_usd.yml | 84 +++++++++-------- .../test/case1_usd_usd_payment_rate.yml | 39 ++++---- .../test/case2_suppl_usd_eur.yml | 70 +++++++++------ .../test/case2_usd_eur_debtor_in_eur.yml | 52 ++++++----- .../test/case2_usd_eur_debtor_in_usd.yml | 61 +++++++------ addons/account_voucher/test/case3_eur_eur.yml | 50 +++++++---- addons/account_voucher/test/case4_cad_chf.yml | 27 +++--- .../test/case5_suppl_usd_usd.yml | 39 ++++---- addons/account_voucher/test/case_eur_usd.yml | 24 ++--- addons/delivery/test/delivery_cost.yml | 8 +- .../test/test_hr_timesheet_invoice.yml | 5 +- .../test_hr_timesheet_invoice_no_prod_tax.yml | 5 +- .../test/02_order_to_invoice.yml | 6 +- addons/product/test/product_pricelist.yml | 28 +++--- .../test/process/edi_purchase_order.yml | 18 ++-- .../purchase/test/process/rfq2order2done.yml | 13 +-- .../test/purchase_requisition.yml | 3 +- addons/resource/test/resource.yml | 6 +- addons/sale/test/edi_sale_order.yml | 18 ++-- addons/sale/test/sale_order_demo.yml | 25 +++--- .../sale_stock/test/picking_order_policy.yml | 9 +- .../sale_stock/test/sale_order_onchange.yml | 8 +- 28 files changed, 495 insertions(+), 324 deletions(-) diff --git a/addons/account/test/account_fiscalyear_close.yml b/addons/account/test/account_fiscalyear_close.yml index 65fb581619eab..75c94a6eae6d3 100644 --- a/addons/account/test/account_fiscalyear_close.yml +++ b/addons/account/test/account_fiscalyear_close.yml @@ -75,5 +75,7 @@ - I check that the past accounts are taken into account in partner credit - - !assert {model: res.partner, id: base.res_partner_2, string: Total Receivable does not takes unreconciled moves of previous years}: - - credit == 1040.0 + !python {model: res.partner}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('base.res_partner_2')).credit + assert float_compare(credit, 1040.0, precision_digits=2) == 0, "Total Receivable does not takes unreconciled moves of previous years" diff --git a/addons/account/test/account_supplier_invoice.yml b/addons/account/test/account_supplier_invoice.yml index a59ede03e4ee2..df4b99bc47687 100644 --- a/addons/account/test/account_supplier_invoice.yml +++ b/addons/account/test/account_supplier_invoice.yml @@ -62,6 +62,7 @@ I verify that account move is created - !python {model: account.invoice}: | + from openerp.tools import float_compare move_obj = self.pool.get('account.move') inv = self.browse(cr, uid, ref('account_invoice_supplier0')) move = inv.move_id @@ -73,7 +74,7 @@ amt_compute = move_obj._amount_compute(cr, uid, list(ids), 'amount', None, {'lang': u'en_US', 'active_model': 'ir.ui.menu', 'active_ids': [ref('menu_action_move_journal_line_form')], 'tz': False, 'active_id': ref('menu_action_move_journal_line_form')}, where ='') move_amount = amt_compute.values() - assert(inv.move_id and move.period_id.id == get_period and move_amount[0] == 3100.0), ('Journal Entries has not been created') + assert(inv.move_id and move.period_id.id == get_period and float_compare(move_amount[0], 3100.0, precision_digits=2) == 0), ('Journal Entries has not been created') - I cancel the account move which is in posted state and verifies that it gives warning message - @@ -92,5 +93,6 @@ I verify that 'Period Sum' and 'Year sum' of the tax code are the expected values - !python {model: account.tax.code}: | + from openerp.tools import float_compare tax_code = self.browse(cr, uid, ref('tax_case')) - assert(tax_code.sum_period == 100.0 and tax_code.sum == 100.0), "Incorrect 'Period Sum' / 'Year sum' expected twice 100.0, got period=%r and year=%r)" % (tax_code.sum_period,tax_code.sum) + assert(float_compare(tax_code.sum_period, 100.0, precision_digits=2) == 0 and float_compare(tax_code.sum, 100.0, precision_digits=2) == 0), "Incorrect 'Period Sum' / 'Year sum' expected twice 100.0, got period=%r and year=%r)" % (tax_code.sum_period,tax_code.sum) diff --git a/addons/account/test/test_edi_invoice.yml b/addons/account/test/test_edi_invoice.yml index 2225ae5ba9b07..a0c3257d1b6d8 100644 --- a/addons/account/test/test_edi_invoice.yml +++ b/addons/account/test/test_edi_invoice.yml @@ -49,6 +49,7 @@ - !python {model: account.invoice}: | import time + from openerp.tools import float_compare edi_document = { "__id": "account:b33adf8a-decd-11f0-a4de-702a04e25700.random_invoice_763jsms", "__module": "account", @@ -141,14 +142,14 @@ for inv_line in invoice_new.invoice_line: if inv_line.name == 'PC Assemble SC234': assert inv_line.uos_id.name == "Unit" , "uom is not same" - assert inv_line.price_unit == 10 , "price unit is not same" - assert inv_line.quantity == 1 , "product qty is not same" - assert inv_line.price_subtotal == 10, "price sub total is not same" + assert float_compare(inv_line.price_unit, 10, precision_digits=2) == 0, "price unit is not same" + assert float_compare(inv_line.quantity, 1, precision_digits=2) == 0, "product qty is not same" + assert float_compare(inv_line.price_subtotal, 10, precision_digits=2) == 0, "price sub total is not same" elif inv_line.name == 'PC on Demand': assert inv_line.uos_id.name == "Unit" , "uom is not same" - assert inv_line.price_unit == 100 , "price unit is not same" - assert inv_line.quantity == 5 , "product qty is not same" - assert inv_line.price_subtotal == 500, "price sub total is not same" + assert float_compare(inv_line.price_unit, 100, precision_digits=2) == 0, "price unit is not same" + assert float_compare(inv_line.quantity, 5, precision_digits=2) == 0, "product qty is not same" + assert float_compare(inv_line.price_subtotal, 500, precision_digits=2) == 0, "price sub total is not same" else: raise AssertionError('unknown invoice line: %s' % inv_line) for inv_tax in invoice_new.tax_line: @@ -159,6 +160,7 @@ - !python {model: account.invoice}: | import time + from openerp.tools import float_compare edi_document = { "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.random_invoice_763jsms", "__module": "account", @@ -249,14 +251,14 @@ for inv_line in invoice_new.invoice_line: if inv_line.name == 'Basic PC': assert inv_line.uos_id.name == "PCE" , "uom is not same" - assert inv_line.price_unit == 10 , "price unit is not same" - assert inv_line.quantity == 1 , "product qty is not same" - assert inv_line.price_subtotal == 10, "price sub total is not same" + assert float_compare(inv_line.price_unit, 10, precision_digits=2) == 0, "price unit is not same" + assert float_compare(inv_line.quantity, 1, precision_digits=2) == 0, "product qty is not same" + assert float_compare(inv_line.price_subtotal, 10, precision_digits=2) == 0, "price sub total is not same" elif inv_line.name == 'Medium PC': assert inv_line.uos_id.name == "PCE" , "uom is not same" - assert inv_line.price_unit == 100 , "price unit is not same" - assert inv_line.quantity == 5 , "product qty is not same" - assert inv_line.price_subtotal == 500, "price sub total is not same" + assert float_compare(inv_line.price_unit, 100, precision_digits=2) == 0, "price unit is not same" + assert float_compare(inv_line.quantity, 5, precision_digits=2) == 0, "product qty is not same" + assert float_compare(inv_line.price_subtotal, 500, precision_digits=2) == 0, "price sub total is not same" else: raise AssertionError('unknown invoice line: %s' % inv_line) for inv_tax in invoice_new.tax_line: diff --git a/addons/account_analytic_analysis/test/account_analytic_analysis.yml b/addons/account_analytic_analysis/test/account_analytic_analysis.yml index 4f594b6bed3f0..ef4eced2b680c 100644 --- a/addons/account_analytic_analysis/test/account_analytic_analysis.yml +++ b/addons/account_analytic_analysis/test/account_analytic_analysis.yml @@ -38,8 +38,9 @@ I test the generated invoice - !python {model: account.invoice}: | + from openerp.tools import float_compare aid = ref('account_analytic_analysis.contract_main') ids = self.search(cr, uid, [('invoice_line.account_analytic_id','=',aid)], context=context) assert len(ids)>=1, 'No invoice created for the contract' for invoice in self.browse(cr, uid, ids,context=context): - assert invoice.amount_untaxed == 150.0, "The invoice total is different than 150!" + assert float_compare(invoice.amount_untaxed, 150.0, precision_digits=2) == 0, "The invoice total is different than 150!" diff --git a/addons/account_anglo_saxon/test/anglo_saxon.yml b/addons/account_anglo_saxon/test/anglo_saxon.yml index c98de7c47db9d..c5b4361240e2a 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon.yml @@ -132,13 +132,17 @@ - I check the Stock Interim account (Received) is credited successfully. - - !assert {model: account.account, id : account_anglo_stock_input, string : Stock Interim account (Received) is not credited successfully.}: - - credit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_stock_input')).credit + float_compare(credit, 9, precision_digits=2) == 0, "Stock Interim account (Received) is not credited successfully." - I check the Stock valuation account is debited sucessfully. - - !assert {model: account.account, id : account_anglo_stock_valuation, string : Stock valuation account is not debited successfully.}: - - debit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_stock_valuation')).debit + float_compare(debit, 9, precision_digits=2) == 0, "Stock valuation account is not debited successfully." - I Validate Invoice of Purchase Order. - @@ -148,18 +152,24 @@ - I check the Stock Interim account (Received) is debited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_stock_input, string : Stock Interim account (Received) is not debited successfully.}: - - debit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_stock_input')).debit + float_compare(debit, 9, precision_digits=2) == 0, "Stock Interim account (Received) is not debited successfully." - I check the Price difference creditor Account is debited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_price_difference, string : Price difference creditor Account is not debited successfully.}: - - debit == 1 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_price_difference')).debit + float_compare(debit, 1, precision_digits=2) == 0, "Price difference creditor Account is not debited successfully." - I check Payable(creditor) Account is Credited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_payable, string : Payable(creditor) Account is not Credited successfully.}: - - credit == 10 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_payable')).credit + float_compare(credit, 10, precision_digits=2) == 0, "Payable(creditor) Account is not Credited successfully." - I open the Invoice. - @@ -179,13 +189,17 @@ - I check Payable(Creditors) Account is Debited sucessfully after invoice paid. - - !assert {model: account.account, id : account_anglo_payable, string : Payable(Creditors) Account is not Debited successfully.}: - - debit == 10 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_payable')).debit + assert float_compare(debit, 10, precision_digits=2) == 0, "Payable(Creditors) Account is not Debited successfully." - I check Bank/Cash account is credited sucessfully after invoice paid. - - !assert {model: account.account, id : account_anglo_cash, string: Bank/Cash account is not credited successfully.}: - - credit == 10 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_cash')).credit + float_compare(credit, 10, precision_digits=2) == 0, "Bank/Cash account is not credited successfully." - I create an Outgoing Picking order - @@ -225,13 +239,17 @@ - I check Stock Interim account (Delivery) is debited successfully. - - !assert {model: account.account, id : account_anglo_stock_output, string : Stock Interim account (Delivery) is not debited successfully.}: - - debit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_stock_output')).debit + float_compare(debit, 9, precision_digits=2) == 0, "Stock Interim account (Delivery) is not debited successfully." - I check the Stock valuation account is credited sucessfully. - - !assert {model: account.account, id : account_anglo_stock_valuation, string : Stock valuation account is not credited successfully.}: - - credit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_stock_valuation')).credit + float_compare(credit, 9, precision_digits=2) == 0, "Stock valuation account is not credited successfully." - As the Invoice state of the picking order is To be invoiced. I create invoice for my outgoing picking order. - @@ -256,23 +274,31 @@ - I check Income Account is Credited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_income, string : Income Account is not Credited successfully.}: - - credit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_income')).credit + float_compare(credit, 20, precision_digits=2) == 0, "Income Account is not Credited successfully." - I check Cost of goods sold account for debit. - - !assert {model: account.account, id : account_anglo_cogs, string : Cost of goods sale is not Debited successfully.}: - - debit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_cogs')).debit + float_compare(debit, 9, precision_digits=2) == 0, "Cost of goods sale is not Debited successfully." - I check Stock Interim account (Delivery) - - !assert {model: account.account, id : account_anglo_stock_output, string : Stock Interim account (Delivery) is not credited successfully.}: - - credit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_stock_output')).credit + float_compare(credit, 9, precision_digits=2) == 0, "Stock Interim account (Delivery) is not credited successfully." - I check Receivable(Debtor) Account for debit. - - !assert {model: account.account, id : account_anglo_receivable, string : Receivable(Debtors) Account is not Debited successfully.}: - - debit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_receivable')).debit + float_compare(debit, 20, precision_digits=2) == 0, "Receivable(Debtors) Account is not Debited successfully." - I pay the invoice. - @@ -289,10 +315,14 @@ - I check Receivable(Debtor) Account for credit. - - !assert {model: account.account, id : account_anglo_receivable, string : Receivable(Debtors) Account is not Credited successfully.}: - - credit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_receivable')).credit + float_compare(credit, 20, precision_digits=2) == 0, "Receivable(Debtors) Account is not Credited successfully." - I check Bank/Cash account is debited sucessfully after invoice paid. - - !assert {model: account.account, id : account_anglo_cash, string: Bank/Cash account is not successfully credited.}: - - debit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_cash')).debit + float_compare(debit, 20, precision_digits=2) == 0, "Bank/Cash account is not successfully credited." diff --git a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml index 034422602950c..3a89bfe60ba2b 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml @@ -140,13 +140,17 @@ - I check the Stock Interim account (Received) is credit successfully. - - !assert {model: account.account, id : account_anglo_stock_input_fifo, string : Stock Interim account (Received) is not credited successfully.}: - - credit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_stock_input_fifo')).credit + assert float_compare(credit, 9, precision_digits=2) == 0, "Stock Interim account (Received) is not credited successfully." - I check the Stock valuation account is debit sucessfully. - - !assert {model: account.account, id : account_anglo_stock_valuation_fifo, string : Stock valuation account is not debited successfully.}: - - debit == 9 + !python {model: account.account, id}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_stock_valuation_fifo')).debit + assert float_compare(debit, 9, precision_digits=2) == 0, "Stock valuation account is not debited successfully." - I Validate Invoice of Purchase Order after having changed the price to 10. - @@ -158,18 +162,24 @@ - I check the Stock Interim account (Received) is debited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_stock_input_fifo, string : Stock Interim account (Received) is not debited successfully.}: - - debit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_stock_input_fifo')).debit + assert float_compare(debit, 9, precision_digits=2) == 0, "Stock Interim account (Received) is not debited successfully." - I check the Price difference creditor Account is debited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_price_difference_fifo, string : Price difference creditor Account is not debited successfully.}: - - debit == 1 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_price_difference_fifo')).debit + assert float_compare(debit, 1, precision_digits=2) == 0, "Price difference creditor Account is not debited successfully." - I check Payable(creditor) Account is Credited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_payable_fifo, string : Payable(creditor) Account is not Credited successfully.}: - - credit == 10 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_payable_fifo')).credit + assert float_compare(credit, 10, precision_digits=2) == 0, "Payable(creditor) Account is not Credited successfully." - I pay the invoice. - @@ -182,13 +192,17 @@ - I check Payable(Creditors) Account is Debited sucessfully after invoice paid. - - !assert {model: account.account, id : account_anglo_payable_fifo, string : Payable(Creditors) Account is not Debited successfully.}: - - debit == 10 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_payable_fifo')).debit + assert float_compare(debit, 10, precision_digits=2) == 0, "Payable(Creditors) Account is not Debited successfully." - I check Bank/Cash account is credited sucessfully after invoice paid. - - !assert {model: account.account, id : account_anglo_cash_fifo, string: Bank/Cash account is not credited successfully.}: - - credit == 10 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_cash_fifo')).credit + assert float_compare(credit, 10, precision_digits=2) == 0, "Bank/Cash account is not credited successfully." - I create an Outgoing Picking order - @@ -225,13 +239,17 @@ - I check Stock Interim account (Delivery) is debited successfully. - - !assert {model: account.account, id : account_anglo_stock_output_fifo, string : Stock Interim account (Delivery) is not debited successfully.}: - - debit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_stock_output_fifo')).debit + assert float_compare(debit, 9, precision_digits=2) == 0, "Stock Interim account (Delivery) is not debited successfully." - I check the Stock valuation account is credited sucessfully. - - !assert {model: account.account, id : account_anglo_stock_valuation_fifo, string : Stock valuation account is not credited successfully.}: - - credit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_stock_valuation_fifo')).credit + assert float_compare(credit, 9, precision_digits=2) == 0, "Stock valuation account is not credited successfully." - As the Invoice state of the picking order is To be invoiced. I create invoice for my outgoing picking order. - @@ -261,23 +279,31 @@ - I check Income Account is Credited sucessfully when Invoice validated. - - !assert {model: account.account, id : account_anglo_income_fifo, string : Income Account is not Credited successfully.}: - - credit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_income_fifo')).credit + assert float_compare(credit, 20, precision_digits=2) == 0, "Income Account is not Credited successfully." - I check Cost of goods sold account for debit. - - !assert {model: account.account, id : account_anglo_cogs_fifo, string : Cost of goods sale is not Debited successfully.}: - - debit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_cogs_fifo')).debit + assert float_compare(debit, 9, precision_digits=2) == 0, "Cost of goods sale is not Debited successfully." - I check Stock Interim account (Delivery) - - !assert {model: account.account, id : account_anglo_stock_output_fifo, string : Stock Interim account (Delivery) is not credited successfully.}: - - credit == 9 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_stock_output_fifo')).credit + assert float_compare(credit, 9, precision_digits=2) == 0, "Stock Interim account (Delivery) is not credited successfully." - I check Receivable(Debtor) Account for debit. - - !assert {model: account.account, id : account_anglo_receivable_fifo, string : Receivable(Debtors) Account is not Debited successfully.}: - - debit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_receivable_fifo')).debit + assert float_compare(debit, 20, precision_digits=2) == 0, "Receivable(Debtors) Account is not Debited successfully." - I pay the invoice. - @@ -294,10 +320,14 @@ - I check Receivable(Debtor) Account for credit. - - !assert {model: account.account, id : account_anglo_receivable_fifo, string : Receivable(Debtors) Account is not Credited successfully.}: - - credit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + credit = self.browse(cr, uid, ref('account_anglo_receivable_fifo')).credit + assert float_compare(credit, 20, precision_digits=2) == 0, "Receivable(Debtors) Account is not Credited successfully." - I check Bank/Cash account is debited sucessfully after invoice paid. - - !assert {model: account.account, id : account_anglo_cash_fifo, string: Bank/Cash account is not successfully credited.}: - - debit == 20 + !python {model: account.account}: | + from openerp.tools import float_compare + debit = self.browse(cr, uid, ref('account_anglo_cash_fifo')).debit + assert float_compare(debit, 20, precision_digits=2) == 0, "Bank/Cash account is not successfully credited." diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index 84ae118ab16b6..4c19c33eb5ff7 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -94,12 +94,13 @@ I check that first invoice move is correct for debtor account (debit - credit == 150.0) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_jan")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 150.0, precision_digits=2) == 0), "Invoice move is not correct for debtors account" - I create the second invoice on 1st February for 100 USD - @@ -127,12 +128,13 @@ I check that second invoice move is correct for debtor account (debit - credit == 80) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_feb")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is not correct for debtors account" - I set the context that will be used for the encoding of all the vouchers of this file @@ -159,11 +161,12 @@ I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$> - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 200.00: + if float_compare(item.amount_unreconciled, 200.00, precision_digits=2) == 0: data += [(item.id, 180.0)] else: data += [(item.id, 70.0)] @@ -174,9 +177,10 @@ I check that writeoff amount computed is -10.0 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0" + assert (float_compare(voucher_id.writeoff_amount, -10.0, precision_digits=2) == 0), "Writeoff amount is not -10.0" - I confirm the voucher - @@ -201,39 +205,42 @@ I check that my write-off is correct. 9 debit and 10 amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 1 USD/USD'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -180.00: - assert move_line.credit == 162.00, "Debtor account has wrong entry." - elif move_line.amount_currency == -70.00: - assert move_line.credit == 63.00, "Debtor account has wrong entry." - elif move_line.amount_currency == 10.00: - assert move_line.debit == 9.00, "Writeoff amount is wrong." - elif move_line.amount_currency == 240.00: - assert move_line.debit == 216.00, "Bank entry is wrong." + if float_compare(move_line.amount_currency, -180.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 162.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, -70.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 63.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, 10.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 9.00, precision_digits=2) == 0, "Writeoff amount is wrong." + elif float_compare(move_line.amount_currency, 240.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 216.00, precision_digits=2) == 0, "Bank entry is wrong." else: assert False, "Unrecognized journal entry" - I check the residual amount of Invoice1, should be 20 in amount_currency - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_jan")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 20.0) , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 20.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice" - I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_feb")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 30.0) , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 30.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice" - On the first April, I create the second voucher of payment with values 45 USD, journal USD, - @@ -253,11 +260,12 @@ I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$ - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_2_case1')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 20.00: + if float_compare(item.amount_unreconciled, 20.00, precision_digits=2) == 0: data += [(item.id, 20.0)] else: data += [(item.id, 30.0)] @@ -268,9 +276,10 @@ I check that writeoff amount computed is -5.0 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == -5.0), "Writeoff amount is not -5.0" + assert (float_compare(voucher_id.writeoff_amount, -5.0, precision_digits=2) == 0), "Writeoff amount is not -5.0" - I confirm the voucher - @@ -299,52 +308,55 @@ I check that my writeoff is correct. 4.75 debit and 5 amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 1'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) reconcile_a = reconcile_b = False for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -20.00: + if float_compare(move_line.amount_currency, -20.00, precision_digits=2) == 0: assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled" reconcile_b = move_line.reconcile_id.id - elif move_line.amount_currency == -30.00: + elif float_compare(move_line.amount_currency, -30.00, precision_digits=2) == 0: assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled" reconcile_a = move_line.reconcile_id.id for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -20.00: - assert move_line.credit == 19.00, "Debtor account has wrong entry." - elif move_line.amount_currency == -30.00: - assert move_line.credit == 28.50, "Debtor account has wrong entry." - elif move_line.amount_currency == 5.00: - assert move_line.debit == 4.75, "Writeoff amount is wrong." - elif move_line.debit == 11.5 and move_line.account_id.reconcile: - assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong" - elif move_line.credit == 11.5: - assert move_line.amount_currency == 0.0 - elif move_line.debit == 31.0 and move_line.account_id.reconcile: - assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong" - elif move_line.credit == 31.0: - assert move_line.amount_currency == 0.0 - elif move_line.amount_currency == 45.00: - assert move_line.debit == 42.75, "Bank entry is wrong." + if float_compare(move_line.amount_currency, -20.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 19.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, -30.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 28.50, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, 5.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 4.75, precision_digits=2) == 0, "Writeoff amount is wrong." + elif float_compare(move_line.debit, 11.5, precision_digits=2) == 0 and move_line.account_id.reconcile: + assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong" + elif float_compare(move_line.credit, 11.5, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0 + elif float_compare(move_line.debit, 31.0, precision_digits=2) == 0 and move_line.account_id.reconcile: + assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong" + elif float_compare(move_line.credit, 31.0, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0 + elif float_compare(move_line.amount_currency, 45.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 42.75, precision_digits=2) == 0, "Bank entry is wrong." else: assert False, "Unrecognized journal entry" - I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_jan")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" - I check the residual amuont of Invoice2, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_feb")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" diff --git a/addons/account_voucher/test/case1_usd_usd_payment_rate.yml b/addons/account_voucher/test/case1_usd_usd_payment_rate.yml index c0aa617783ca6..7f5cf15284d93 100644 --- a/addons/account_voucher/test/case1_usd_usd_payment_rate.yml +++ b/addons/account_voucher/test/case1_usd_usd_payment_rate.yml @@ -101,12 +101,13 @@ I check that first invoice move is correct for debtor account (debit - credit == 150.0) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_jan_payment_rate")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 150.0), "Invoice move is not correct for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 150.0, precision_digits=2) == 0), "Invoice move is not correct for debtors account" - I create the second invoice on 1st February for 100 USD - @@ -134,12 +135,13 @@ I check that second invoice move is correct for debtor account (debit - credit == 80) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_feb_payment_rate")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 80), "Invoice move is not correct for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is not correct for debtors account" - I set the context that will be used for the encoding of all the vouchers of this file @@ -168,11 +170,12 @@ I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$> - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_1_case1_payment_rate')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 200.00: + if float_compare(item.amount_unreconciled, 200.00, precision_digits=2) == 0: data += [(item.id, 180.0)] else: data += [(item.id, 70.0)] @@ -183,9 +186,10 @@ I check that writeoff amount computed is -10.0 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = ref('account_voucher_1_case1_payment_rate') voucher_id = self.browse(cr, uid, voucher) - assert (voucher_id.writeoff_amount == -10.0), "Writeoff amount is not -10.0" + assert (float_compare(voucher_id.writeoff_amount, -10.0, precision_digits=2) == 0), "Writeoff amount is not -10.0" - I confirm the voucher - @@ -210,38 +214,41 @@ I check that my write-off is correct. 8 debit and 10 amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = ref('account_voucher_1_case1_payment_rate') voucher_id = self.browse(cr, uid, voucher) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -180.00: - assert move_line.credit == 144.00, "Debtor account has wrong entry." - elif move_line.amount_currency == -70.00: - assert move_line.credit == 56.00, "Debtor account has wrong entry." - elif move_line.amount_currency == 10.00: - assert move_line.debit == 8.00, "Writeoff amount is wrong: Got a debit of %s (expected 8,00€)" % (move_line.debit) - elif move_line.amount_currency == 240.00: - assert move_line.debit == 192.00, "Bank entry is wrong." + if float_compare(move_line.amount_currency, -180.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 144.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, -70.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 56.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, 10.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 8.00, precision_digits=2) == 0, "Writeoff amount is wrong: Got a debit of %s (expected 8,00€)" % (move_line.debit) + elif float_compare(move_line.amount_currency, 240.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 192.00, precision_digits=2) == 0, "Bank entry is wrong." else: assert False, "Unrecognized journal entry" - I check the residual amount of Invoice1, should be 20 in amount_currency and 6 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_jan_payment_rate")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual == 6.0) , "Residual amount is not correct for first Invoice" - assert (move_line.amount_residual_currency == 20.0) , "Residual amount in currency is not correct for first Invoice" + assert (float_compare(move_line.amount_residual, 6.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 20.0, precision_digits=2) == 0) , "Residual amount in currency is not correct for first Invoice" - I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_feb_payment_rate")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual == 24.0) , "Residual amount is not correct for second Invoice" - assert (move_line.amount_residual_currency == 30.0) , "Residual amount in currency is not correct for second Invoice" + assert (float_compare(move_line.amount_residual, 24.0, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 30.0, precision_digits=2) == 0) , "Residual amount in currency is not correct for second Invoice" diff --git a/addons/account_voucher/test/case2_suppl_usd_eur.yml b/addons/account_voucher/test/case2_suppl_usd_eur.yml index 836bee35d30be..79870aea12db5 100644 --- a/addons/account_voucher/test/case2_suppl_usd_eur.yml +++ b/addons/account_voucher/test/case2_suppl_usd_eur.yml @@ -65,12 +65,13 @@ I check that first invoice move is correct for debtor account(debit - credit == -150) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == -150.00), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, -150.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I create the second invoice on 1st February for 100 USD - @@ -100,12 +101,13 @@ I check that second invoice move is correct for debtor account (debit - credit == -80) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == -80), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, -80, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I set the context that will be used for the encoding of all the vouchers of this file - @@ -131,11 +133,12 @@ I fill amounts 180 for the invoice of 200$ and 70 for the invoice of 100$ - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2_suppl')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 200.00: + if float_compare(item.amount_unreconciled, 200.00, precision_digits=2) == 0: data += [(item.id, 180.0)] else: data += [(item.id, 70.0)] @@ -146,16 +149,18 @@ I check that writeoff amount computed is -15.0 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == -15.0), "Writeoff amount is not -15.0" + assert (float_compare(voucher_id.writeoff_amount, -15.0, precision_digits=2) == 0), "Writeoff amount is not -15.0" - I check that currency rate difference is 34.0 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.currency_rate_difference == 34.0), "Currency rate difference is not 34.0" + assert (float_compare(voucher_id.currency_rate_difference, 34.0, precision_digits=2) == 0), "Currency rate difference is not 34.0" - I confirm the voucher - @@ -182,37 +187,40 @@ I check that my writeoff is correct. -15 in credit with no amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == 180.00: - assert move_line.debit == 135.00, "Creditor account has wrong entry." - elif move_line.amount_currency == 70.00: - assert move_line.debit == 56.00, "Debtor account has wrong entry." - elif move_line.debit == 34.00: - assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." - elif move_line.debit == 15.00: - assert move_line.amount_currency == 0.00, "Writeoff amount is wrong." + if float_compare(move_line.amount_currency, 180.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 135.00, precision_digits=2) == 0, "Creditor account has wrong entry." + elif float_compare(move_line.amount_currency, 70.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 56.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.debit, 34.00, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Incorrect Currency Difference." + elif float_compare(move_line.debit, 15.00, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Writeoff amount is wrong." - I check the residual amount of Invoice1, should be 20 in residual currency and 15 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 20.0 and move_line.amount_residual == 15) , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 20.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 15, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice" - I check the residual amuont of Invoice2, should be 30 in residual currency and 24 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 30 and move_line.amount_residual == 24) , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 30, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 24, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice" - I create the second voucher of payment with values 45 USD, journal USD, - @@ -233,11 +241,12 @@ I fill amounts 20 for the invoice of 200$ and 30 for the invoice of 100$> - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2_suppl')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 20.00: + if float_compare(item.amount_unreconciled, 20.00, precision_digits=2) == 0: data += [(item.id, 20.0)] else: data += [(item.id, 30.0)] @@ -248,16 +257,18 @@ I check that writeoff amount computed is -5.0 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == 5.0), "Writeoff amount is not 5.0" + assert (float_compare(voucher_id.writeoff_amount, 5.0, precision_digits=2) == 0), "Writeoff amount is not 5.0" - I check that currency rate difference is 8.50 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.currency_rate_difference == 8.50), "Currency rate difference is not 8.50" + assert (float_compare(voucher_id.currency_rate_difference, 8.50, precision_digits=2) == 0), "Currency rate difference is not 8.50" - I confirm the voucher - @@ -281,34 +292,37 @@ I check that my writeoff is correct. 4.75 in credit and 5 in amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == 20.00: - assert move_line.debit == 15.00, "Debtor account has wrong entry." - elif move_line.amount_currency == 30.00: - assert move_line.debit == 24.00, "Debtor account has wrong entry." - elif move_line.debit == 8.50: - assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." - elif move_line.amount_currency == -5.00: - assert move_line.credit == 4.75, "Writeoff amount is wrong." + if float_compare(move_line.amount_currency, 20.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 15.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, 30.00, precision_digits=2) == 0: + assert float_compare(move_line.debit, 24.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.debit, 8.50, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Incorrect Currency Difference." + elif float_compare(move_line.amount_currency, -5.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 4.75, precision_digits=2) == 0, "Writeoff amount is wrong." - I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_suppl")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" - I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_suppl")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" diff --git a/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml index 45c86eb7ad055..0eb71d66d4d8d 100644 --- a/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_eur.yml @@ -99,12 +99,13 @@ I check that first invoice move is correct for debtor account(debit - credit == 150) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 150.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I create the second invoice on 1st February for 100 USD - @@ -132,12 +133,13 @@ I check that second invoice move is correct for debtor account (debit - credit == 80) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 80), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I set the context that will be used for the encoding of all the vouchers of this file - @@ -163,13 +165,14 @@ I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$ - !python {model: account.voucher}: | + from openerp.tools import float_compare import time from openerp import netsvc vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2a')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 150.00: + if float_compare(item.amount_unreconciled, 150.00, precision_digits=2) == 0: data += [(item.id, 130.0)] else: data += [(item.id, 70.0)] @@ -197,20 +200,22 @@ I check the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 55.56 and move_line.amount_residual == 20) , "Residual amount is not correct for first Invoice. Got %s USD (%s EUR)" %(move_line.amount_residual_currency, move_line.amount_residual) + assert (float_compare(move_line.amount_residual_currency, 55.56, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 20, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice. Got %s USD (%s EUR)" %(move_line.amount_residual_currency, move_line.amount_residual) - I check the residual amuont of Invoice2, should be 22.22 in residual currency and 10 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 22.22 and move_line.amount_residual == 10) , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 22.22, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 10, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice" - I create the second voucher of payment with values 80 USD, journal USD - @@ -233,11 +238,12 @@ !python {model: account.voucher}: | import time from openerp import netsvc + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2a')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 55.56: + if float_compare(item.amount_unreconciled, 55.56, precision_digits=2) == 0: data += [(item.id, 55.56)] else: data += [(item.id, 22.22)] @@ -248,9 +254,10 @@ I check that writeoff amount computed is 2.22 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (round(voucher_id.writeoff_amount, 2) == 2.22), "Writeoff amount is not 2.22$" + assert (float_compare(round(voucher_id.writeoff_amount, 2), 2.22, precision_digits=2) == 0), "Writeoff amount is not 2.22$" - I confirm the voucher - @@ -275,44 +282,47 @@ I check that my writeoff is correct. 2.11 in credit and 2.22 in amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR EUR'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) reconcile_a = reconcile_b = False for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -22.22: + if float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0: assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled" reconcile_b = move_line.reconcile_id.id - elif move_line.amount_currency == -55.56: + elif float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0: assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled" reconcile_a = move_line.reconcile_id.id for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -55.56: - assert move_line.credit == 52.78, "Debtor account has wrong entry." - elif move_line.amount_currency == -22.22: - assert move_line.credit == 21.11, "Debtor account has wrong entry." - elif move_line.credit == 11.11 and move_line.account_id.reconcile: - assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference." - elif move_line.credit == 32.78 and move_line.account_id.reconcile: - assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference." - elif move_line.amount_currency == 2.22: - assert move_line.credit == 2.11, "Writeoff amount is wrong." + if float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0: + assert float_compare(move_line.credit, 52.78, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0: + assert float_compare(move_line.credit, 21.11, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.credit, 11.11, precision_digits=2) == 0 and move_line.account_id.reconcile: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference." + elif float_compare(move_line.credit, 32.78, precision_digits=2) == 0 and move_line.account_id.reconcile: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference." + elif float_compare(move_line.amount_currency, 2.22, precision_digits=2) == 0: + assert float_compare(move_line.credit, 2.11, precision_digits=2) == 0, "Writeoff amount is wrong." - I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" - I check the residual amuont of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" diff --git a/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml b/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml index f353cd8c6fc64..12d6f07b33afa 100644 --- a/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml +++ b/addons/account_voucher/test/case2_usd_eur_debtor_in_usd.yml @@ -99,12 +99,13 @@ I check that first invoice move is correct for debtor account(debit - credit == 150) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_michal")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 150.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I create the second invoice on 1st February for 100 USD - @@ -132,12 +133,13 @@ I check that second invoice move is correct for debtor account (debit - credit == 80) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 80), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 80, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I set the context that will be used for the encoding of all the vouchers of this file - @@ -163,11 +165,12 @@ I fill amounts 130 for the invoice of 200$ and 70 for the invoice of 100$> - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_1_case2b')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 150.00: + if float_compare(item.amount_unreconciled, 150.00, precision_digits=2) == 0: data += [(item.id, 130.0)] else: data += [(item.id, 70.0)] @@ -196,33 +199,36 @@ I check that the debtor account has 2 new lines with 144.44 and 77.78 in amount_currency columns and their credit columns are 130 and 70 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 2 USD/EUR DR USD'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.credit == 70.0: - assert move_line.amount_currency == -77.78, "Wrong debtor entry" - if move_line.credit == 130.0: - assert move_line.amount_currency == -144.44, "Wrong debtor entry" + if float_compare(move_line.credit, 70.0, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, -77.78, precision_digits=2) == 0, "Wrong debtor entry" + if float_compare(move_line.credit, 130.0, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, -144.44, precision_digits=2) == 0, "Wrong debtor entry" - I check the residual amount of Invoice1, should be 55.56 in residual currency and 20 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_michal")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 55.56 and move_line.amount_residual == 20) , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 55.56, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 20, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice" - I check the residual amount of Invoice2, should be 22.22 in residual currency and 10 in amount_residual - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 22.22 and move_line.amount_residual == 10) , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 22.22, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 10, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice" - I create the second voucher of payment with values 80 USD, journal USD - @@ -243,11 +249,12 @@ and I fully reconcil the 2 previous invoices - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_2_case2b')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 55.56: + if float_compare(item.amount_unreconciled, 55.56, precision_digits=2) == 0: data += [(item.id, 55.56)] else: data += [(item.id, 22.22)] @@ -258,9 +265,10 @@ I check that writeoff amount computed is 2.22 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR USD'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (round(voucher_id.writeoff_amount, 2) == 2.22), "Writeoff amount is not 2.22$" + assert (float_compare(round(voucher_id.writeoff_amount, 2), 2.22, precision_digits=2) == 0), "Writeoff amount is not 2.22$" - I confirm the voucher - @@ -284,44 +292,47 @@ I check that my writeoff is correct. 2.11 in credit and 2.22 in amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 2 SUPPL USD/EUR DR USD'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) reconcile_a = reconcile_b = False for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -22.22: + if float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0: assert move_line.reconcile_id.id, "The invoice of 200$ is not fully reconciled" reconcile_b = move_line.reconcile_id.id - elif move_line.amount_currency == -55.56: + elif float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0: assert move_line.reconcile_id.id, "The invoice of 100$ is not fully reconciled" reconcile_a = move_line.reconcile_id.id for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.amount_currency == -55.56: - assert move_line.credit == 52.78, "Debtor account has wrong entry." - elif move_line.amount_currency == -22.22: - assert move_line.credit == 21.11, "Debtor account has wrong entry." - elif move_line.credit == 11.11 and move_line.account_id.reconcile: - assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference." - elif move_line.credit == 32.78 and move_line.account_id.reconcile: - assert move_line.amount_currency == 0.00 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference." - elif move_line.amount_currency == 2.22: - assert move_line.credit == 2.11, "Writeoff amount is wrong." + if float_compare(move_line.amount_currency, -55.56, precision_digits=2) == 0: + assert float_compare(move_line.credit, 52.78, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.amount_currency, -22.22, precision_digits=2) == 0: + assert float_compare(move_line.credit, 21.11, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.credit, 11.11, precision_digits=2) == 0 and move_line.account_id.reconcile: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_b, "Incorrect Currency Difference." + elif float_compare(move_line.credit, 32.78, precision_digits=2) == 0 and move_line.account_id.reconcile: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0 and move_line.reconcile_id.id == reconcile_a, "Incorrect Currency Difference." + elif float_compare(move_line.amount_currency, 2.22, precision_digits=2) == 0: + assert float_compare(move_line.credit, 2.11, precision_digits=2) == 0, "Writeoff amount is wrong." - I check the residual amount of invoice 1, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_michal")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" - I check the residual amount of invoice 2, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_michal")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for second Invoice" diff --git a/addons/account_voucher/test/case3_eur_eur.yml b/addons/account_voucher/test/case3_eur_eur.yml index 064b79ed30536..6c48c2e2136cf 100644 --- a/addons/account_voucher/test/case3_eur_eur.yml +++ b/addons/account_voucher/test/case3_eur_eur.yml @@ -54,12 +54,13 @@ I check that first invoice move is correct for debtor account(debit - credit == 150) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 150.00), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 150.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I create the second invoice on 1st February for 80 EUR - @@ -87,12 +88,13 @@ I check that second invoice move is correct for debtor account (debit - credit == 80) - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur")) assert invoice_id.move_id, "Move not created for open invoice" move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.debit - move_line.credit == 80.00), "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 80.00, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I set the context that will be used for the encoding of all the vouchers of this file - @@ -118,11 +120,12 @@ I fill amounts 100 for the invoice of 150€ and 20 for the invoice of 80€ - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_1_case3')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 150.00: + if float_compare(item.amount_unreconciled, 150.00, precision_digits=2) == 0: data += [(item.id, 100.0)] else: data += [(item.id, 20.0)] @@ -133,9 +136,10 @@ I check that writeoff amount computed is 0.00 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 3'),('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0.00" + assert (float_compare(voucher_id.writeoff_amount, 0.00, precision_digits=2) == 0), "Writeoff amount is not 0.00" - I confirm the voucher - @@ -158,33 +162,36 @@ I check that the debtor account has 2 new lines with 0.00 and 0.00 in amount_currency columns and their credit are 20 and 100 respectively - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 3'),('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.credit == 20.00: - assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." - elif move_line.credit == 100.00: - assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." + if float_compare(move_line.credit, 20.00, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.credit, 100.00, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Debtor account has wrong entry." - I check the residual amount of Invoice1 is 50 - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 50.0 and move_line.amount_residual == 50.0) , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 50.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 50.0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice" - I check the residual amuont of Invoice2 is 60 - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 60.0 and move_line.amount_residual == 60.0) , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, 60.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 60.0, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice" - I create the second voucher of payment with values 120€, journal EUR, and check to let open the debtor overpaid amount - @@ -205,13 +212,14 @@ I fill amounts 50 for the invoice of 150€ and 70 for the invoice of 80€ - !python {model: account.voucher}: | + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_2_case3')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 50.00: + if float_compare(item.amount_unreconciled, 50.00, precision_digits=2) == 0: data += [(item.id, 50.0)] - elif item.amount_unreconciled == 60.00: + elif float_compare(item.amount_unreconciled, 60.00, precision_digits=2) == 0: data += [(item.id, 70.00)] for line_id, amount in data: self.pool.get('account.voucher.line').write(cr, uid, [line_id], {'amount': amount}) @@ -220,9 +228,10 @@ I check that writeoff amount computed is 0.00 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 3'),('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (voucher_id.writeoff_amount == 0.00), "Writeoff amount is not 0" + assert (float_compare(voucher_id.writeoff_amount, 0.00, precision_digits=2) == 0), "Writeoff amount is not 0" - I confirm the voucher - @@ -246,30 +255,33 @@ I check that the debtor account has 2 new lines with 0.00 and 0.00 in amount_currency columns and their credit are 70 and 50 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'Second payment: Case 3'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) for move_line in move_line_obj.browse(cr, uid, move_lines): - if move_line.credit == 70.00: - assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." - elif move_line.credit == 50.00: - assert move_line.amount_currency == 0.00, "Debtor account has wrong entry." + if float_compare(move_line.credit, 70.00, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.credit, 50.00, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Debtor account has wrong entry." - I check the residual amount of Invoice1 is 0 - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_eur")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0 and move_line.amount_residual == 0) , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0, precision_digits=2) == 0) , "Residual amount is not correct for first Invoice" - I check the residual amuont of Invoice2 is -10 - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_second_invoice_feb_eur")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == -10.0 and move_line.amount_residual == -10.0) , "Residual amount is not correct for second Invoice" + assert (float_compare(move_line.amount_residual_currency, -10.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, -10.0, precision_digits=2) == 0) , "Residual amount is not correct for second Invoice" diff --git a/addons/account_voucher/test/case4_cad_chf.yml b/addons/account_voucher/test/case4_cad_chf.yml index 476a22c3f1546..e31dd5783c00d 100644 --- a/addons/account_voucher/test/case4_cad_chf.yml +++ b/addons/account_voucher/test/case4_cad_chf.yml @@ -94,7 +94,7 @@ move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert float_compare(move_line.debit - move_line.credit, 149.39, 2) == 0, "Invoice move is incorrect for debtors account" + assert (float_compare(move_line.debit - move_line.credit, 149.39, precision_digits=2) == 0), "Invoice move is incorrect for debtors account" - I set the context that will be used for the encoding of all the vouchers of this file - @@ -121,11 +121,12 @@ !python {model: account.voucher}: | import time from openerp import netsvc + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_1_case4')) data = [] for item in voucher_id.line_cr_ids: - if item.amount_unreconciled == 186.74: + if float_compare(item.amount_unreconciled, 186.74, precision_digits=2) == 0: data += [(item.id, 186.74)] else: data += [(item.id, 0.0)] @@ -136,9 +137,10 @@ I check that writeoff amount computed is 13.26 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))]) voucher_id = self.browse(cr, uid, voucher[0]) - assert (round(voucher_id.writeoff_amount,2) == 13.26), "Writeoff amount is not 13.26 CHF" + assert (float_compare(round(voucher_id.writeoff_amount,2), 13.26, precision_digits=2) == 0), "Writeoff amount is not 13.26 CHF" - I confirm the voucher - @@ -174,23 +176,24 @@ move_lines = move_line_obj.search(cr, uid, [('move_id', '=', voucher_id.move_id.id)]) assert move_lines, "Voucher move has no lines" for move_line in move_line_obj.browse(cr, uid, move_lines): - if float_compare(move_line.amount_currency, 200, 2) == 0: - assert float_compare(move_line.debit, 160.00, 2) == 0, "Bank account has wrong entry." - elif float_compare(move_line.amount_currency, -298.78, 2) == 0: - assert float_compare(move_line.credit, 149.39, 2) == 0, "Debtor account has wrong entry." - elif move_line.debit == 0.00 and move_line.credit == 0.00: - assert move_line.amount_currency == 98.78, "Incorrect Currency Difference, got %s as amount_currency (expected 98.78)." % (move_line.amount_currency) + if float_compare(move_line.amount_currency, 200, precision_digits=2) == 0: + assert float_compare(move_line.debit, 160.00, precision_digits=2) == 0, "Bank account has wrong entry." + elif float_compare(move_line.amount_currency, -298.78, precision_digits=2) == 0 : + assert float_compare(move_line.credit, 149.39, precision_digits=2) == 0, "Debtor account has wrong entry." + elif float_compare(move_line.debit, 0.00, precision_digits=2) == 0 and float_compare(move_line.credit, 0.00, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 98.78, precision_digits=2) == 0, "Incorrect Currency Difference, got %s as amount_currency (expected 98.78)." % (move_line.amount_currency) assert move_line.currency_id.id == ref('base.CAD'), "Incorrect Currency Difference, got %s (expected 'CAD')" % (move_line.currency_id.name) - elif move_line.credit == 10.61: - assert move_line.amount_currency == -13.26, "Writeoff amount is wrong." + elif float_compare(move_line.credit, 10.61, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, -13.26, precision_digits=2) == 0, "Writeoff amount is wrong." else: assert False, "Wrong entry" - I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_first_invoice_jan_cad")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for first Invoice" diff --git a/addons/account_voucher/test/case5_suppl_usd_usd.yml b/addons/account_voucher/test/case5_suppl_usd_usd.yml index c20d07a81926b..327cd9de25c1e 100644 --- a/addons/account_voucher/test/case5_suppl_usd_usd.yml +++ b/addons/account_voucher/test/case5_suppl_usd_usd.yml @@ -16,14 +16,14 @@ - !record {model: res.currency.rate, id: nov_usd}: currency_id: base.USD - name: !eval "'%s-11-01 00:00:00' %(datetime.now().year)" + name: !eval "'%s-11-01' %(datetime.now().year)" rate: 1.8 - I create currency USD in OpenERP for December of 1.5 Rate - !record {model: res.currency.rate, id: dec_usd}: currency_id: base.USD - name: !eval "'%s-12-01 00:00:00' %(datetime.now().year)" + name: !eval "'%s-12-01' %(datetime.now().year)" rate: 1.5 - I set the income and expense currency accounts on the main company @@ -98,10 +98,8 @@ move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert float_compare(move_line.debit - move_line.credit, -555.56, 2) == 0, \ - "Invoice move is incorrect for creditor account" - assert float_compare(move_line.amount_currency, -1000, 2) == 0, \ - "Amount currency is incorrect for creditor account" + assert (float_compare(move_line.debit - move_line.credit, -555.56, precision_digits=2) == 0), "Invoice move is incorrect for creditor account" + assert (float_compare(move_line.amount_currency, -1000, precision_digits=2) == 0), "Amount currency is incorrect for creditor account" - I set the context that will be used for the encoding of all the vouchers of this file - @@ -128,17 +126,20 @@ - !python {model: account.voucher}: | import time + from openerp.tools import float_compare vals = {} voucher_id = self.browse(cr, uid, ref('account_voucher_case_5_supplier_flow')) for item in voucher_id.line_dr_ids: - if item.amount_unreconciled == 1000.00: + if float_compare(item.amount_unreconciled, 1000.00, precision_digits=2) == 0: self.pool.get('account.voucher.line').write(cr, uid, [item.id], {'amount': 1000}) assert (voucher_id.state=='draft'), "Voucher is not in draft state" - I check that writeoff amount computed is -50.0 - - !assert {model: account.voucher, id: account_voucher_case_5_supplier_flow}: - - writeoff_amount == -50.0 + !python {model: account.voucher}: | + from openerp.tools import float_compare + writeoff_amount = self.browse(cr, uid, ref('account_voucher_case_5_supplier_flow')).writeoff_amount + assert float_compare(writeoff_amount, -50.0, precision_digits=2) == 0 - I confirm the voucher - @@ -163,24 +164,26 @@ I check that my writeoff is correct. 33.34€ in credit with -$50 as amount currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher_id = self.browse(cr, uid, ref('account_voucher_case_5_supplier_flow')) for move_line in voucher_id.move_id.line_id: - if move_line.amount_currency == -950.00: - assert move_line.credit == 633.33, "Wrong bank entry." - elif move_line.credit == 111.11 or move_line.debit == 111.11: - assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." - elif move_line.credit == 33.34: - assert move_line.amount_currency == -50.0, "Writeoff amount is wrong." - elif move_line.debit == 666.67: - assert move_line.amount_currency == 1000.0, "Wrong supplier entry." + if float_compare(move_line.amount_currency, -950.00, precision_digits=2) == 0: + assert float_compare(move_line.credit, 633.33, precision_digits=2) == 0, "Wrong bank entry." + elif float_compare(move_line.credit, 111.11, precision_digits=2) == 0 or float_compare(move_line.debit, 111.11, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 0.00, precision_digits=2) == 0, "Incorrect Currency Difference." + elif float_compare(move_line.credit, 33.34, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, -50.0, precision_digits=2) == 0, "Writeoff amount is wrong." + elif float_compare(move_line.debit, 666.67, precision_digits=2) == 0: + assert float_compare(move_line.amount_currency, 1000.0, precision_digits=2) == 0, "Wrong supplier entry." else: assert False, "Wrong entry. Unrecognized account move line" - I check the residual amount of invoice, it should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_supplier_invoice_november")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert (move_line.amount_residual_currency == 0.0 and move_line.amount_residual == 0.0 and invoice_id.state == 'paid') , "Residual amount is not correct for supplier invoice" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for supplier invoice" diff --git a/addons/account_voucher/test/case_eur_usd.yml b/addons/account_voucher/test/case_eur_usd.yml index 69304c342c9e4..ce2b71d7ac049 100644 --- a/addons/account_voucher/test/case_eur_usd.yml +++ b/addons/account_voucher/test/case_eur_usd.yml @@ -102,10 +102,11 @@ I fill amount 1400 for the invoice of 1400$ - !python {model: account.voucher}: | + from openerp.tools import float_compare data = [] voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case')) for item in voucher.line_cr_ids: - if item.amount_unreconciled == 1400: + if float_compare(item.amount_unreconciled, 1400, precision_digits=2) == 0: data += [(item.id, 1400)] assert data, "Credit line not found" for line_id, amount in data: @@ -115,8 +116,9 @@ I check that writeoff amount computed is -50.0 - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case')) - assert (voucher.writeoff_amount == -50.0), "Writeoff amount is not -50.0" + assert (float_compare(voucher.writeoff_amount, -50.0, precision_digits=2) == 0), "Writeoff amount is not -50.0" - I confirm the voucher - @@ -148,14 +150,15 @@ I check that my bank account is correct. 964.29 debit and 1350 amount_currency - !python {model: account.voucher}: | + from openerp.tools import float_compare voucher = self.browse(cr, uid, ref('account_voucher_eur_usd_case')) for move_line in voucher.move_ids: - if move_line.amount_currency == 1350: - assert move_line.debit == 964.29,"debtor account is not correct" - if move_line.amount_currency == 50: - assert move_line.debit == 35.71,"write off bank account is not correct" - if move_line.amount_currency == 0.0: - assert move_line.credit == 1000,"total reconcile is not correct of invoice" + if float_compare(move_line.amount_currency, 1350, precision_digits=2) == 0: + assert float_compare(move_line.debit, 964.29, precision_digits=2) == 0,"debtor account is not correct" + if float_compare(move_line.amount_currency, 50, precision_digits=2) == 0: + assert float_compare(move_line.debit, 35.71, precision_digits=2) == 0,"write off bank account is not correct" + if float_compare(move_line.amount_currency, 0.0, precision_digits=2) == 0: + assert float_compare(move_line.credit, 1000, precision_digits=2) == 0,"total reconcile is not correct of invoice" - I check that the move of payment in invoice is valid - @@ -167,10 +170,9 @@ I check the residual amount of invoice should be 0 in residual currency and 0 in amount_residual and paid - !python {model: account.invoice}: | + from openerp.tools import float_compare invoice_id = self.browse(cr, uid, ref("account_invoice_eur_usd")) move_line_obj = self.pool.get('account.move.line') move_lines = move_line_obj.search(cr, uid, [('move_id', '=', invoice_id.move_id.id), ('invoice', '=', invoice_id.id), ('account_id', '=', invoice_id.account_id.id)]) move_line = move_line_obj.browse(cr, uid, move_lines[0]) - assert move_line.amount_residual_currency == 0.0, "Residual amount is not correct for Invoice" - assert move_line.amount_residual == 0.0, "Residual amount is not correct for Invoice" - assert invoice_id.state == 'paid', "Invoice is not paid" + assert (float_compare(move_line.amount_residual_currency, 0.0, precision_digits=2) == 0 and float_compare(move_line.amount_residual, 0.0, precision_digits=2) == 0 and invoice_id.state == 'paid') , "Residual amount is not correct for Invoice" diff --git a/addons/delivery/test/delivery_cost.yml b/addons/delivery/test/delivery_cost.yml index efa22ca5df7e8..e20d89e91e96d 100644 --- a/addons/delivery/test/delivery_cost.yml +++ b/addons/delivery/test/delivery_cost.yml @@ -28,10 +28,11 @@ I check sale order after added delivery cost. - !python {model: sale.order.line}: | + from openerp.tools import float_compare line_ids = self.search(cr, uid, [('order_id','=', ref('sale_normal_delivery_charges')), ('product_id','=', ref('product_product_delivery'))]) assert len(line_ids), "Delivery cost is not Added" line_data = self.browse(cr ,uid ,line_ids[0] ,context) - assert line_data.price_subtotal == 10, "Delivey cost is not correspond." + assert float_compare(line_data.price_subtotal, 10, precision_digits=2) == 0, "Delivey cost is not correspond." - I confirm the sale order. - @@ -79,10 +80,11 @@ I check sale order after added delivery cost. - !python {model: sale.order.line}: | + from openerp.tools import float_compare line_ids = self.search(cr, uid, [('order_id','=', ref('sale_free_delivery_charges')), ('product_id','=', ref('product_product_delivery'))]) assert len(line_ids), "Delivery cost is not Added" line_data = self.browse(cr ,uid ,line_ids[0] ,context) - assert line_data.price_subtotal == 0, "Delivey cost is not correspond." + assert float_compare(line_data.price_subtotal, 0, precision_digits=2) == 0, "Delivey cost is not correspond." - I set default delivery policy. @@ -91,4 +93,4 @@ {} - !python {model: sale.config.settings}: | - self.execute(cr, uid, [ref('default_delivery_policy')], context=context) \ No newline at end of file + self.execute(cr, uid, [ref('default_delivery_policy')], context=context) diff --git a/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice.yml b/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice.yml index b6b52544cbcd6..3a185736fe5f0 100644 --- a/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice.yml +++ b/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice.yml @@ -92,6 +92,7 @@ I check that Invoice is created for this timesheet. - !python {model: account.analytic.line}: | + from openerp.tools import float_compare aline = self.browse(cr, uid, ref('account_analytic_line_developyamlforhrmodule0')) analytic_account_obj = self.pool.get('account.analytic.account') data = self.pool.get('hr.timesheet.invoice.create').read(cr, uid, [ref("hr_timesheet_invoice_create_0")], [], context)[0] @@ -111,5 +112,5 @@ assert product == product_exp assert aline.invoice_id, "Invoice created, but analytic line wasn't updated." assert aline.invoice_id == invoice_id, "Invoice doesn't match the one at analytic line" - assert invoice_id.amount_untaxed == 187.5, "Invoice amount mismatch: %s" % invoice_id.amount_untaxed - assert invoice_id.amount_tax == 50, "Invoice tax mismatch: %s" % invoice_id.amount_tax + assert float_compare(invoice_id.amount_untaxed, 187.5, precision_digits=2) == 0, "Invoice amount mismatch: %s" % invoice_id.amount_untaxed + assert float_compare(invoice_id.amount_tax, 50, precision_digits=2) == 0, "Invoice tax mismatch: %s" % invoice_id.amount_tax diff --git a/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice_no_prod_tax.yml b/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice_no_prod_tax.yml index c5b7c9b5be858..dac550a369a1a 100644 --- a/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice_no_prod_tax.yml +++ b/addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice_no_prod_tax.yml @@ -90,6 +90,7 @@ I check that Invoice is created for this timesheet. - !python {model: account.analytic.line}: | + from openerp.tools import float_compare aline = self.browse(cr, uid, ref('account_analytic_line_developyamlforhrmodule1')) analytic_account_obj = self.pool.get('account.analytic.account') data = self.pool.get('hr.timesheet.invoice.create').read(cr, uid, [ref("hr_timesheet_invoice_create_0")], [], context)[0] @@ -110,5 +111,5 @@ assert product == product_exp assert aline.invoice_id, "Invoice created, but analytic line wasn't updated." assert aline.invoice_id == invoice_id, "Invoice doesn't match the one at analytic line" - assert invoice_id.amount_untaxed == 187.5, "Invoice amount mismatch: %s" % invoice_id.amount_untaxed - assert invoice_id.amount_tax == 40, "Invoice tax mismatch: %s" % invoice_id.amount_tax + assert float_compare(invoice_id.amount_untaxed, 187.5, precision_digits=2) == 0, "Invoice amount mismatch: %s" % invoice_id.amount_untaxed + assert float_compare(invoice_id.amount_tax, 40, precision_digits=2) == 0, "Invoice tax mismatch: %s" % invoice_id.amount_tax diff --git a/addons/point_of_sale/test/02_order_to_invoice.yml b/addons/point_of_sale/test/02_order_to_invoice.yml index ea63b24c58c0e..90442a9a2e105 100644 --- a/addons/point_of_sale/test/02_order_to_invoice.yml +++ b/addons/point_of_sale/test/02_order_to_invoice.yml @@ -47,5 +47,7 @@ - I test that the total of the attached invoice is correct - - !assert {model: pos.order, id: pos_order_pos1, string: Invoice inconsistent with its origin order}: - - invoice_id.amount_total == 1795.5 + !python {model: pos.order}: | + from openerp.tools import float_compare + amount_total = self.browse(cr, uid, ref('pos_order_pos1')).amount_total + assert float_compare(amount_total, 1752.75, precision_digits=2) == 0, "Invoice not correct" diff --git a/addons/product/test/product_pricelist.yml b/addons/product/test/product_pricelist.yml index 53fa22df43efd..6380e66045151 100644 --- a/addons/product/test/product_pricelist.yml +++ b/addons/product/test/product_pricelist.yml @@ -4,60 +4,64 @@ I check sale price of Assemble Computer - !python {model: product.product}: | + from openerp.tools import float_compare context.update({'pricelist': ref("customer_pricelist"), 'quantity':1}) product = self.browse(cr, uid, ref("product_product_4"), context=context) - assert product.price == (product.lst_price-product.lst_price*(0.10)), "Wrong sale price: Assemble Computer." + assert float_compare(product.price, (product.lst_price-product.lst_price*(0.10)), precision_digits=2) == 0, "Wrong sale price: Assemble Computer." - I check sale price of Laptop. - !python {model: product.product}: | + from openerp.tools import float_compare product = self.browse(cr, uid, ref("product_product_25"), context=context) - assert product.price == product.lst_price + 1, "Wrong sale price: Laptop." + assert float_compare(product.price, product.lst_price + 1, precision_digits=2) == 0, "Wrong sale price: Laptop." - I check sale price of IT component. - !python {model: product.product}: | + from openerp.tools import float_compare product = self.browse(cr, uid, ref("product_product_7"), context=context) - assert product.price == product.lst_price, "Wrong sale price: IT component." - + assert float_compare(product.price, product.lst_price, precision_digits=2) == 0, "Wrong sale price: IT component." - I check sale price of IT component if more than 3 Unit. - !python {model: product.product}: | + from openerp.tools import float_compare context.update({'quantity':5}) product = self.browse(cr, uid, ref("product_product_26"), context=context) - assert product.price == product.lst_price-product.lst_price*(0.05), "Wrong sale price: IT component if more than 3 Unit." + assert float_compare(product.price, product.lst_price-product.lst_price*(0.05), precision_digits=2) == 0, "Wrong sale price: IT component if more than 3 Unit." - I check sale price of LCD Monitor. - !python {model: product.product}: | + from openerp.tools import float_compare context.update({'quantity':1}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert product.price == product.lst_price, "Wrong sale price: LCD Monitor." - + assert float_compare(product.price, product.lst_price, precision_digits=2) == 0, "Wrong sale price: LCD Monitor." - I check sale price of LCD Monitor on end of year. - !python {model: product.product}: | + from openerp.tools import float_compare context.update({'quantity':1, 'date': '2011-12-31'}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert product.price == product.lst_price-product.lst_price*(0.30), "Wrong sale price: LCD Monitor on end of year." - + assert float_compare(product.price, product.lst_price-product.lst_price*(0.30), precision_digits=2) == 0, "Wrong sale price: LCD Monitor on end of year." - I check cost price of LCD Monitor. - !python {model: product.product}: | + from openerp.tools import float_compare context.update({'quantity':1, 'date': False, 'partner': ref('base.res_partner_4'), 'pricelist': ref("supplier_pricelist")}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert product.price == 792, "wrong cost price: LCD Monitor." + assert float_compare(product.price, 792, precision_digits=2) == 0, "Wrong cost price: LCD Monitor." - I check cost price of LCD Monitor if more than 3 Unit. - !python {model: product.product}: | + from openerp.tools import float_compare context.update({'quantity':3}) product = self.browse(cr, uid, ref("product_product_6"), context=context) - assert product.price == 787, "wrong cost price: LCD Monitor if more than 3 Unit." - + assert float_compare(product.price, 787, precision_digits=2) == 0, "Wrong cost price: LCD Monitor if more than 3 Unit." - I print the sale prices report. - diff --git a/addons/purchase/test/process/edi_purchase_order.yml b/addons/purchase/test/process/edi_purchase_order.yml index 6d585d69c650b..f97a20ab3a977 100644 --- a/addons/purchase/test/process/edi_purchase_order.yml +++ b/addons/purchase/test/process/edi_purchase_order.yml @@ -37,6 +37,7 @@ Then I import a sample EDI document of a sale order (v7.0) - !python {model: edi.edi}: | + from openerp.tools import float_compare purchase_order_pool = self.pool.get('purchase.order') edi_document = { "__id": "sale:724f9v70-dv70-1v70-8v70-701a04e25v70.sale_order_test", @@ -120,17 +121,17 @@ assert bank_info.acc_number == "Guys bank: 123477777-156113", 'Expected "Guys bank: 123477777-156113", got %s' % bank_info.acc_number assert order_new.pricelist_id.name == 'Default Purchase Pricelist' , "Default Purchase Pricelist was not automatically assigned" - assert order_new.amount_total == 350, "Amount total is not same" - assert order_new.amount_untaxed == 350, "untaxed amount is not same" + assert float_compare(order_new.amount_total, 350, precision_digits=2) == 0, "Amount total is not same" + assert float_compare(order_new.amount_untaxed, 350, precision_digits=2) == 0, "untaxed amount is not same" assert len(order_new.order_line) == 2, "Purchase order lines number mismatch" for purchase_line in order_new.order_line: if purchase_line.name == 'PC Assemble SC234': assert purchase_line.product_uom.name == "Unit" , "uom is not same" - assert purchase_line.price_unit == 150 , "unit price is not same, got %s, expected 150"%(purchase_line.price_unit,) + assert float_compare(purchase_line.price_unit, 150 , precision_digits=2) == 0, "unit price is not same, got %s, expected 150"%(purchase_line.price_unit,) assert purchase_line.product_qty == 1 , "product qty is not same" elif purchase_line.name == 'PC on Demand': assert purchase_line.product_uom.name == "Unit" , "uom is not same" - assert purchase_line.price_unit == 20 , "unit price is not same, got %s, expected 20"%(purchase_line.price_unit,) + assert float_compare(purchase_line.price_unit, 20 , precision_digits=2) == 0, "unit price is not same, got %s, expected 20"%(purchase_line.price_unit,) assert purchase_line.product_qty == 10 , "product qty is not same" else: raise AssertionError('unknown order line: %s' % purchase_line) @@ -138,6 +139,7 @@ "Then I import a sample EDI document of a sale order (v6.1 - to test backwards compatibility)" - !python {model: edi.edi}: | + from openerp.tools import float_compare purchase_order_pool = self.pool.get('purchase.order') edi_document = { "__id": "sale:724f93ec-ddd0-11e0-88ec-701a04e25543.sale_order_test", @@ -221,17 +223,17 @@ assert bank_info.acc_number == "Another bank: 123477700-156113", 'Expected "Another bank: 123477700-156113", got %s' % bank_info.acc_number assert order_new.pricelist_id.name == 'Default Purchase Pricelist' , "Default Purchase Pricelist was not automatically assigned" - assert order_new.amount_total == 350, "Amount total is not same" - assert order_new.amount_untaxed == 350, "untaxed amount is not same" + assert float_compare(order_new.amount_total, 350, precision_digits=2) == 0, "Amount total is not same" + assert float_compare(order_new.amount_untaxed, 350, precision_digits=2) == 0, "untaxed amount is not same" assert len(order_new.order_line) == 2, "Purchase order lines number mismatch" for purchase_line in order_new.order_line: if purchase_line.name == 'Basic PC': assert purchase_line.product_uom.name == "PCE" , "uom is not same" - assert purchase_line.price_unit == 150 , "unit price is not same, got %s, expected 150"%(purchase_line.price_unit,) + assert float_compare(purchase_line.price_unit, 150 , precision_digits=2) == 0, "unit price is not same, got %s, expected 150"%(purchase_line.price_unit,) assert purchase_line.product_qty == 1 , "product qty is not same" elif purchase_line.name == 'Medium PC': assert purchase_line.product_uom.name == "PCE" , "uom is not same" - assert purchase_line.price_unit == 20 , "unit price is not same, got %s, expected 20"%(purchase_line.price_unit,) + assert float_compare(purchase_line.price_unit, 20 , precision_digits=2) == 0, "unit price is not same, got %s, expected 20"%(purchase_line.price_unit,) assert purchase_line.product_qty == 10 , "product qty is not same" else: raise AssertionError('unknown order line: %s' % purchase_line) diff --git a/addons/purchase/test/process/rfq2order2done.yml b/addons/purchase/test/process/rfq2order2done.yml index bf48e3369d25e..d4c4a9dff0d3f 100644 --- a/addons/purchase/test/process/rfq2order2done.yml +++ b/addons/purchase/test/process/rfq2order2done.yml @@ -3,8 +3,10 @@ - I check the total untaxed amount of the RFQ is correctly computed - - !assert {model: purchase.order, id: purchase_order_1, string: The amount of RFQ is not correctly computed}: - - round(sum([l.price_subtotal for l in order_line]), 2) == round(amount_untaxed, 2) + !python {model: purchase.order}: | + from openerp.tools import float_compare + po = self.browse(cr, uid, ref('purchase_order_1')) + assert float_compare(sum([l.price_subtotal for l in po.order_line]), po.amount_untaxed, precision_digits=2) == 0, "The amount of RFQ is not correctly computed" - I confirm the RFQ. - @@ -18,6 +20,7 @@ I check that the invoice details which is generated after confirmed RFQ. - !python {model: purchase.order}: | + from openerp.tools import float_compare purchase_order = self.browse(cr, uid, ref("purchase_order_1")) assert len(purchase_order.invoice_ids) >= 1, "Invoice is not generated more or less than one" for invoice in purchase_order.invoice_ids: @@ -28,9 +31,9 @@ assert invoice.currency_id.id == purchase_order.pricelist_id.currency_id.id ,"Invoice currency is not correspond with purchase order" assert invoice.origin == purchase_order.name,"Invoice origin is not correspond with purchase order" assert invoice.company_id.id == purchase_order.company_id.id ,"Invoice company is not correspond with purchase order" - assert invoice.amount_untaxed == purchase_order.amount_untaxed, "Invoice untaxed amount is not correspond with purchase order" - assert invoice.amount_tax == purchase_order.amount_tax, "Invoice tax amount is not correspond with purchase order" - assert invoice.amount_total == purchase_order.amount_total, "Invoice total amount is not correspond with purchase order" + assert float_compare(invoice.amount_untaxed, purchase_order.amount_untaxed, precision_digits=2) == 0, "Invoice untaxed amount is not correspond with purchase order" + assert float_compare(invoice.amount_tax, purchase_order.amount_tax, precision_digits=2) == 0, "Invoice tax amount is not correspond with purchase order" + assert float_compare(invoice.amount_total, purchase_order.amount_total, precision_digits=2) == 0, "Invoice total amount is not correspond with purchase order" assert len(invoice.invoice_line) == len(purchase_order.order_line), "Lines of Invoice and Purchase Order are not correspond" - I check that Reception details after confirmed RFQ. diff --git a/addons/purchase_requisition/test/purchase_requisition.yml b/addons/purchase_requisition/test/purchase_requisition.yml index af5aade283347..97b0875ed354f 100644 --- a/addons/purchase_requisition/test/purchase_requisition.yml +++ b/addons/purchase_requisition/test/purchase_requisition.yml @@ -21,6 +21,7 @@ I check requisition details which created after run procurement. - !python {model: procurement.order}: | + from openerp.tools import float_compare procurement_ids = self.search(cr, uid, [('requisition_id','!=', False)]) for procurement in self.browse(cr, uid, procurement_ids, context=context): requisition = procurement.requisition_id @@ -29,7 +30,7 @@ line = requisition.line_ids[0] assert line.product_id.id == procurement.product_id.id, "Product is not correspond." assert line.product_uom_id.id == procurement.product_uom.id, "UOM is not correspond." - assert line.product_qty == procurement.product_qty, "Quantity is not correspond." + assert float_compare(line.product_qty, procurement.product_qty, precision_digits=2) == 0, "Quantity is not correspond." - I send the purchase order associated to the requisition. - diff --git a/addons/resource/test/resource.yml b/addons/resource/test/resource.yml index b085c0734c460..618f3227d0c89 100644 --- a/addons/resource/test/resource.yml +++ b/addons/resource/test/resource.yml @@ -12,13 +12,15 @@ First, I generate the resource detail and check the resource Efficiency assigned. - !python {model: resource.resource}: | + from openerp.tools import float_compare resources = self.generate_resources(cr, uid, [ref('base.user_root'),ref('base.user_demo')], ref('timesheet_group1'), context) for resource in resources.values(): - assert resource.get('efficiency', 0.0) == 1.0, 'Invalid resource generated.' + assert float_compare(resource.get('efficiency', 0.0), 1.0, precision_digits=2) == 0, 'Invalid resource generated.' - I check per day work hour availability of the Resource based on Working Calendar Assigned to each resource, for first day of the week. - !python {model: resource.resource}: | + from openerp.tools import float_compare calendar_pool = self.pool.get('resource.calendar') resources = self.browse(cr, uid, [ref('resource_analyst'), ref('resource_designer'), ref('resource_developer')], context) from datetime import datetime, timedelta @@ -26,7 +28,7 @@ dt = now - timedelta(days=now.weekday()) for resource in resources: result = calendar_pool.working_hours_on_day(cr, uid, resource.calendar_id, dt, context) - assert result == 9.0, 'Wrong calculation of day work hour availability of the Resource (found %d).' % result + assert float_compare(result, 9.0, precision_digits=2) == 0, 'Wrong calculation of day work hour availability of the Resource (found %d).' % result - Now, resource "Developer" drafted leave on Thursday in this week. - diff --git a/addons/sale/test/edi_sale_order.yml b/addons/sale/test/edi_sale_order.yml index 65b6eb76835cc..4eb7ebb34b4ff 100644 --- a/addons/sale/test/edi_sale_order.yml +++ b/addons/sale/test/edi_sale_order.yml @@ -35,6 +35,7 @@ "Then I import a sample EDI document of a purchase order (v7.0)" - !python {model: edi.edi}: | + from openerp.tools import float_compare sale_order_pool = self.pool.get('sale.order') edi_document = { "__id": "purchase:5af12v70-dv70-1v70-bv70-701a04e25v70.purchase_order_test", @@ -103,17 +104,17 @@ assert bank_info.acc_number == "Another bank: 032465700-156700", 'Expected "Another bank: 032465700-156700", got %s' % bank_info.acc_number assert order_new.pricelist_id.name == 'Public Pricelist' , "Public Price list was not automatically assigned" - assert order_new.amount_total == 350, "Amount total is wrong" - assert order_new.amount_untaxed == 350, "Untaxed amount is wrong" + assert float_compare(order_new.amount_total, 350, precision_digits=2) == 0, "Amount total is wrong" + assert float_compare(order_new.amount_untaxed, 350, precision_digits=2) == 0, "Untaxed amount is wrong" assert len(order_new.order_line) == 2, "Sale order lines mismatch" for sale_line in order_new.order_line: if sale_line.name == 'PC Assemble SC234': assert sale_line.product_uom.name == "Unit" , "uom is not same" - assert sale_line.price_unit == 150 , "unit price is not same, got %s, expected 150"%(sale_line.price_unit,) + assert float_compare(sale_line.price_unit, 150 , precision_digits=2) == 0, "unit price is not same, got %s, expected 150"%(sale_line.price_unit,) assert sale_line.product_uom_qty == 1 , "product qty is not same" elif sale_line.name == 'PC on Demand': assert sale_line.product_uom.name == "Unit" , "uom is not same" - assert sale_line.price_unit == 100 , "unit price is not same, got %s, expected 100"%(sale_line.price_unit,) + assert float_compare(sale_line.price_unit, 100, precision_digits=2) == 0, "unit price is not same, got %s, expected 100"%(sale_line.price_unit,) assert sale_line.product_uom_qty == 2 , "product qty is not same" else: raise AssertionError('unknown order line: %s' % sale_line) @@ -121,6 +122,7 @@ "Then I import a sample EDI document of a purchase order (v6.1 - to test backwards compatibility)" - !python {model: edi.edi}: | + from openerp.tools import float_compare sale_order_pool = self.pool.get('sale.order') edi_document = { "__id": "purchase:5af1272e-dd26-11e0-b65e-701a04e25543.purchase_order_test", @@ -199,17 +201,17 @@ assert bank_info.acc_number == "Ladies bank: 032465789-156113", 'Expected "Ladies bank: 032465789-156113", got %s' % bank_info.acc_number assert order_new.pricelist_id.name == 'Public Pricelist' , "Public Price list was not automatically assigned" - assert order_new.amount_total == 350, "Amount total is wrong" - assert order_new.amount_untaxed == 350, "Untaxed amount is wrong" + assert float_compare(order_new.amount_total, 350, precision_digits=2) == 0, "Amount total is wrong" + assert float_compare(order_new.amount_untaxed, 350, precision_digits=2) == 0, "Untaxed amount is wrong" assert len(order_new.order_line) == 2, "Sale order lines mismatch" for sale_line in order_new.order_line: if sale_line.name == 'Basic PC': assert sale_line.product_uom.name == "PCE" , "uom is not same" - assert sale_line.price_unit == 150 , "unit price is not same, got %s, expected 150"%(sale_line.price_unit,) + assert float_compare(sale_line.price_unit, 150, precision_digits=2) == 0, "unit price is not same, got %s, expected 150"%(sale_line.price_unit,) assert sale_line.product_uom_qty == 1 , "product qty is not same" elif sale_line.name == 'Medium PC': assert sale_line.product_uom.name == "PCE" , "uom is not same" - assert sale_line.price_unit == 100 , "unit price is not same, got %s, expected 100"%(sale_line.price_unit,) + assert float_compare(sale_line.price_unit, 100 , precision_digits=2) == 0, "unit price is not same, got %s, expected 100"%(sale_line.price_unit,) assert sale_line.product_uom_qty == 2 , "product qty is not same" else: raise AssertionError('unknown order line: %s' % sale_line) diff --git a/addons/sale/test/sale_order_demo.yml b/addons/sale/test/sale_order_demo.yml index c911815f25b36..1488b2ff0f78c 100644 --- a/addons/sale/test/sale_order_demo.yml +++ b/addons/sale/test/sale_order_demo.yml @@ -16,11 +16,13 @@ - I verify that the onchange was correctly triggered - - !assert {model: sale.order, id: sale.sale_order_test1, string: The onchange function of product was not correctly triggered}: - - order_line[0].name == u'[A8767] Apple In-Ear Headphones' - - order_line[0].price_unit == 79.0 - - order_line[0].product_uom_qty == 8 - - order_line[0].product_uom.id == ref('product.product_uom_unit') + !python {model: sale.order}: | + from openerp.tools import float_compare + order_line = self.browse(cr, uid, ref('sale.sale_order_test1')).order_line + assert order_line[0].name == u'[A8767] Apple In-Ear Headphones', "The onchange function of product was not correctly triggered" + assert float_compare(order_line[0].price_unit, 79.0, precision_digits=2) == 0, "The onchange function of product was not correctly triggered" + assert order_line[0].product_uom_qty == 8, "The onchange function of product was not correctly triggered" + assert order_line[0].product_uom.id == ref('product.product_uom_unit'), "The onchange function of product was not correctly triggered" - I create another sale order @@ -34,8 +36,11 @@ - I verify that the onchange was correctly triggered - - !assert {model: sale.order, id: sale.sale_order_test2, string: The onchange function of product was not correctly triggered}: - - order_line[0].name == u'[A8767] Apple In-Ear Headphones' - - order_line[0].price_unit == 79.0 * 12 - - order_line[0].product_uom.id == ref('product.product_uom_dozen') - - order_line[0].product_uom_qty == 16 \ No newline at end of file + !python {model: sale.order}: | + from openerp.tools import float_compare + order_line = self.browse(cr, uid, ref('sale.sale_order_test2')).order_line + assert order_line[0].name == u'[A8767] Apple In-Ear Headphones', "The onchange function of product was not correctly triggered" + assert float_compare(order_line[0].price_unit, 79.0 * 12, precision_digits=2) == 0, "The onchange function of product was not correctly triggered" + assert order_line[0].product_uom.id == ref('product.product_uom_dozen'), "The onchange function of product was not correctly triggered" + assert order_line[0].product_uom_qty == 16, "The onchange function of product was not correctly triggered" + diff --git a/addons/sale_stock/test/picking_order_policy.yml b/addons/sale_stock/test/picking_order_policy.yml index 8de8ea45a0879..06a0f4d48844c 100644 --- a/addons/sale_stock/test/picking_order_policy.yml +++ b/addons/sale_stock/test/picking_order_policy.yml @@ -37,8 +37,10 @@ - First I check the total amount of the Quotation before Approved. - - !assert {model: sale.order, id: sale_order_service, string: The amount of the Quotation is not correctly computed}: - - sum([l.price_subtotal for l in order_line]) == amount_untaxed + !python {model: sale.order}: | + from openerp.tools import float_compare + so = self.browse(cr, uid, ref('sale_order_service')) + float_compare(sum([l.price_subtotal for l in so.order_line]), so.amount_untaxed, precision_digits=2) == 0, "The amount of the Quotation is not correctly computed" - I set an explicit invoicing partner that is different from the main SO Customer - @@ -156,6 +158,7 @@ I check the invoice details after dispatched delivery. - !python {model: sale.order}: | + from openerp.tools import float_compare order = self.browse(cr, uid, ref("sale_order_service")) assert order.invoice_ids, "Invoice is not created." ac = order.partner_invoice_id.property_account_receivable.id @@ -175,7 +178,7 @@ assert inv_line.product_id.id == so_line.product_id.id or False,"Product is not correspond" assert inv_line.account_id.id == ac,"Account of Invoice line is not corresponding." assert inv_line.uos_id.id == (so_line.product_uos and so_line.product_uos.id or so_line.product_uom.id), "Product UOS is not correspond." - assert inv_line.price_unit == so_line.price_unit , "Price Unit is not correspond." + assert float_compare(inv_line.price_unit, so_line.price_unit , precision_digits=2) == 0, "Price Unit is not correspond." assert inv_line.quantity == (so_line.product_uos and so_line.product_uos_qty or so_line.product_uom_qty), "Product qty is not correspond." assert inv_line.price_subtotal == so_line.price_subtotal, "Price sub total is not correspond." - diff --git a/addons/sale_stock/test/sale_order_onchange.yml b/addons/sale_stock/test/sale_order_onchange.yml index 7cb4da5c338bd..f01b8ba0bf67d 100644 --- a/addons/sale_stock/test/sale_order_onchange.yml +++ b/addons/sale_stock/test/sale_order_onchange.yml @@ -25,6 +25,8 @@ - I verify that the onchange of product on sale order line was correctly triggered - - !assert {model: sale.order, id: sale_order_onchange1, string: The onchange function of product was not correctly triggered}: - - order_line[0].name == u'Devil Worship Book' - - order_line[0].price_unit == 66.6 + !python {model: sale.order}: | + from openerp.tools import float_compare + order_line = self.browse(cr, uid, ref('sale_order_onchange1')).order_line + assert order_line[0].name == u'Devil Worship Book', "The onchange function of product was not correctly triggered" + assert float_compare(order_line[0].price_unit, 66.6, precision_digits=2) == 0, "The onchange function of product was not correctly triggered"