summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomain Derie <rde@odoo.com>2021-01-13 11:35:09 +0000
committerRomain Derie <rde@odoo.com>2021-01-14 14:37:40 +0000
commit2891f9e24f10f42fd997e2f42aee80a53bc6acaa (patch)
treef0d9755711ba9f5c64197aad0e5c688748ee5014
parentfb16a05d4f5025db647996866f2db7fa4248940b (diff)
[FIX] website_sale: add tests to ensure correct fiscal position is used
Forward port of tests only of #64477 (12.0) since the fix was already applied in 14.0 with https://github.com/odoo/odoo/pull/40336 opw-2423215 closes odoo/odoo#64539 X-original-commit: 761319a3b652f8258f44385ef6e45dc5e07c5fd2 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com> Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
-rw-r--r--addons/website_sale/tests/test_website_sale_product_attribute_value_config.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py b/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py
index 7b446e05f21..079a885cc53 100644
--- a/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py
+++ b/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py
@@ -63,3 +63,55 @@ class TestWebsiteSaleProductAttributeValueConfig(TestSaleProductAttributeValueCo
self.assertEqual(pricelist.currency_id.compare_amounts(combination_info['price'], 2222 * discount_rate * currency_ratio * tax_ratio), 0)
self.assertEqual(pricelist.currency_id.compare_amounts(combination_info['list_price'], 2222 * currency_ratio * tax_ratio), 0)
self.assertEqual(combination_info['has_discounted_price'], True)
+
+ def test_get_combination_info_with_fpos(self):
+ self.env.user.partner_id.country_id = False
+ current_website = self.env['website'].get_current_website()
+ pricelist = current_website.get_current_pricelist()
+ (self.env['product.pricelist'].search([]) - pricelist).write({'active': False})
+
+ test_product = self.env['product.template'].create({
+ 'name': 'Test Product',
+ 'price': 2000,
+ }).with_context(website_id=current_website.id)
+
+ # Add fixed price for pricelist
+ pricelist.item_ids = self.env['product.pricelist.item'].create({
+ 'applied_on': "1_product",
+ 'base': "list_price",
+ 'compute_price': "fixed",
+ 'fixed_price': 500,
+ 'product_tmpl_id': test_product.id,
+ })
+ # Add 15% tax on product
+ tax15 = self.env['account.tax'].create({'name': "Test tax 15", 'amount': 15})
+ tax0 = self.env['account.tax'].create({'name': "Test tax 0", 'amount': 0})
+ test_product.taxes_id = tax15
+
+ # Enable tax included
+ group_tax_included = self.env.ref('account.group_show_line_subtotals_tax_included').with_context(active_test=False)
+ group_tax_excluded = self.env.ref('account.group_show_line_subtotals_tax_excluded').with_context(active_test=False)
+ group_tax_excluded.users -= self.env.user
+ group_tax_included.users |= self.env.user
+
+ # Create fiscal position for belgium mapping taxes 15% -> 0%
+ fpos = self.env['account.fiscal.position'].create({
+ 'name': 'test',
+ 'auto_apply': True,
+ 'country_id': self.env.ref('base.be').id,
+ })
+ self.env['account.fiscal.position.tax'].create({
+ 'position_id': fpos.id,
+ 'tax_src_id': tax15.id,
+ 'tax_dest_id': tax0.id,
+ })
+
+ combination_info = test_product._get_combination_info()
+ self.assertEqual(combination_info['price'], 575, "500$ + 15% tax")
+ self.assertEqual(combination_info['list_price'], 575, "500$ + 15% tax (2)")
+
+ # Now with fiscal position, taxes should be mapped
+ self.env.user.partner_id.country_id = self.env.ref('base.be').id
+ combination_info = test_product._get_combination_info()
+ self.assertEqual(combination_info['price'], 500, "500% + 0% tax (mapped from fp 15% -> 0% for BE)")
+ self.assertEqual(combination_info['list_price'], 500, "500% + 0% tax (mapped from fp 15% -> 0% for BE) (2)")