Hello, i create a field on each product category to add extra cost on the products but i want to be able to change this extra cost on the quotation tree
(i dont want the change to be saved on the category, i want the change to save only on the quotation for this time only)
i add the field to the quotation tree i change the extra cost and its working but when i save the quotation the extra cost resets backs to the default (the cost that i add on the product categories)
Here is the code the field is the extra_cost
@api.depends('order_line.extra_cost_amount','order_line.product_uom_qty','order_line.real_cost_amount','order_line.purchase_price')
def _extra_cost(self):
for order in self:
extra_cost = real_cost_amount = total_real_cost_amount = total_cost = 0
for line in order.order_line:
#if line.state != 'cancel':
extra_cost += line.extra_cost_amount * line.product_uom_qty
real_cost_amount += line.real_cost_amount
total_real_cost_amount += line.real_cost_amount * line.product_uom_qty
total_cost += line.purchase_price * line.product_uom_qty
line.extra_cost_amount = (line.purchase_price * line.extra_cost) / 100
line.real_cost_amount = line.extra_cost_amount + line.purchase_price
order.extra_cost = line.extra_cost
order.real_cost_amount = line.real_cost_amount
order.total_real_cost_amount = total_real_cost_amount
order.extra_cost_per = ((order.extra_cost / total_cost)*100) if total_cost else 0
# total_amount = order.amount_after_discount if order.apply_discount else order.amount_untaxed
total_amount = order.amount_untaxed
real_margin = total_amount - order.total_real_cost_amount
order.real_margin = real_margin
order.real_margin_per = (real_margin * 100)/total_amount if total_amount else 100