1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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'}
|