Discount and Margin in Sales invoice items

Hi,

I have issue with discount and margin in Sales invoice item,
I have custom child table in Customer doctype, and I need to apply the discount in the sales invoice for each customer depend on the child table,

But when I update the fields (discount percentage, discount amount) it’s not update the rate and amount,

I think I miss some built in functionality

  def validate(self):
    customer = frappe.get_doc("Customer", self.customer)
    for i in customer.item_group_discount:
      for j in self.items:
        if i.item_group == j.item_group:
          j.margin_type = "Amount"
          j.discount_percentage = i.discount_percentage
          j.discount_amount = (j.rate * (j.discount_percentage / 100))

This what I see after validate, it’s fetch the right discount percentage but without any impact

Any help ?

I solve it

Hy @Omar_Mohammed can you tell how you solved this? and Here is my scenario, my item amount is 100 which is tax rate inclusive with 15 % which means the item price is 86.96. so when i apply discount percentage as 10% it is taking the 10% of 100 rather than 86.96. How can i achieve this discount amount calculation based on net_rate rather than price_list_rate in the sales invoice item table. Any solution for this customisation?