diff options
| -rw-r--r-- | addons/website_sale/models/sale_order.py | 16 | ||||
| -rw-r--r-- | addons/website_sale/tests/test_website_sale_product_attribute_value_config.py | 59 | ||||
| -rw-r--r-- | addons/website_sale/views/templates.xml | 2 |
3 files changed, 68 insertions, 9 deletions
diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 53efba7460f..d270c51714d 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -245,21 +245,21 @@ class SaleOrder(models.Model): # update line no_variant_attributes_price_extra = [ptav.price_extra for ptav in order_line.product_no_variant_attribute_value_ids] values = self.with_context(no_variant_attributes_price_extra=tuple(no_variant_attributes_price_extra))._website_product_id_change(self.id, product_id, qty=quantity) + order = self.sudo().browse(self.id) if self.pricelist_id.discount_policy == 'with_discount' and not self.env.context.get('fixed_price'): - order = self.sudo().browse(self.id) product_context.update({ 'partner': order.partner_id, 'quantity': quantity, 'date': order.date_order, 'pricelist': order.pricelist_id.id, }) - product_with_context = self.env['product.product'].with_context(product_context).with_company(order.company_id.id) - product = product_with_context.browse(product_id) - values['price_unit'] = self.env['account.tax']._fix_tax_included_price_company( - order_line._get_display_price(product), - order_line.product_id.taxes_id, - order_line.tax_id, - self.company_id + product_with_context = self.env['product.product'].with_context(product_context).with_company(order.company_id.id) + product = product_with_context.browse(product_id) + values['price_unit'] = self.env['account.tax']._fix_tax_included_price_company( + order_line._get_display_price(product), + order_line.product_id.taxes_id, + order_line.tax_id, + self.company_id ) order_line.write(values) 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 c716f5bb5b9..fa0de777866 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 @@ -3,6 +3,7 @@ from odoo.addons.sale.tests.test_sale_product_attribute_value_config import TestSaleProductAttributeValueCommon from odoo.tests import tagged +from odoo.addons.website.tools import MockRequest @tagged('post_install', '-at_install') @@ -130,3 +131,61 @@ class TestWebsiteSaleProductAttributeValueConfig(TestSaleProductAttributeValueCo combination_info = test_product._get_combination_info() self.assertEqual(round(combination_info['price'], 2), 434.78, "434.78$ + 0% tax (mapped from fp 15% -> 0% for BE)") self.assertEqual(round(combination_info['list_price'], 2), 434.78, "434.78$ + 0% tax (mapped from fp 15% -> 0% for BE)") + +@tagged('post_install', '-at_install') +class TestWebsiteSaleProductPricelist(TestSaleProductAttributeValueCommon): + def test_cart_update_with_fpos(self): + # We will test that the mapping of an 10% included tax by a 0% by a fiscal position is taken into account when updating the cart + 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}) + # Add 10% tax on product + tax10 = self.env['account.tax'].create({'name': "Test tax 10", 'amount': 10, 'price_include': True, 'amount_type': 'percent'}) + tax0 = self.env['account.tax'].create({'name': "Test tax 0", 'amount': 0, 'price_include': True, 'amount_type': 'percent'}) + + test_product = self.env['product.template'].create({ + 'name': 'Test Product', + 'price': 110, + 'taxes_id': [(6, 0, [tax10.id])], + }).with_context(website_id=current_website.id) + + # Add discout of 50% for pricelist + pricelist.item_ids = self.env['product.pricelist.item'].create({ + 'applied_on': "1_product", + 'base': "list_price", + 'compute_price': "percentage", + 'percent_price': 50, + 'product_tmpl_id': test_product.id, + }) + + pricelist.discount_policy = 'without_discount' + + # Create fiscal position mapping taxes 10% -> 0% + fpos = self.env['account.fiscal.position'].create({ + 'name': 'test', + }) + self.env['account.fiscal.position.tax'].create({ + 'position_id': fpos.id, + 'tax_src_id': tax10.id, + 'tax_dest_id': tax0.id, + }) + so = self.env['sale.order'].create({ + 'partner_id': self.env.user.partner_id.id, + }) + sol = self.env['sale.order.line'].create({ + 'name': test_product.name, + 'product_id': test_product.product_variant_id.id, + 'product_uom_qty': 1, + 'product_uom': test_product.uom_id.id, + 'price_unit': test_product.list_price, + 'order_id': so.id, + 'tax_id': [(6, 0, [tax10.id])], + }) + self.assertEqual(round(sol.price_total), 110.0, "110$ with 10% included tax") + so.pricelist_id = pricelist + so.fiscal_position_id = fpos + sol.product_id_change() + with MockRequest(self.env, website=current_website, sale_order_id=so.id): + so._cart_update(product_id=test_product.product_variant_id.id, line_id=sol.id, set_qty=1) + self.assertEqual(round(sol.price_total), 50, "100$ with 50% discount + 0% tax (mapped from fp 10% -> 0%)") diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index e7e671c88b0..c8e689f7151 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -1021,7 +1021,7 @@ </td> <td class="text-center td-price" name="price"> <t t-set="combination" t-value="line.product_id.product_template_attribute_value_ids + line.product_no_variant_attribute_value_ids"/> - <t t-set="combination_info" t-value="line.product_id.product_tmpl_id._get_combination_info(combination)"/> + <t t-set="combination_info" t-value="line.product_id.product_tmpl_id._get_combination_info(combination, pricelist=website_sale_order.pricelist_id)"/> <t t-set="list_price_converted" t-value="website.currency_id._convert(combination_info['list_price'], website_sale_order.currency_id, website_sale_order.company_id, date)"/> <t groups="account.group_show_line_subtotals_tax_excluded" t-if="(website_sale_order.pricelist_id.discount_policy == 'without_discount' and website_sale_order.currency_id.compare_amounts(list_price_converted, line.price_reduce_taxexcl) == 1) or website_sale_order.currency_id.compare_amounts(line.price_unit, line.price_reduce) == 1" name="order_line_discount"> |
