|
1 | 1 | # Copyright 2021 Camptocamp SA
|
| 2 | +# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de> |
2 | 3 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
3 | 4 |
|
4 | 5 | from unittest import mock
|
5 | 6 |
|
6 | 7 | from lxml import etree
|
7 | 8 |
|
8 |
| -from odoo.tests.common import SavepointCase |
| 9 | +from odoo.tests.common import Form, SavepointCase |
9 | 10 | from odoo.tools.safe_eval import safe_eval
|
10 | 11 |
|
11 | 12 | SEND_SHIPPING_RETURN_VALUE = [{"exact_price": 10.0, "tracking_number": "TEST"}]
|
@@ -82,10 +83,19 @@ def setUpClass(cls):
|
82 | 83 | )
|
83 | 84 | (cls.picking | cls.packing | cls.shipping).sale_id = cls.order
|
84 | 85 |
|
85 |
| - def _validate_picking(self, picking): |
| 86 | + def _validate_picking(self, picking, qty_done=None): |
86 | 87 | 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)]) |
89 | 99 |
|
90 | 100 | def test_send_to_shipper_on_ship(self):
|
91 | 101 | """Check sending of delivery notification on ship.
|
@@ -195,3 +205,48 @@ def test_picking_fields_view_get(self):
|
195 | 205 | attrs_str = button_send_to_shipper.attrib["attrs"]
|
196 | 206 | attrs = safe_eval(attrs_str)
|
197 | 207 | 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