Skip to content

Commit 38003a7

Browse files
[IMP] purchase_order_line_sequence: use correct sequence in moves when section or notes in purchase order
1 parent d0e6c2c commit 38003a7

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

purchase_order_line_sequence/models/purchase.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def _compute_max_line_sequence(self):
2727

2828
def _create_picking(self):
2929
res = super(PurchaseOrder, self)._create_picking()
30+
self._update_moves_sequence()
31+
return res
32+
33+
def _update_moves_sequence(self):
3034
for order in self:
3135
if any(
3236
[
@@ -39,11 +43,13 @@ def _create_picking(self):
3943
)
4044
if pickings:
4145
picking = pickings[0]
46+
order_lines = order.order_line.filtered(
47+
lambda l: l.product_id.type in ["product", "consu"]
48+
)
4249
for move, line in zip(
43-
sorted(picking.move_lines, key=lambda m: m.id), order.order_line
50+
sorted(picking.move_lines, key=lambda m: m.id), order_lines
4451
):
4552
move.write({"sequence": line.sequence})
46-
return res
4753

4854
def _reset_sequence(self):
4955
for rec in self:
@@ -55,6 +61,8 @@ def _reset_sequence(self):
5561
def write(self, line_values):
5662
res = super(PurchaseOrder, self).write(line_values)
5763
self._reset_sequence()
64+
if "order_line" in line_values:
65+
self._update_moves_sequence()
5866
return res
5967

6068
def copy(self, default=None):

purchase_order_line_sequence/tests/test_po_lines_sequence.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,91 @@ def test_purchase_order_line_sequence(self):
134134
"The Sequence is not copied properly",
135135
)
136136

137+
def test_purchase_order_line_sequence_with_section_note(self):
138+
"""
139+
Verify that the sequence is correctly assigned to the move associated
140+
with the purchase order line it references.
141+
"""
142+
po = self._create_purchase_order()
143+
self.PurchaseOrderLine.create(
144+
{
145+
"name": "Section 1",
146+
"display_type": "line_section",
147+
"order_id": po.id,
148+
"product_qty": 0,
149+
}
150+
)
151+
self.PurchaseOrderLine.create(
152+
{
153+
"name": self.product_id_1.name,
154+
"product_id": self.product_id_1.id,
155+
"product_qty": 15.0,
156+
"product_uom": self.product_id_1.uom_po_id.id,
157+
"price_unit": 150.0,
158+
"date_planned": datetime.today().strftime(
159+
DEFAULT_SERVER_DATETIME_FORMAT
160+
),
161+
"order_id": po.id,
162+
}
163+
)
164+
self.PurchaseOrderLine.create(
165+
{
166+
"name": "Note 1",
167+
"display_type": "line_note",
168+
"order_id": po.id,
169+
"product_qty": 0,
170+
}
171+
)
172+
self.PurchaseOrderLine.create(
173+
{
174+
"name": self.product_id_2.name,
175+
"product_id": self.product_id_2.id,
176+
"product_qty": 1.0,
177+
"product_uom": self.product_id_2.uom_po_id.id,
178+
"price_unit": 50.0,
179+
"date_planned": datetime.today().strftime(
180+
DEFAULT_SERVER_DATETIME_FORMAT
181+
),
182+
"order_id": po.id,
183+
}
184+
)
185+
po.button_confirm()
186+
187+
moves = po.picking_ids[0].move_ids_without_package
188+
self.assertNotEquals(len(po.order_line), len(moves))
189+
190+
for move in moves:
191+
self.assertEqual(move.sequence, move.purchase_line_id.sequence)
192+
193+
def test_write_purchase_order_line(self):
194+
po = self._create_purchase_order()
195+
po.button_confirm()
196+
197+
po.write(
198+
{
199+
"order_line": [
200+
(
201+
0,
202+
0,
203+
{
204+
"name": self.product_id_2.name,
205+
"product_id": self.product_id_2.id,
206+
"product_qty": 2,
207+
"product_uom": self.product_id_2.uom_id.id,
208+
"price_unit": 30,
209+
"date_planned": datetime.today().strftime(
210+
DEFAULT_SERVER_DATETIME_FORMAT
211+
),
212+
},
213+
)
214+
]
215+
}
216+
)
217+
218+
moves = po.picking_ids[0].move_ids_without_package
219+
for move in moves:
220+
self.assertEqual(move.sequence, move.purchase_line_id.sequence)
221+
137222
def test_invoice_sequence(self):
138223

139224
po = self._create_purchase_order()

0 commit comments

Comments
 (0)