fix: prevent duplicate shipping charges without cost center

(cherry picked from commit a4134af30b)

# Conflicts:
#	erpnext/selling/doctype/sales_order/test_sales_order.py
This commit is contained in:
Mihir Kandoi
2026-08-02 12:01:35 +05:30
committed by Mergify
parent 8bef78afda
commit a6dff3fc47
2 changed files with 48 additions and 1 deletions

View File

@@ -161,7 +161,16 @@ class ShippingRule(Document):
)
shipping_charge["add_deduct_tax"] = "Add"
existing_shipping_charge = doc.get("taxes", filters=shipping_charge)
shipping_charge_filters = shipping_charge.copy()
if not self.cost_center:
# Blank Link values can be None on the server or an empty string from the client.
# Child-table defaults can also resolve a blank value to the company default.
shipping_charge_filters["cost_center"] = (
"in",
(None, "", erpnext.get_default_cost_center(doc.company)),
)
existing_shipping_charge = doc.get("taxes", filters=shipping_charge_filters)
if existing_shipping_charge:
# take the last record found
existing_shipping_charge[-1].tax_amount = shipping_amount