Skip to content

Commit 2001fa2

Browse files
committed
[FIX] sale_order_product_availability_online: Display the quantity for templates + fix for variants
Display correctly the quantity even if product template has been displayed instead of variant. Don't add the quantity if the product name is used in line description since odoo/odoo@c84b67e
1 parent a3aea61 commit 2001fa2

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
22
from . import product_product
3+
from . import product_template
34
from . import sale
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2020 Tecnativa - Ernesto Tejeda
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models
5+
6+
7+
class ProductTemplate(models.Model):
8+
_inherit = "product.template"
9+
10+
def _compute_display_name(self):
11+
res = super()._compute_display_name()
12+
if self.env.context.get("so_product_stock_inline"):
13+
self = self.with_context(warehouse=self.env.context.get("warehouse"))
14+
availability = {
15+
r.id: [
16+
sum(p.free_qty for p in r.product_variant_ids),
17+
r.uom_id.display_name,
18+
]
19+
for r in self
20+
}
21+
precision = self.env["decimal.precision"].precision_get(
22+
"Product Unit of Measure"
23+
)
24+
for record in self:
25+
name = "{} ({:.{}f} {})".format(
26+
record.display_name,
27+
availability[record.id][0],
28+
precision,
29+
availability[record.id][1],
30+
)
31+
record.display_name = name
32+
return res

sale_order_product_availability_inline/models/sale.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ def _compute_name(self):
1212
if self.env.context.get("so_product_stock_inline"):
1313
self = self.with_context(so_product_stock_inline=False)
1414
return super()._compute_name()
15+
16+
def _compute_translated_product_name(self):
17+
if self.env.context.get("so_product_stock_inline"):
18+
self = self.with_context(so_product_stock_inline=False)
19+
return super()._compute_translated_product_name()

sale_order_product_availability_inline/views/sale_views.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
"warehouse": parent.warehouse_id}
1616
</attribute>
1717
</xpath>
18+
19+
<xpath
20+
expr="//field[@name='order_line']/list//field[@name='product_template_id']"
21+
position="attributes"
22+
>
23+
<attribute name="context" operation="update">
24+
{"so_product_stock_inline": True,
25+
"warehouse": parent.warehouse_id}
26+
</attribute>
27+
</xpath>
1828
<xpath
1929
expr="//field[@name='order_line']/form//field[@name='product_id']"
2030
position="attributes"

0 commit comments

Comments
 (0)