Skip to content

Commit 58e93c5

Browse files
committed
[FIX] product_catalog_tree: clear context when updating order line info
When using catalog tree from invoices a context with UI keys is passed and that produces errors when creating account move lines. This commit clears the context when calling the order method to avoid such issues.
1 parent 0f36826 commit 58e93c5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

product_catalog_tree/models/product_product.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66

77
from lxml import etree
8+
89
from odoo import api, fields, models
910

1011

@@ -42,9 +43,9 @@ def _compute_catalog_values(self):
4243
return
4344

4445
order = self.env[res_model].browse(order_id)
45-
order_line_info = order.with_company(order.company_id)._get_product_catalog_order_line_info(
46-
product_ids=self.ids
47-
)
46+
order_line_info = order.with_company(
47+
order.company_id
48+
)._get_product_catalog_order_line_info(product_ids=self.ids)
4849
for rec in self:
4950
rec.product_catalog_qty = order_line_info[rec.id].get("quantity")
5051
rec.product_catalog_price = order_line_info[rec.id].get("price")
@@ -59,7 +60,10 @@ def _inverse_catalog_values(self, product_catalog_qty):
5960
order = self.env[res_model].browse(order_id)
6061
for rec in self:
6162
# Actualizar la información de la línea de orden
62-
order.with_company(order.company_id)._update_order_line_info(rec.id, product_catalog_qty)
63+
# Call the order method with a cleared context to avoid errors on creating move line
64+
order.with_company(order.company_id).with_context(
65+
clear_context=True
66+
)._update_order_line_info(rec.id, product_catalog_qty)
6367

6468
def increase_quantity(self):
6569
for rec in self:
@@ -73,7 +77,9 @@ def get_view(self, view_id=None, view_type="form", **options):
7377
"""
7478
res = super().get_view(view_id=view_id, view_type=view_type, **options)
7579

76-
catalog_tree_view_id = self.env.ref("product_catalog_tree.product_view_tree_catalog").id
80+
catalog_tree_view_id = self.env.ref(
81+
"product_catalog_tree.product_view_tree_catalog"
82+
).id
7783

7884
if view_id and view_id == catalog_tree_view_id:
7985
doc = etree.XML(res["arch"])

0 commit comments

Comments
 (0)