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
|
from odoo import fields, models, api
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
# Override method from addons/purchase/models/purchase.py
@api.onchange('product_qty', 'product_uom')
def _onchange_quantity(self):
res = super(PurchaseOrderLine, self)._onchange_quantity()
# Custom script
purchase_pricelist = self.env['purchase.pricelist'].search([
('product_id', '=', self.product_id.id),
('vendor_id', '=', self.partner_id.id)
], limit=1)
price_unit = purchase_pricelist.product_price
if not price_unit:
product_supplierinfo = self.env['product.supplierinfo'].search([
('product_tmpl_id', '=', self.product_id.product_tmpl_id.id),
('name', '=', self.partner_id.id)
], limit=1)
price_unit = product_supplierinfo.price
self.price_unit = price_unit
return res
|