Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2282 Zobrazení

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


Avatar
Zrušit
Nejlepší odpověď

Hi,

You can update the extra_cost in the XML file

Use the force save attribute in the XML code force_save="1"

<field name="extra_cost" force_save="1"/>


Regards

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
kvě 25
1716
1
dub 25
1280
3
zář 24
14167
2
úno 24
2463
1
čvc 23
2723