Merge pull request #25374 from ankush/shipment_status_update
fix: commit changes to shipment status in database
diff --git a/.github/helper/semgrep_rules/frappe_correctness.yml b/.github/helper/semgrep_rules/frappe_correctness.yml
index 394abbf..54df062 100644
--- a/.github/helper/semgrep_rules/frappe_correctness.yml
+++ b/.github/helper/semgrep_rules/frappe_correctness.yml
@@ -7,11 +7,29 @@
- pattern-inside: |
def on_submit(self, ...):
...
+ - metavariable-regex:
+ metavariable: '$ATTR'
+ # this is negative look-ahead, add more attrs to ignore like (ignore|ignore_this_too|ignore_me)
+ regex: '^(?!status_updater)(.*)$'
message: |
Doctype modified after submission. Please check if modification of self.$ATTR is commited to database.
languages: [python]
severity: ERROR
+- id: frappe-modifying-after-cancel
+ patterns:
+ - pattern: self.$ATTR = ...
+ - pattern-inside: |
+ def on_cancel(self, ...):
+ ...
+ - metavariable-regex:
+ metavariable: '$ATTR'
+ regex: '^(?!ignore_linked_doctypes|status_updater)(.*)$'
+ message: |
+ Doctype modified after cancellation. Please check if modification of self.$ATTR is commited to database.
+ languages: [python]
+ severity: ERROR
+
- id: frappe-print-function-in-doctypes
pattern: print(...)
message: |
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 112f6d8..620cc5b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -772,3 +772,4 @@
erpnext.patches.v13_0.fix_non_unique_represents_company
erpnext.patches.v12_0.add_document_type_field_for_italy_einvoicing
erpnext.patches.v13_0.make_non_standard_user_type #13-04-2021
+erpnext.patches.v13_0.update_shipment_status
diff --git a/erpnext/patches/v13_0/update_shipment_status.py b/erpnext/patches/v13_0/update_shipment_status.py
new file mode 100644
index 0000000..c425599
--- /dev/null
+++ b/erpnext/patches/v13_0/update_shipment_status.py
@@ -0,0 +1,14 @@
+import frappe
+
+def execute():
+ frappe.reload_doc("stock", "doctype", "shipment")
+
+ # update submitted status
+ frappe.db.sql("""UPDATE `tabShipment`
+ SET status = "Submitted"
+ WHERE status = "Draft" AND docstatus = 1""")
+
+ # update cancelled status
+ frappe.db.sql("""UPDATE `tabShipment`
+ SET status = "Cancelled"
+ WHERE status = "Draft" AND docstatus = 2""")
diff --git a/erpnext/stock/doctype/shipment/shipment.py b/erpnext/stock/doctype/shipment/shipment.py
index 4697a7b..01fcee4 100644
--- a/erpnext/stock/doctype/shipment/shipment.py
+++ b/erpnext/stock/doctype/shipment/shipment.py
@@ -23,10 +23,10 @@
frappe.throw(_('Please enter Shipment Parcel information'))
if self.value_of_goods == 0:
frappe.throw(_('Value of goods cannot be 0'))
- self.status = 'Submitted'
+ self.db_set('status', 'Submitted')
def on_cancel(self):
- self.status = 'Cancelled'
+ self.db_set('status', 'Cancelled')
def validate_weight(self):
for parcel in self.shipment_parcel: