From da03d9700347ca4b6564237dd62e5dd76b1bea14 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 6 Jan 2016 15:38:01 +0100 Subject: [PATCH] [IMP] account: test_product_id_change Forward port of c4fb2c2 in new api --- addons/account/tests/__init__.py | 1 + .../account/tests/test_product_id_change.py | 119 ++++++++++++------ 2 files changed, 81 insertions(+), 39 deletions(-) diff --git a/addons/account/tests/__init__.py b/addons/account/tests/__init__.py index e4a6224852d..01e519c02cf 100644 --- a/addons/account/tests/__init__.py +++ b/addons/account/tests/__init__.py @@ -12,6 +12,7 @@ from . import test_chart_of_account from . import test_fiscal_position from . import test_manual_reconciliation from . import test_payment +from . import test_product_id_change from . import test_reconciliation from . import test_search from . import test_tax diff --git a/addons/account/tests/test_product_id_change.py b/addons/account/tests/test_product_id_change.py index 1bd5154f4ba..a2008b64bc7 100644 --- a/addons/account/tests/test_product_id_change.py +++ b/addons/account/tests/test_product_id_change.py @@ -1,50 +1,91 @@ -from openerp.tests.common import TransactionCase +from openerp.addons.account.tests.account_test_classes import AccountingTestCase +import time -class TestProductIdChange(TransactionCase): +class TestProductIdChange(AccountingTestCase): """Test that when an included tax is mapped by a fiscal position, the included tax must be subtracted to the price of the product. """ def setUp(self): super(TestProductIdChange, self).setUp() - self.fiscal_position_model = self.registry('account.fiscal.position') - self.fiscal_position_tax_model = self.registry('account.fiscal.position.tax') - self.tax_model = self.registry('account.tax') - self.pricelist_model = self.registry('product.pricelist') - self.res_partner_model = self.registry('res.partner') - self.product_tmpl_model = self.registry('product.template') - self.product_model = self.registry('product.product') - self.invoice_line_model = self.registry('account.invoice.line') + self.invoice_model = self.env['account.invoice'] + self.fiscal_position_model = self.env['account.fiscal.position'] + self.fiscal_position_tax_model = self.env['account.fiscal.position.tax'] + self.tax_model = self.env['account.tax'] + self.pricelist_model = self.env['product.pricelist'] + self.res_partner_model = self.env['res.partner'] + self.product_tmpl_model = self.env['product.template'] + self.product_model = self.env['product.product'] + self.invoice_line_model = self.env['account.invoice.line'] + self.account_receivable = self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_receivable').id)], limit=1) + self.account_revenue = self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1) def test_product_id_change(self): - cr, uid = self.cr, self.uid - partner_id = self.res_partner_model.create(cr, uid, dict(name="George")) - tax_include_id = self.tax_model.create(cr, uid, dict(name="Include tax", - type='percent', - amount='0.21', - price_include=True)) - tax_exclude_id = self.tax_model.create(cr, uid, dict(name="Exclude tax", - type='percent', - amount='0.00')) - product_tmpl_id = self.product_tmpl_model.create(cr, uid, dict(name="Voiture", - list_price='121', - standard_price='121', - taxes_id=[(6, 0, [tax_include_id])], - supplier_taxes_id=[(6, 0, [tax_include_id])])) - product_id = self.product_model.create(cr, uid, dict(product_tmpl_id=product_tmpl_id)) - product = self.product_model.browse(cr, uid, [product_id]) - fp_id = self.fiscal_position_model.create(cr, uid, dict(name="fiscal position", - sequence=1)) - fp_tax_id = self.fiscal_position_tax_model.create(cr, uid, dict(position_id=fp_id, - tax_src_id=tax_include_id, - tax_dest_id=tax_exclude_id)) + partner = self.res_partner_model.create(dict(name="George")) + tax_include_sale = self.tax_model.create(dict(name="Include tax", + type_tax_use='sale', + amount='21.00', + price_include=True)) + tax_include_purchase = self.tax_model.create(dict(name="Include tax", + type_tax_use='purchase', + amount='21.00', + price_include=True)) + tax_exclude_sale = self.tax_model.create(dict(name="Exclude tax", + type_tax_use='sale', + amount='0.00')) + tax_exclude_purchase = self.tax_model.create(dict(name="Exclude tax", + type_tax_use='purchase', + amount='0.00')) + product_tmpl = self.product_tmpl_model.create(dict(name="Voiture", + list_price='121', + standard_price='121', + taxes_id=[(6, 0, [tax_include_sale.id])], + supplier_taxes_id=[(6, 0, [tax_include_purchase.id])])) + product = self.product_model.create(dict(product_tmpl_id=product_tmpl.id)) + fp = self.fiscal_position_model.create(dict(name="fiscal position", sequence=1)) + fp_tax_sale = self.fiscal_position_tax_model.create(dict(position_id=fp.id, + tax_src_id=tax_include_sale.id, + tax_dest_id=tax_exclude_sale.id)) + fp_tax_purchase = self.fiscal_position_tax_model.create(dict(position_id=fp.id, + tax_src_id=tax_include_purchase.id, + tax_dest_id=tax_exclude_purchase.id)) - res = self.invoice_line_model.product_id_change(cr, uid, [], product.id, product.uom_id.id, - qty=1, type='out_invoice', partner_id=partner_id, - fposition_id=fp_id) - self.assertEquals(100, res['value']['price_unit'], "The included tax must be subtracted to the price") + out_invoice = self.invoice_model.create({ + 'partner_id': partner.id, + 'reference_type': 'none', + 'name': 'invoice to client', + 'account_id': self.account_receivable.id, + 'type': 'out_invoice', + 'date_invoice': time.strftime('%Y') + '-06-26', + 'fiscal_position_id': fp.id, + }) + out_line = self.invoice_line_model.create({ + 'product_id': product.id, + 'quantity': 1, + 'price_unit': 121.0, + 'invoice_id': out_invoice.id, + 'name': 'something out', + 'account_id': self.account_revenue.id, + }) - res = self.invoice_line_model.product_id_change(cr, uid, [], product.id, product.uom_id.id, - qty=1, type='in_invoice', partner_id=partner_id, - fposition_id=fp_id) - self.assertEquals(100, res['value']['price_unit'], "The included tax must be subtracted to the price") + in_invoice = self.invoice_model.create({ + 'partner_id': partner.id, + 'reference_type': 'none', + 'name': 'invoice to supplier', + 'account_id': self.account_receivable.id, + 'type': 'in_invoice', + 'date_invoice': time.strftime('%Y') + '-06-26', + 'fiscal_position_id': fp.id, + }) + in_line = self.invoice_line_model.create({ + 'product_id': product.id, + 'quantity': 1, + 'price_unit': 121.0, + 'invoice_id': in_invoice.id, + 'name': 'something in', + 'account_id': self.account_revenue.id, + }) + out_line._onchange_product_id() + self.assertEquals(100, out_line.price_unit, "The included tax must be subtracted to the price") + in_line._onchange_product_id() + self.assertEquals(100, in_line.price_unit, "The included tax must be subtracted to the price")