fix: Margin and Discount percentage set correctly via 'Update Items' (#19276)

This commit is contained in:
Marica 2019-10-11 10:47:09 +05:30 committed by Nabin Hait
parent 39d9cbc43d
commit f067447d9c

View File

@ -1195,10 +1195,22 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil
child_item.rate = flt(d.get("rate"))
if flt(child_item.price_list_rate):
discount = flt((1 - flt(child_item.rate) / flt(child_item.price_list_rate)) * 100.0,
child_item.precision("discount_percentage"))
if discount > 0:
child_item.discount_percentage = discount
if flt(child_item.rate) > flt(child_item.price_list_rate):
# if rate is greater than price_list_rate, set margin
# or set discount
child_item.discount_percentage = 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)
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: