from odoo import models, fields class PurchasePricelistWizard(models.TransientModel): _name = 'purchase.pricelist.wizard' _description = 'Wizard Create Purchase Pricelist' product_id = fields.Many2one('product.product', string="Product", required=True) vendor_id = fields.Many2one('res.partner', string="Vendor", required=True, domain="[('supplier_rank','>',0)]") price = fields.Float(string="Price", required=True) def action_create_pricelist(self): self.ensure_one() existing = self.env['purchase.pricelist'].search([ ('product_id', '=', self.product_id.id) ], limit=1) if existing: existing.vendor_id = self.vendor_id.id existing.price = self.price return {'type': 'ir.actions.act_window_close'} self.env['purchase.pricelist'].create({ 'product_id': self.product_id.id, 'vendor_id': self.vendor_id.id, 'price': self.price, }) return {'type': 'ir.actions.act_window_close'}