Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add total weight in shipment #46049

Merged
merged 5 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion erpnext/stock/doctype/shipment/shipment.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"shipment_parcel",
"parcel_template",
"add_template",
"total_weight",
"column_break_28",
"shipment_delivery_note",
"shipment_details_section",
Expand Down Expand Up @@ -429,11 +430,17 @@
"label": "Pickup Contact Person",
"mandatory_depends_on": "eval:doc.pickup_from_type === 'Company'",
"options": "User"
},
{
"fieldname": "total_weight",
"fieldtype": "Float",
"label": "Total Weight (kg)",
"read_only": 1
}
],
"is_submittable": 1,
"links": [],
"modified": "2024-03-27 13:10:41.030764",
"modified": "2025-02-20 16:55:20.076418",
"modified_by": "Administrator",
"module": "Stock",
"name": "Shipment",
Expand Down
8 changes: 8 additions & 0 deletions erpnext/stock/doctype/shipment/shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Shipment(Document):
shipment_parcel: DF.Table[ShipmentParcel]
shipment_type: DF.Literal["Goods", "Documents"]
status: DF.Literal["Draft", "Submitted", "Booked", "Cancelled", "Completed"]
total_weight: DF.Float
tracking_status: DF.Literal["", "In Progress", "Delivered", "Returned", "Lost"]
tracking_status_info: DF.Data | None
tracking_url: DF.SmallText | None
Expand All @@ -75,6 +76,7 @@ def validate(self):
self.validate_weight()
self.validate_pickup_time()
self.set_value_of_goods()
self.set_total_weight()
if self.docstatus == 0:
self.status = "Draft"

Expand All @@ -93,6 +95,12 @@ def validate_weight(self):
if flt(parcel.weight) <= 0:
frappe.throw(_("Parcel weight cannot be 0"))

def set_total_weight(self):
self.total_weight = self.get_total_weight()

def get_total_weight(self):
return sum(flt(parcel.weight) * parcel.count for parcel in self.shipment_parcel if parcel.count > 0)

def validate_pickup_time(self):
if self.pickup_from and self.pickup_to and get_time(self.pickup_to) < get_time(self.pickup_from):
frappe.throw(_("Pickup To time should be greater than Pickup From time"))
Expand Down
11 changes: 11 additions & 0 deletions erpnext/stock/doctype/shipment/test_shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def test_shipment_from_delivery_note(self):
self.assertEqual(len(second_shipment.shipment_delivery_note), 1)
self.assertEqual(second_shipment.shipment_delivery_note[0].delivery_note, delivery_note.name)

def test_get_total_weight(self):
shipment = frappe.new_doc("Shipment")
shipment.extend(
"shipment_parcel",
[
{"length": 5, "width": 5, "height": 5, "weight": 5, "count": 5},
{"length": 5, "width": 5, "height": 5, "weight": 10, "count": 1},
],
)
self.assertEqual(shipment.get_total_weight(), 35)


def create_test_delivery_note():
company = get_shipment_company()
Expand Down
Loading