Skip to content

Commit fdb7424

Browse files
[FIX] delivery_send_to_shipper_at_operation:
Keep delivery_notification_sent set on backorder
1 parent 079aaf5 commit fdb7424

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

delivery_send_to_shipper_at_operation/README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Delivery Send To Shipper at Operation
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:e08f1bae901fa7fb9746e9bc036a58e909da57a7dcad28411a0f362e3bd8cf56
10+
!! source digest: sha256:d6b3c50aa624dc5204efd61e8a83a4461eda6686e22c698c3ddf888598957c7d
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -95,6 +95,7 @@ Contributors
9595
* `Trobz <https://trobz.com>`_:
9696
* Nguyen Hoang Hiep <hiepnh@trobz.com>
9797
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
98+
* Michael Tietz (MT Software) <mtietz@mt-software.de>
9899

99100
Other credits
100101
~~~~~~~~~~~~~

delivery_send_to_shipper_at_operation/models/stock_picking.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2021 Camptocamp SA
22
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
3+
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de>
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
45

56
from lxml import etree
@@ -51,7 +52,6 @@ def _handle_send_to_shipper_at_operation(self):
5152
self.with_context(skip_delivery_cost=True).send_to_shipper()
5253
# Flag the current operation and the ship one.
5354
# Mandatory to not execute twice 'send_to_shipper' method
54-
self.delivery_notification_sent = True
5555
related_ship.delivery_notification_sent = True
5656
related_ship.carrier_price = self.carrier_price
5757
if not related_ship.carrier_tracking_ref:
@@ -111,3 +111,13 @@ def _fields_view_get_adapt_send_to_shipper_attrs(self, view_arch):
111111
)
112112
transfer_modifiers_to_node(modifiers, field)
113113
return etree.tostring(doc, encoding="unicode")
114+
115+
def _create_backorder(self):
116+
backorders = super()._create_backorder()
117+
for backorder in backorders:
118+
delivery_notification_sent = (
119+
backorder.backorder_id.delivery_notification_sent
120+
)
121+
if delivery_notification_sent:
122+
backorder.delivery_notification_sent = delivery_notification_sent
123+
return backorders

delivery_send_to_shipper_at_operation/readme/CONTRIBUTORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
* `Trobz <https://trobz.com>`_:
33
* Nguyen Hoang Hiep <hiepnh@trobz.com>
44
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
5+
* Michael Tietz (MT Software) <mtietz@mt-software.de>

delivery_send_to_shipper_at_operation/static/description/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
23
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
34
<head>
@@ -366,7 +367,7 @@ <h1 class="title">Delivery Send To Shipper at Operation</h1>
366367
!! This file is generated by oca-gen-addon-readme !!
367368
!! changes will be overwritten. !!
368369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369-
!! source digest: sha256:e08f1bae901fa7fb9746e9bc036a58e909da57a7dcad28411a0f362e3bd8cf56
370+
!! source digest: sha256:d6b3c50aa624dc5204efd61e8a83a4461eda6686e22c698c3ddf888598957c7d
370371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/delivery-carrier/tree/14.0/delivery_send_to_shipper_at_operation"><img alt="OCA/delivery-carrier" src="https://img.shields.io/badge/github-OCA%2Fdelivery--carrier-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/delivery-carrier-14-0/delivery-carrier-14-0-delivery_send_to_shipper_at_operation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/delivery-carrier&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372373
<p>This module allows to send the delivery notification to the carrier when
@@ -444,6 +445,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
444445
</dl>
445446
</li>
446447
<li>Jacques-Etienne Baudoux (BCIM) &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
448+
<li>Michael Tietz (MT Software) &lt;<a class="reference external" href="mailto:mtietz&#64;mt-software.de">mtietz&#64;mt-software.de</a>&gt;</li>
447449
</ul>
448450
</div>
449451
<div class="section" id="other-credits">

delivery_send_to_shipper_at_operation/tests/test_send_to_shipper.py

+59-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Copyright 2021 Camptocamp SA
2+
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
34

