Skip to content

Commit 87323c1

Browse files
committed
Merge PR #3765 into 18.0
Signed-off-by pedrobaeza
2 parents 3a55bc7 + 2001fa2 commit 87323c1

5 files changed

Lines changed: 100 additions & 7 deletions

File tree

sale_order_lot_selection/tests/test_sale_order_lot_selection.py

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# © 2015 Agile Business Group
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3-
3+
from odoo.fields import Command
44
from odoo.tests import TransactionCase
55

66

@@ -18,17 +18,62 @@ def setUpClass(cls):
1818
1919
"""
2020
super().setUpClass()
21-
cls.prd_cable = cls.env.ref("stock.product_cable_management_box")
22-
cls.prd_cable.tracking = "lot"
23-
cls.product_46 = cls.env.ref("product.product_product_13")
24-
cls.product_12 = cls.env.ref("product.product_product_12")
21+
cls.partner = cls.env["res.partner"].create(
22+
{
23+
"name": "Partner Test",
24+
}
25+
)
26+
cls.prd_cable = cls.env["product.product"].create(
27+
{
28+
"name": "Cable Test",
29+
"tracking": "lot",
30+
"is_storable": True,
31+
}
32+
)
33+
cls.product_46 = cls.env["product.product"].create(
34+
{
35+
"name": "Product 46",
36+
"is_storable": True,
37+
}
38+
)
39+
cls.product_12 = cls.env["product.product"].create(
40+
{
41+
"name": "Product 12",
42+
"is_storable": True,
43+
}
44+
)
2545
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers")
2646
cls.customer_location = cls.env.ref("stock.stock_location_customers")
2747
cls.stock_location = cls.env.ref("stock.stock_location_stock")
2848
cls.product_model = cls.env["product.product"]
2949
cls.lot_model = cls.env["stock.lot"]
30-
cls.lot_cable = cls.env.ref("sale_order_lot_selection.lot_cable_demo")
31-
cls.sale = cls.env.ref("sale_order_lot_selection.sale_order_demo")
50+
cls.lot_cable = cls.env["stock.lot"].create(
51+
{
52+
"name": "cable test lot",
53+
"product_id": cls.prd_cable.id,
54+
}
55+
)
56+
cls.sale = cls.env["sale.order"].create(
57+
{
58+
"partner_id": cls.partner.id,
59+
"order_line": [
60+
Command.create(
61+
{
62+
"product_id": cls.prd_cable.id,
63+
"product_uom_qty": 1.0,
64+
"lot_id": cls.lot_cable.id,
65+
}
66+
),
67+
Command.create(
68+
{
69+
"product_id": cls.prd_cable.id,
70+
"product_uom_qty": 1.0,
71+
"lot_id": cls.lot_cable.id,
72+
}
73+
),
74+
],
75+
}
76+
)
3277

3378
def _retrieve_stock_quantity(self, product, lot, location):
3479
return product.with_context(lot_id=lot.id, location=location.id).qty_available
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)