summaryrefslogtreecommitdiff
path: root/addons/website_sale/models
diff options
context:
space:
mode:
authorAnh Thao Pham (pta) <pta@odoo.com>2020-10-19 11:46:39 +0000
committerAnh Thao Pham (pta) <pta@odoo.com>2020-10-23 07:23:45 +0000
commitd89fa970e8e5b07f1b9a396e6ee02db7fdd136e4 (patch)
tree60cdda896363d964433747a6adce24f310a27a9b /addons/website_sale/models
parent4058b200102eec88956913af1ad98adf2f7f0ec7 (diff)
[FIX] website_sale: fix fiscal position update in eCommerce cart
- Install website_sale - Go to Website > Products > Products and create a Product with "Tax 15.00%" (i.e. Product X) - Publish the Product on Website - Go to Invoicing > Configuration > Fiscal Positions - Create a first Fiscal Position: * Fiscal Position (Name): Fiscal Position A * Tax Mapping: Tax 15.00% => Tax 15.00% - Create a second Fiscal Position: * Fiscal Position (Name): Fiscal Position B * Tax Mapping: Tax 15.00% => Tax 0.00% - Create a Portal User (i.e. User X) - Go to Contacts and edit User X to set his Fiscal Position to Fiscal Position A - Connect with User X - Go to online Shop and add Product X in the cart - Open "My Cart" => Taxes are displayed correctly - Process checkout and enter an address, but do not pay - Disconnect - Change Fiscal Position of User X to Fiscal Position B - Reconnect with User X and open "My cart" - Open "My Cart" => Taxes are displayed as if the Fiscal Position has not been changed The prices and taxes in the cart are still based on the previous fiscale position. To fix that, fiscale position of SO will be compared to fiscale position of user, even if user has not changed. Howerver, as it is a specific use case, it will only be done if "sale_order_id" is not in session anymore. Also the cart from user's last visit will not be reloaded, but a new one will be created, as it is done when used pricelist is not available anymore. opw-2300330 closes odoo/odoo#60585 X-original-commit: bd77d0ca35a0ab724d235aca989b9c2357a25caf Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com> Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons/website_sale/models')
-rw-r--r--addons/website_sale/models/website.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/addons/website_sale/models/website.py b/addons/website_sale/models/website.py
index 2f8b4ec6a22..877a4afa82a 100644
--- a/addons/website_sale/models/website.py
+++ b/addons/website_sale/models/website.py
@@ -246,16 +246,28 @@ class Website(models.Model):
self.ensure_one()
partner = self.env.user.partner_id
sale_order_id = request.session.get('sale_order_id')
+ check_fpos = False
if not sale_order_id and not self.env.user._is_public():
last_order = partner.last_website_so_id
if last_order:
available_pricelists = self.get_pricelist_available()
# Do not reload the cart of this user last visit if the cart uses a pricelist no longer available.
sale_order_id = last_order.pricelist_id in available_pricelists and last_order.id
+ check_fpos = True
# Test validity of the sale_order_id
sale_order = self.env['sale.order'].with_company(request.website.company_id.id).sudo().browse(sale_order_id).exists() if sale_order_id else None
+ # Do not reload the cart of this user last visit if the Fiscal Position has changed.
+ if check_fpos and sale_order:
+ fpos_id = (
+ self.env['account.fiscal.position']
+ .with_company(sale_order.company_id.id)
+ .get_fiscal_position(sale_order.partner_id.id, delivery_id=sale_order.partner_shipping_id.id)
+ )
+ if sale_order.fiscal_position_id.id != fpos_id:
+ sale_order = None
+
if not (sale_order or force_create or code):
if request.session.get('sale_order_id'):
request.session['sale_order_id'] = None