fix: set margin fields for purchase documents when updating items

This commit is contained in:
Sagar Vora
2024-10-02 13:11:13 +05:30
parent deccb007c1
commit 7be4d56be2

View File

@@ -3313,7 +3313,6 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil
items_added_or_removed = False # updated to true if any new item is added or removed items_added_or_removed = False # updated to true if any new item is added or removed
any_conversion_factor_changed = False any_conversion_factor_changed = False
sales_doctypes = ["Sales Order", "Sales Invoice", "Delivery Note", "Quotation"]
parent = frappe.get_doc(parent_doctype, parent_doctype_name) parent = frappe.get_doc(parent_doctype, parent_doctype_name)
check_doc_permissions(parent, "write") check_doc_permissions(parent, "write")
@@ -3429,8 +3428,6 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil
# if rate is greater than price_list_rate, set margin # if rate is greater than price_list_rate, set margin
# or set discount # or set discount
child_item.discount_percentage = 0 child_item.discount_percentage = 0
if parent_doctype in sales_doctypes:
child_item.margin_type = "Amount" child_item.margin_type = "Amount"
child_item.margin_rate_or_amount = flt( child_item.margin_rate_or_amount = flt(
child_item.rate - child_item.price_list_rate, child_item.rate - child_item.price_list_rate,
@@ -3443,8 +3440,6 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil
child_item.precision("discount_percentage"), child_item.precision("discount_percentage"),
) )
child_item.discount_amount = flt(child_item.price_list_rate) - flt(child_item.rate) child_item.discount_amount = flt(child_item.price_list_rate) - flt(child_item.rate)
if parent_doctype in sales_doctypes:
child_item.margin_type = "" child_item.margin_type = ""
child_item.margin_rate_or_amount = 0 child_item.margin_rate_or_amount = 0
child_item.rate_with_margin = 0 child_item.rate_with_margin = 0