Skip to content

Commit 1943d84

Browse files
[IMP] purchase_manual_delivery: refactor out context key on confirmation
1 parent 14d3197 commit 1943d84

9 files changed

+40
-54
lines changed

purchase_manual_delivery/README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ only PO lines from same PO can be selected) and create the manual
7878
delivery. Follow the same steps as above to manually generate the
7979
incoming shipment.
8080

81+
If, as a developer, you need to override the behaviour you can call
82+
``purchase.order``'s ``button_confirm`` with context key
83+
``ignore_manual_delivery=True``.
84+
8185
.. |image1| image:: https://raw.githubusercontent.com/OCA/purchase-workflow/18.0/purchase_manual_delivery/static/description/create_incoming_shipment_button.png
8286
.. |image2| image:: https://raw.githubusercontent.com/OCA/purchase-workflow/18.0/purchase_manual_delivery/static/description/create_incoming_shipment_wizard.png
8387

purchase_manual_delivery/models/purchase_order.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,9 @@ def _compute_pending_to_receive(self):
3131
order.order_line.mapped("pending_to_receive")
3232
)
3333

34-
def button_confirm_manual(self):
35-
return super(
36-
PurchaseOrder, self.with_context(manual_delivery=True)
37-
).button_confirm()
38-
39-
def button_approve(self, force=False):
40-
if self.manual_delivery:
41-
self = self.with_context(manual_delivery=True)
42-
return super().button_approve(force=force)
43-
4434
def _create_picking(self):
45-
if self.env.context.get("manual_delivery", False) and self.manual_delivery:
46-
# We do not want to create the picking when confirming the order
47-
# if it comes from manual confirmation
48-
return
49-
return super()._create_picking()
35+
if self.env.context.get("ignore_manual_delivery"):
36+
orders = self
37+
else:
38+
orders = self.filtered(lambda po: not po.manual_delivery)
39+
return super(PurchaseOrder, orders)._create_picking()

purchase_manual_delivery/readme/USAGE.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ Menu). From there you can select multiple PO lines (in this base module
2323
only PO lines from same PO can be selected) and create the manual
2424
delivery. Follow the same steps as above to manually generate the
2525
incoming shipment.
26+
27+
If, as a developer, you need to override the behaviour you can call
28+
`purchase.order`'s `button_confirm` with context key `ignore_manual_delivery=True`.

purchase_manual_delivery/static/description/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
422422
only PO lines from same PO can be selected) and create the manual
423423
delivery. Follow the same steps as above to manually generate the
424424
incoming shipment.</p>
425+
<p>If, as a developer, you need to override the behaviour you can call
426+
<tt class="docutils literal">purchase.order</tt>’s <tt class="docutils literal">button_confirm</tt> with context key
427+
<tt class="docutils literal">ignore_manual_delivery=True</tt>.</p>
425428
</div>
426429
<div class="section" id="bug-tracker">
427430
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>

purchase_manual_delivery/tests/test_purchase_manual_delivery.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_01_purchase_order_manual_delivery(self):
8787
add second PO line to same picking afterwards)
8888
"""
8989
# confirm RFQ
90-
self.po1.button_confirm_manual()
90+
self.po1.button_confirm()
9191
self.assertTrue(self.po1_line1.pending_to_receive)
9292
self.assertTrue(self.po1_line2.pending_to_receive)
9393
self.assertEqual(self.po1_line1.qty_in_receipt, 0)
@@ -225,8 +225,8 @@ def test_02_purchase_order_line_manual_delivery(self):
225225
for two PO lines from same PO twice.
226226
"""
227227
# confirm RFQ
228-
self.po1.button_confirm_manual()
229-
self.po2.button_confirm_manual()
228+
self.po1.button_confirm()
229+
self.po2.button_confirm()
230230
self.assertTrue(self.po1_line1.pending_to_receive)
231231
self.assertTrue(self.po1_line2.pending_to_receive)
232232
self.assertTrue(self.po2_line1.pending_to_receive)
@@ -279,7 +279,7 @@ def test_03_purchase_order_line_location(self):
279279
grp_multi_loc = self.env.ref("stock.group_stock_multi_locations")
280280
self.env.user.write({"groups_id": [(4, grp_multi_loc.id, 0)]})
281281
# confirm RFQ
282-
self.po1.button_confirm_manual()
282+
self.po1.button_confirm()
283283
self.assertTrue(self.po1_line1.pending_to_receive)
284284
self.assertTrue(self.po1_line2.pending_to_receive)
285285
self.assertEqual(self.po1_line1.qty_in_receipt, 0)
@@ -332,7 +332,7 @@ def test_04_pending_to_receive(self):
332332
"product_qty": 5.0,
333333
}
334334
)
335-
po_existing_bigger.button_confirm_manual()
335+
po_existing_bigger.button_confirm()
336336
# create a manual delivery for line in po_existing_bigger
337337
wizard = (
338338
self.env["create.stock.picking.wizard"]
@@ -391,7 +391,7 @@ def test_05_purchase_order_in_progress(self):
391391
"product_qty": 5.0,
392392
}
393393
)
394-
po_in_progress.button_confirm_manual()
394+
po_in_progress.button_confirm()
395395
location = self.env["stock.location"].browse(
396396
po_in_progress.picking_type_id.default_location_dest_id.id
397397
)
@@ -470,7 +470,7 @@ def test_06_purchase_order_manual_delivery_double_validation(self):
470470
)
471471

