feat: add total weight in shipment (#46049)
Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
(cherry picked from commit 1ec182430d)
# Conflicts:
# erpnext/stock/doctype/shipment/shipment.json
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
"shipment_parcel",
|
||||
"parcel_template",
|
||||
"add_template",
|
||||
"total_weight",
|
||||
"column_break_28",
|
||||
"shipment_delivery_note",
|
||||
"shipment_details_section",
|
||||
@@ -429,11 +430,21 @@
|
||||
"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": [],
|
||||
<<<<<<< HEAD
|
||||
"modified": "2022-11-17 17:23:27.025802",
|
||||
=======
|
||||
"modified": "2025-02-20 16:55:20.076418",
|
||||
>>>>>>> 1ec182430d (feat: add total weight in shipment (#46049))
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Shipment",
|
||||
|
||||
@@ -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
|
||||
@@ -75,6 +76,7 @@ class Shipment(Document):
|
||||
self.validate_weight()
|
||||
self.validate_pickup_time()
|
||||
self.set_value_of_goods()
|
||||
self.set_total_weight()
|
||||
if self.docstatus == 0:
|
||||
self.status = "Draft"
|
||||
|
||||
@@ -93,6 +95,12 @@ class Shipment(Document):
|
||||
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"))
|
||||
|
||||
@@ -20,6 +20,17 @@ class TestShipment(FrappeTestCase):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user