Skip to content

Commit c971b7d

Browse files
committed
[REF] stock_picking_mail_incorrect_qty: Use stock.move.line instead of stock.move
For some reason---on some databases---there is a discrepancy between the two when manually adding items to the picking. stock.move.line would contain the new item, but stock.move wouldn't. Using stock.move.line here seems like a decent enough work-around. Signed-off-by: Carmen Bianca Bakker <[email protected]>
1 parent 80145ba commit c971b7d

2 files changed

Lines changed: 48 additions & 42 deletions

File tree

stock_picking_mail_incorrect_qty/data/mail_template.xml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,46 @@
1313
<field name="lang">${ctx.get("lang")}</field>
1414
<field name="body_html" type="html">
1515
<div>
16-
<p>One or several products in <a href="${object.form_view_url()}">${object.name}</a> were received in incorrect amounts.</p>
16+
<p>One or several products in <a
17+
href="${object.form_view_url()}"
18+
>${object.name}</a> were received in incorrect amounts.</p>
1719

18-
% if object.zero_received_move_ids:
20+
% if object.zero_received_move_line_ids:
1921
<p>Zero received:</p>
2022
<ul>
21-
% for move in object.zero_received_move_ids:
22-
<li>${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}</li>
23+
% for line in object.zero_received_move_line_ids:
24+
<li
25+
>${line.product_id.name} --- Received ${line.qty_done} out of expected ${line.product_qty}</li>
2326
% endfor
2427
</ul>
2528
% endif
2629

27-
% if object.zero_expected_move_ids:
30+
% if object.zero_expected_move_line_ids:
2831
<p>Received, but expected zero:</p>
2932
<ul>
30-
% for move in object.zero_expected_move_ids:
31-
<li>${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}</li>
33+
% for line in object.zero_expected_move_line_ids:
34+
<li
35+
>${line.product_id.name} --- Received ${line.qty_done} out of expected ${line.product_qty}</li>
3236
% endfor
3337
</ul>
3438
% endif
3539

36-
% if object.too_few_received_move_ids:
40+
% if object.too_few_received_move_line_ids:
3741
<p>Received too few:</p>
3842
<ul>
39-
% for move in object.too_few_received_move_ids:
40-
<li>${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}</li>
43+
% for line in object.too_few_received_move_line_ids:
44+
<li
45+
>${line.product_id.name} --- Received ${line.qty_done} out of expected ${line.product_qty}</li>
4146
% endfor
4247
</ul>
4348
% endif
4449

45-
% if object.too_many_received_move_ids:
50+
% if object.too_many_received_move_line_ids:
4651
<p>Received too many:</p>
4752
<ul>
48-
% for move in object.too_many_received_move_ids:
49-
<li>${move.name} --- Received ${move.quantity_done} out of expected ${move.product_qty}</li>
53+
% for line in object.too_many_received_move_line_ids:
54+
<li
55+
>${line.product_id.name} --- Received ${line.qty_done} out of expected ${line.product_qty}</li>
5056
% endfor
5157
</ul>
5258
% endif

stock_picking_mail_incorrect_qty/models/stock_picking.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
class Picking(models.Model):
1010
_inherit = "stock.picking"
1111

12-
zero_received_move_ids = fields.One2many(
13-
"stock.move",
14-
string="Stock moves that were not received",
12+
zero_received_move_line_ids = fields.One2many(
13+
"stock.move.line",
14+
string="Stock move lines that were not received",
1515
compute="_compute_move_discrepancy",
1616
)
17-
zero_expected_move_ids = fields.One2many(
18-
"stock.move",
19-
string="Stock moves of which some were received, but none were expected",
17+
zero_expected_move_line_ids = fields.One2many(
18+
"stock.move.line",
19+
string="Stock move lines of which some were received, but none were expected",
2020
compute="_compute_move_discrepancy",
2121
)
22-
too_few_received_move_ids = fields.One2many(
23-
"stock.move",
24-
string="Stock moves of which too few were received",
22+
too_few_received_move_line_ids = fields.One2many(
23+
"stock.move.line",
24+
string="Stock move lines of which too few were received",
2525
compute="_compute_move_discrepancy",
2626
)
27-
too_many_received_move_ids = fields.One2many(
28-
"stock.move",
29-
string="Stock moves of which too many were received",
27+
too_many_received_move_line_ids = fields.One2many(
28+
"stock.move.line",
29+
string="Stock move lines of which too many were received",
3030
compute="_compute_move_discrepancy",
3131
)
3232

3333
@api.multi
34-
@api.depends("move_lines")
34+
@api.depends("move_line_ids")
3535
def _compute_move_discrepancy(self):
3636
for picking in self:
3737
# The following filter is also used in upstream action_done()
38-
filtered_moves = picking.mapped("move_lines").filtered(
39-
lambda move: move.state
38+
filtered_moves = picking.mapped("move_line_ids").filtered(
39+
lambda line: line.state
4040
in [
4141
"draft",
4242
"waiting",
@@ -46,19 +46,19 @@ def _compute_move_discrepancy(self):
4646
]
4747
)
4848

49-
picking.zero_received_move_ids = filtered_moves.filtered(
50-
lambda move: move.quantity_done == 0 and move.product_qty
49+
picking.zero_received_move_line_ids = filtered_moves.filtered(
50+
lambda line: line.qty_done == 0 and line.product_qty
5151
)
52-
picking.zero_expected_move_ids = filtered_moves.filtered(
53-
lambda move: move.quantity_done and move.product_qty == 0
52+
picking.zero_expected_move_line_ids = filtered_moves.filtered(
53+
lambda line: line.qty_done and line.product_qty == 0
5454
)
55-
picking.too_few_received_move_ids = filtered_moves.filtered(
56-
lambda move: move.quantity_done != 0
57-
and move.quantity_done < move.product_qty
55+
picking.too_few_received_move_line_ids = filtered_moves.filtered(
56+
lambda line: line.qty_done != 0
57+
and line.qty_done < line.product_qty
5858
)
59-
picking.too_many_received_move_ids = filtered_moves.filtered(
60-
lambda move: move.quantity_done > move.product_qty
61-
and move.product_qty != 0
59+
picking.too_many_received_move_line_ids = filtered_moves.filtered(
60+
lambda line: line.qty_done > line.product_qty
61+
and line.product_qty != 0
6262
)
6363

6464
@api.multi
@@ -115,10 +115,10 @@ def _notify_incorrect_delivery(self):
115115
for picking in self:
116116
if not any(
117117
(
118-
picking.zero_received_move_ids,
119-
picking.zero_expected_move_ids,
120-
picking.too_few_received_move_ids,
121-
picking.too_many_received_move_ids,
118+
picking.zero_received_move_line_ids,
119+
picking.zero_expected_move_line_ids,
120+
picking.too_few_received_move_line_ids,
121+
picking.too_many_received_move_line_ids,
122122
)
123123
):
124124
continue

0 commit comments

Comments
 (0)