[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#60587

X-original-commit: bd77d0ca35a0ab724d235aca989b9c2357a25caf
Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Anh Thao Pham (pta)
2020-10-23 07:48:09 +00:00
parent 17bee9e723
commit 06ca464458
+12
View File
@@ -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