Skip to content

Commit 111dd48

Browse files
committed
[MIG] stock_picking_report_valued_sale_mrp: Migration to 18.0
1 parent 5b01fdc commit 111dd48

File tree

5 files changed

+55
-76
lines changed

5 files changed

+55
-76
lines changed

stock_picking_report_valued_sale_mrp/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Valued picking linked with MRP Kits",
55
"summary": "Allow to summarize the picking related with the selled kits",
6-
"version": "16.0.1.0.0",
6+
"version": "18.0.1.0.0",
77
"development_status": "Beta",
88
"category": "Warehouse Management",
99
"website": "https://github.com/OCA/stock-logistics-reporting",

stock_picking_report_valued_sale_mrp/models/stock_move.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ def _get_components_per_kit(self):
1111
rely on the matching of sale order and pickings demands, but if those
1212
were manually changed, it could lead to inconsistencies"""
1313
self.ensure_one()
14+
result = 0.0
1415
sale_line = self.sale_line_id
15-
if (
16-
not sale_line
17-
or not sale_line.product_id.get_components()
18-
or sale_line.product_id.ids == sale_line.product_id.get_components()
19-
):
20-
return 0
21-
component_demand = sum(
22-
sale_line.move_ids.filtered(
23-
lambda x: x.product_id == self.product_id
24-
and not x.origin_returned_move_id
25-
and (
26-
x.state != "cancel"
27-
or (x.state == "cancel" and x.picking_id.backorder_id)
16+
if sale_line:
17+
product = sale_line.product_id
18+
19+
bom_map = self.env["mrp.bom"]._bom_find(
20+
product,
21+
company_id=self.company_id.id,
22+
)
23+
bom = bom_map.get(product)
24+
if bom and bom.type == "phantom":
25+
bom_line = bom.bom_line_ids.filtered(
26+
lambda line: line.product_id == self.product_id
2827
)
29-
).mapped("product_uom_qty")
30-
)
31-
return component_demand / sale_line.product_uom_qty
28+
if bom_line:
29+
result = bom_line.product_qty
30+
return result

stock_picking_report_valued_sale_mrp/models/stock_move_line.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class StockMoveLine(models.Model):
1111
compute="_compute_phantom_product_id",
1212
compute_sudo=True,
1313
string="Product Kit",
14-
readonly=True,
1514
)
1615
phantom_line = fields.Boolean(
1716
compute="_compute_sale_order_line_fields",
@@ -26,12 +25,17 @@ class StockMoveLine(models.Model):
2625
def _compute_phantom_product_id(self):
2726
"""Relate every line with its kit product"""
2827
self.phantom_product_id = False
29-
for line in self.filtered(
30-
lambda x: x.sale_line
31-
and x.sale_line.product_id.get_components()
32-
and x.sale_line.product_id.ids != x.sale_line.product_id.get_components()
33-
):
34-
line.phantom_product_id = line.sale_line.product_id
28+
for line in self:
29+
if not line.sale_line:
30+
continue
31+
product = line.sale_line.product_id
32+
bom_map = self.env["mrp.bom"]._bom_find(
33+
product,
34+
company_id=line.company_id.id,
35+
)
36+
bom = bom_map.get(product)
37+
if bom and bom.type == "phantom":
38+
line.phantom_product_id = product
3539

3640
def _compute_sale_order_line_fields(self):
3741
"""For kits we only want to store the value in one of the move lines to
@@ -44,7 +48,7 @@ def _compute_sale_order_line_fields(self):
4448
)
4549
for picking in pickings:
4650
self.filtered(
47-
lambda x: x.picking_id == picking
51+
lambda x, picking=picking: x.picking_id == picking
4852
)._compute_sale_order_line_fields_by_picking()
4953
return res
5054

