Skip to Content
Menu
This question has been flagged
2 Replies
1934 Views

Hello, I would like to reduce 2000 on the price of an item in sale.order.line if the field "with_cloth" is checked.
How to test the values ​​of the form and apply the reduction before saving ?
Thank you

Avatar
Discard
Best Answer

Hello Mame Penda Bathily,

Try below code:

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    with_cloth = fields.Boolean('With Cloth')     #Add this field in view.

    @api.onchange('with_cloth')
    def onchange_with_cloth(self):
        if self.with_cloth:
            self.price_unit = self.product_id.lst_price - 2000
        else:
            self.price_unit = self.product_id.lst_price


Hope this will helps you.
Thanks,

Avatar
Discard
Author Best Answer

Thank you so much! It's Work ;)

Avatar
Discard

Please up vote the answer and accepted as resolved. Thanks,