Skip to content

Commit

Permalink
fix database transaction error on multi-languages anonymous carts
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Pigeon authored and HviorForgeFlow committed May 26, 2020
1 parent 11481df commit 20c365d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions shopinvader/services/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,24 @@ def _add_item(self, cart, params):
.play_onchanges(vals, vals.keys())
)
vals.update(new_values)
# As the frontend could be in several languages but we have only
# one anonymous parnter with his language set, we need to ensure
# that description on the line is in the right language
partner = cart.partner_id
ctx_lang = self.env.context.get("lang", partner.lang)
if partner.lang != ctx_lang:
product_id = vals["product_id"]
vals["name"] = self._get_sale_order_line_name(product_id)
self.env["sale.order.line"].create(vals)
cart.recompute()

def _get_sale_order_line_name(self, product_id):
product = self.env["product.product"].browse(product_id)
name = product.name_get()[0][1]
if product.description_sale:
name += "\n" + product.description_sale
return name

def _update_item(self, cart, params, item=False):
if not item:
item = self._get_cart_item(cart, params, raise_if_not_found=False)
Expand Down

0 comments on commit 20c365d

Please sign in to comment.