0

In the sales application, when creating a new quotation I am adding the pricelist for a specific customer, and when adding the product the unit price is automatically updated according to the pricelist chosen. I want when changing the price manually and if the unit price became less than the unit price defined by the pricelist, I want to ask for admin approval. How can I do that in odoo 15?

altela
  • 306
  • 2
  • 13

1 Answers1

0

First, let's say we have a fields called product_id that will contain the user's selection product.

Assumes that you already defining the fields for your manual price (let's call it manual_price), you can later define the self.env[] to call the price list model you defined. From this self.env, you can do .search to access all record inside that model to find your price based on the product_id inputted.

Later, you can define @api.onchange function to oversee the user's change. From this function, you can define the "comparison" of your manual_price with the self.env result we previously fetch.

This may not fully work but i hope you get the idea :

product_id = fields.Many2one("Product Name")

the_pricelist = self.env['product.pricelist.item'].search([('product_id', '=', product_id.id)
manual_price = fields.String("Sales Price")

@api.onchange('manual_price')
    def check_the_changes(self):
        if self.manual_price < the_pricelist.fixed_price:
          raise UserError('The selected price is less than defined in 
          pricelist. please contact admin.')
altela
  • 306
  • 2
  • 13