Skip to content

Commit

Permalink
Merge pull request #1 from barredterra/add-total-weight
Browse files Browse the repository at this point in the history
test: add total weight
  • Loading branch information
ravibharathi656 authored Feb 21, 2025
2 parents beb5381 + 2eb1564 commit 5c1f7bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 6 additions & 6 deletions erpnext/stock/doctype/shipment/shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def validate(self):
self.validate_weight()
self.validate_pickup_time()
self.set_value_of_goods()
self.calculate_total_weight()
self.set_total_weight()
if self.docstatus == 0:
self.status = "Draft"

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

def calculate_total_weight(self):
weight_of_goods = sum(
flt(parcel.weight) * parcel.count for parcel in self.shipment_parcel if parcel.count > 0
)
self.total_weight = weight_of_goods
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):
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

0 comments on commit 5c1f7bb

Please sign in to comment.