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

test: add total weight #1

Merged
merged 2 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
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
Loading