45
from unittest import mock
56

67
from lxml import etree
78

8-
from odoo.tests.common import SavepointCase
9+
from odoo.tests.common import Form, SavepointCase
910
from odoo.tools.safe_eval import safe_eval
1011

1112
SEND_SHIPPING_RETURN_VALUE = [{"exact_price": 10.0, "tracking_number": "TEST"}]
@@ -82,10 +83,19 @@ def setUpClass(cls):
8283
)
8384
(cls.picking | cls.packing | cls.shipping).sale_id = cls.order
8485

85-
def _validate_picking(self, picking):
86+
def _validate_picking(self, picking, qty_done=None):
8687
for ml in picking.move_line_ids:
87-
ml.qty_done = ml.product_uom_qty
88-
picking._action_done()
88+
ml.qty_done = qty_done or ml.product_uom_qty
89+
action_data = picking.button_validate()
90+
if not action_data or action_data is True:
91+
return picking.browse()
92+
backorder_wizard = Form(
93+
self.env["stock.backorder.confirmation"].with_context(
94+
action_data["context"]
95+
)
96+
).save()
97+
backorder_wizard.process()
98+
return self.env["stock.picking"].search([("backorder_id", "=", picking.id)])
8999

90100
def test_send_to_shipper_on_ship(self):
91101
"""Check sending of delivery notification on ship.
@@ -195,3 +205,48 @@ def test_picking_fields_view_get(self):
195205
attrs_str = button_send_to_shipper.attrib["attrs"]
196206
attrs = safe_eval(attrs_str)
197207
self.assertIn(("delivery_notification_sent", "=", True), attrs["invisible"])
208+
209+
def test_send_to_shipper_on_partial_pack(self):
210+
"""Check if a backorder of a transfer, where the delivery notification is already sent
211+
keeps the delivery notification sent set.
212+
"""
213+
with mock.patch.object(
214+
type(self.carrier_on_pack),
215+
"send_shipping",
216+
return_value=SEND_SHIPPING_RETURN_VALUE,
217+
):
218+
self.shipping.carrier_id = self.carrier_on_pack
219+
self._validate_picking(self.picking)
220+
pack_backorder = self._validate_picking(self.packing, 5)
221+
self.assertTrue(self.shipping.delivery_notification_sent)
222+
self.assertFalse(pack_backorder.delivery_notification_sent)
223+
self._validate_picking(pack_backorder, 5)
224+
self.assertTrue(self.shipping.delivery_notification_sent)
225+
backorder = self._validate_picking(self.shipping, 5)
226+
self.assertEqual(self.shipping.state, "done")
227+
self.assertTrue(self.shipping.delivery_notification_sent)
228+
self.assertTrue(backorder.delivery_notification_sent)
229+
backorder2 = self._validate_picking(backorder, 5)
230+
self.assertFalse(backorder2)
231+
self.assertTrue(backorder.delivery_notification_sent)
232+
233+
def test_send_to_shipper_on_pack_partial_shipping(self):
234+
"""Check if a backorder of a transfer, where the delivery notification is already sent
235+
keeps the delivery notification sent set.
236+
"""
237+
with mock.patch.object(
238+
type(self.carrier_on_pack),
239+
"send_shipping",
240+
return_value=SEND_SHIPPING_RETURN_VALUE,
241+
):
242+
self.shipping.carrier_id = self.carrier_on_pack
243+
self._validate_picking(self.picking)
244+
self._validate_picking(self.packing)
245+
self.assertTrue(self.shipping.delivery_notification_sent)
246+
backorder = self._validate_picking(self.shipping, 5)
247+
self.assertEqual(self.shipping.state, "done")
248+
self.assertTrue(self.shipping.delivery_notification_sent)
249+
self.assertTrue(backorder.delivery_notification_sent)
250+
backorder2 = self._validate_picking(backorder, 5)
251+
self.assertFalse(backorder2)
252+
self.assertTrue(backorder.delivery_notification_sent)

0 commit comments

Comments
 (0)