@@ -54,7 +58,9 @@ def _compute_sale_order_line_fields_by_picking(self):
5458
"""
5559
kit_lines = self.filtered("phantom_product_id")
5660
for sale_line in kit_lines.mapped("sale_line"):
57-
move_lines = kit_lines.filtered(lambda x: x.sale_line == sale_line)
61+
move_lines = kit_lines.filtered(
62+
lambda x, sale_line=sale_line: x.sale_line == sale_line
63+
)
5864
# Deduce the kit quantity from the first component in the picking.
5965
# If the the kit is partially delivered, this could lead to an
6066
# unacurate value.
@@ -72,10 +78,13 @@ def _compute_sale_order_line_fields_by_picking(self):
7278
components_per_kit = phantom_line.move_id._get_components_per_kit()
7379
phantom_line_qty_done = sum(
7480
move_lines.filtered(
75-
lambda x: x.product_id == phantom_line.product_id
76-
).mapped("qty_done")
81+
lambda x, phantom_line=phantom_line: x.product_id
82+
== phantom_line.product_id
83+
).mapped("quantity")
84+
)
85+
quantity = (
86+
phantom_line_qty_done / components_per_kit if components_per_kit else 0
7787
)
78-
quantity = phantom_line_qty_done / components_per_kit
7988
taxes = phantom_line.sale_tax_id.compute_all(
8089
price_unit=price_unit,
8190
currency=phantom_line.currency_id,
@@ -107,8 +116,8 @@ def _compute_sale_order_line_fields_by_picking(self):
107116
redundant_lines.update(
108117
{
109118
"sale_tax_description": "",
110-
"sale_price_subtotal": 0,
111-
"sale_price_tax": 0,
112-
"sale_price_total": 0,
119+
"sale_price_subtotal": 0.0,
120+
"sale_price_tax": 0.0,
121+
"sale_price_total": 0.0,
113122
}
114123
)

stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,24 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
33
<template
4-
id="stock_report_delivery_document_inherit_mrp"
5-
inherit_id="mrp.stock_report_delivery_document_inherit_mrp"
4+
id="stock_report_delivery_document_disable_kits"
5+
inherit_id="stock.report_delivery_document"
66
>
7-
<!-- disable printing of kits in a separate table -->
8-
<xpath
9-
expr="//table[@name='stock_move_line_table']/tbody/t[@t-set='has_kits']"
10-
position="attributes"
11-
>
12-
<attribute name="t-value">env["stock.move.line"]</attribute>
13-
</xpath>
14-
<xpath
15-
expr="//t[@name='no_package_move_lines']/t[@t-set='has_kits']"
16-
position="attributes"
17-
>
18-
<attribute name="t-value">env["stock.move.line"]</attribute>
7+
<!-- Disable phantom kit rendering block -->
8+
<xpath expr="//t[@t-if='has_kits']" position="attributes">
9+
<attribute name="t-if">False</attribute>
1910
</xpath>
2011
</template>
2112
<template
2213
id="valued_mrp_report_picking"
2314
inherit_id="stock_picking_report_valued.valued_report_picking"
2415
>
25-
<!-- show only one row for kit products -->
26-
<xpath expr="//tr[@t-foreach='package_move_lines']" position="before">
27-
<t t-if="o.valued and o.sale_id and o.move_line_ids and is_outgoing">
28-
<t
29-
t-set="package_move_lines"
30-
t-value="package_move_lines.filtered(lambda l: not l.phantom_product_id or l.phantom_line)"
31-
/>
32-
</t>
33-
</xpath>
34-
<xpath expr="//tr[@t-foreach='move_lines']" position="before">
35-
<t t-if="o.valued and o.sale_id and o.move_line_ids and is_outgoing">
36-
<t
37-
t-set="move_lines"
38-
t-value="move_lines.filtered(lambda l: not l.phantom_product_id or l.phantom_line)"
39-
/>
40-
</t>
41-
</xpath>
42-
<xpath expr="//tr[@t-foreach='o.move_line_ids']" position="attributes">
43-
<attribute name="t-foreach">has_no_packages_move_lines</attribute>
44-
</xpath>
45-
<xpath expr="//tr[@t-foreach='has_no_packages_move_lines']" position="before">
46-
<t t-set="has_no_packages_move_lines" t-value="o.move_line_ids" />
16+
<!-- Show only one row for kit products -->
17+
<xpath expr="//table[@name='stock_move_line_table']/tbody" position="before">
4718
<t t-if="o.valued and o.sale_id and o.move_line_ids and is_outgoing">
4819
<t
49-
t-set="has_no_packages_move_lines"
50-
t-value="has_no_packages_move_lines.filtered(lambda l: not l.phantom_product_id or l.phantom_line)"
20+
t-set="lines"
21+
t-value="o.move_line_ids.filtered(lambda l: not l.phantom_product_id or l.phantom_line)"
5122
/>
5223
</t>
5324
</xpath>
@@ -69,10 +40,10 @@
6940
<xpath expr="//span[@t-field='move_line.product_id']" position="before">
7041
<span t-field="move_line.sale_line.product_id" t-if="can_display_phantom" />
7142
</xpath>
72-
<xpath expr="//td[@name='move_line_lot_qty_done']" position="attributes">
43+
<xpath expr="//td[@name='move_line_lot_quantity']" position="attributes">
7344
<attribute name="t-if">not can_display_phantom</attribute>
7445
</xpath>
75-
<xpath expr="//td[@name='move_line_lot_qty_done']" position="after">
46+
<xpath expr="//td[@name='move_line_lot_quantity']" position="after">
7647
<td class="text-center" t-if="can_display_phantom">
7748
<span t-field="move_line.phantom_delivered_qty" />
7849
<span t-field="move_line.sale_line.product_uom" />

stock_picking_report_valued_sale_mrp/tests/test_stock_picking_report_valued_mrp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def setUpClass(cls):
1818
{"name": "Product test 1", "type": "consu"}
1919
)
2020
cls.product_kit_comp_1 = cls.product_product.create(
21-
{"name": "Product Component 1", "type": "product"}
21+
{"name": "Product Component 1", "type": "consu"}
2222
)
2323
cls.product_kit_comp_2 = cls.product_product.create(
24-
{"name": "Product Component 2", "type": "product"}
24+
{"name": "Product Component 2", "type": "consu"}
2525
)
2626
cls.bom = cls.env["mrp.bom"].create(
2727
{
@@ -43,7 +43,7 @@ def setUpClass(cls):
4343
}
4444
)
4545
cls.product_2 = cls.product_product.create(
46-
{"name": "Product test 2", "type": "product"}
46+
{"name": "Product test 2", "type": "consu"}
4747
)
4848
order_form = Form(cls.env["sale.order"])
4949
order_form.partner_id = cls.partner
@@ -64,7 +64,7 @@ def setUpClass(cls):
6464

6565
def test_01_picking_confirmed(self):
6666
for line in self.order_out_picking.move_ids:
67-
line.quantity_done = line.product_uom_qty
67+
line.quantity = line.product_uom_qty
6868
self.order_out_picking.button_validate()
6969
self.assertAlmostEqual(self.order_out_picking.amount_untaxed, 149.5)
7070
self.assertAlmostEqual(self.order_out_picking.amount_tax, 14.95)

0 commit comments

Comments
 (0)