details:   https://code.tryton.org/tryton/commit/e4a952622aec
branch:    default
user:      Cédric Krier <[email protected]>
date:      Fri Aug 29 14:38:40 2025 +0200
description:
        Forbid resetting to draft cancelled shipment from Shopify

        Closes #14207
diffstat:

 modules/web_shop_shopify/message.xml |   3 +++
 modules/web_shop_shopify/stock.py    |  16 +++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diffs (45 lines):

diff -r cdc632a60b8a -r e4a952622aec modules/web_shop_shopify/message.xml
--- a/modules/web_shop_shopify/message.xml      Mon Sep 29 13:16:49 2025 +0200
+++ b/modules/web_shop_shopify/message.xml      Fri Aug 29 14:38:40 2025 +0200
@@ -79,5 +79,8 @@
         <record model="ir.message" id="msg_fulfillment_order_line_not_found">
             <field name="text">Failed to find fulfillment order for 
%(quantity)s of move "%(move)s".</field>
         </record>
+        <record model="ir.message" id="msg_shipment_cancelled_draft_shopify">
+            <field name="text">You cannot reset shipment "%(shipment)s" to 
draft because it is linked to a Shopify fulfillment.</field>
+        </record>
     </data>
 </tryton>
diff -r cdc632a60b8a -r e4a952622aec modules/web_shop_shopify/stock.py
--- a/modules/web_shop_shopify/stock.py Mon Sep 29 13:16:49 2025 +0200
+++ b/modules/web_shop_shopify/stock.py Fri Aug 29 14:38:40 2025 +0200
@@ -7,7 +7,8 @@
 from shopify.resources.fulfillment import FulfillmentV2
 
 from trytond.i18n import gettext, lazy_gettext
-from trytond.model import ModelSQL, ModelView, Unique, fields
+from trytond.model import ModelSQL, ModelView, Unique, Workflow, fields
+from trytond.model.exceptions import AccessError
 from trytond.pool import Pool, PoolMeta
 
 from .common import IdentifierMixin
@@ -98,6 +99,19 @@
         default.setdefault('shopify_identifiers')
         return super().copy(records, default=default)
 
+    @classmethod
+    @ModelView.button
+    @Workflow.transition('draft')
+    def draft(cls, shipments):
+        for shipment in shipments:
+            if shipment.state == 'cancelled' and shipment.shopify_identifiers:
+                raise AccessError(
+                    gettext(
+                        'web_shop_shopify.'
+                        'msg_shipment_cancelled_draft_shopify',
+                        shipment=shipment.rec_name))
+        super().draft(shipments)
+
 
 class ShipmentShopifyIdentifier(IdentifierMixin, ModelSQL, ModelView):
     __name__ = 'stock.shipment.shopify_identifier'

Reply via email to