472472
# confirm RFQ
473-
self.po.button_confirm_manual()
473+
self.po.button_confirm()
474474
self.assertTrue(self.po.order_line.pending_to_receive)
475475
self.assertEqual(self.po.order_line.qty_in_receipt, 0)
476476
self.assertFalse(
@@ -489,3 +489,20 @@ def test_06_purchase_order_manual_delivery_double_validation(self):
489489
"Purchase Manual Delivery: no picking should had been created",
490490
)
491491
self.assertEqual(self.po.state, "purchase")
492+
493+
def test_07_purchase_order_ignore_manual_delivery(self):
494+
"""Manual delivery can be overridden with a context key during confirmation"""
495+
self.po1.with_context(ignore_manual_delivery=True).button_confirm()
496+
self.assertTrue(
497+
self.po1.picking_ids,
498+
"Context key failed to trigger picking creation",
499+
)
500+
self.assertTrue(
501+
self.po1.picking_ids.move_ids,
502+
"Context key failed to trigger stock move creation",
503+
)
504+
for line in self.po1.order_line:
505+
self.assertFalse(
506+
line.pending_to_receive,
507+
"Context key did not create stock moves for all quantities",
508+
)

purchase_manual_delivery/tests/test_report_forecast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setUpClass(cls):
2828

2929
def test_report_forecast(self):
3030
"""PO quantities without deliveries are mentioned on the forecast report"""
31-
self.po1.button_confirm_manual()
31+
self.po1.button_confirm()
3232
# Create delivery for a part of the ordered quantity
3333
wizard = (
3434
self.env["create.stock.picking.wizard"]

purchase_manual_delivery/views/purchase_order_line_views.xml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3-
43
<record id="purchase_order_line_tree" model="ir.ui.view">
54
<field name="model">purchase.order.line</field>
65
<field name="inherit_id" ref="purchase.purchase_order_line_tree" />
@@ -40,5 +39,4 @@
4039
</group>
4140
</field>
4241
</record>
43-
4442
</odoo>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3-
43
<record id="purchase_order_view_form_inherit" model="ir.ui.view">
54
<field name="name">purchase.order.form</field>
65
<field name="model">purchase.order</field>
@@ -16,31 +15,6 @@
1615
invisible="state != 'purchase' or not pending_to_receive or not manual_delivery"
1716
/>
1817
</xpath>
19-
<button id="draft_confirm" position="attributes">
20-
<attribute name="invisible">1</attribute>
21-
</button>
22-
<button id="draft_confirm" position="after">
23-
<button
24-
name="button_confirm_manual"
25-
type="object"
26-
invisible="state != 'draft'"
27-
string="Confirm Order"
28-
id="draft_confirm_manual"
29-
/>
30-
</button>
31-
<button id="bid_confirm" position="attributes">
32-
<attribute name="invisible">1</attribute>
33-
</button>
34-
<button id="bid_confirm" position="after">
35-
<button
36-
name="button_confirm_manual"
37-
type="object"
38-
invisible="state != 'sent'"
39-
string="Confirm Order"
40-
class="oe_highlight"
41-
id="bid_confirm_manual"
42-
/>
43-
</button>
4418
<field name="qty_received" position="before">
4519
<field name="pending_to_receive" column_invisible="1" />
4620
<field
@@ -62,5 +36,4 @@
6236
</group>
6337
</field>
6438
</record>
65-
6639
</odoo>

purchase_manual_delivery/wizard/create_manual_stock_picking.xml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3-
43
<record id="view_create_stock_picking" model="ir.ui.view">
54
<field name="name">Create Stock Picking</field>
65
<field name="model">create.stock.picking.wizard</field>
@@ -59,5 +58,4 @@
5958
<field name="target">new</field>
6059
<field name="binding_model_id" ref="purchase.model_purchase_order_line" />
6160
</record>
62-
6361
</odoo>

0 commit comments

Comments
 (0)