Skip to content

Commit

Permalink
fix: set margin fields for purchase documents when updating items
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarvora committed Oct 2, 2024
1 parent deccb00 commit 59880b0
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3313,7 +3313,6 @@ def validate_fg_item_for_subcontracting(new_data, is_new):
items_added_or_removed = False # updated to true if any new item is added or removed
any_conversion_factor_changed = False

sales_doctypes = ["Sales Order", "Sales Invoice", "Delivery Note", "Quotation"]
parent = frappe.get_doc(parent_doctype, parent_doctype_name)

check_doc_permissions(parent, "write")
Expand Down Expand Up @@ -3429,25 +3428,22 @@ def validate_fg_item_for_subcontracting(new_data, is_new):
# if rate is greater than price_list_rate, set margin
# or set discount
child_item.discount_percentage = 0

if parent_doctype in sales_doctypes:
child_item.margin_type = "Amount"
child_item.margin_rate_or_amount = flt(
child_item.rate - child_item.price_list_rate,
child_item.precision("margin_rate_or_amount"),
)
child_item.rate_with_margin = child_item.rate
child_item.discount_amount = 0
child_item.margin_type = "Amount"
child_item.margin_rate_or_amount = flt(
child_item.rate - child_item.price_list_rate,
child_item.precision("margin_rate_or_amount"),
)
child_item.rate_with_margin = child_item.rate
else:
child_item.discount_percentage = flt(
(1 - flt(child_item.rate) / flt(child_item.price_list_rate)) * 100.0,
child_item.precision("discount_percentage"),
)
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_rate_or_amount = 0
child_item.rate_with_margin = 0
child_item.margin_type = ""
child_item.margin_rate_or_amount = 0
child_item.rate_with_margin = 0

child_item.flags.ignore_validate_update_after_submit = True
if new_child_flag:
Expand Down

0 comments on commit 59880b0

Please sign in to comment.