summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order_line.py
blob: b4be9ffcec9b8a639f5e8a81d5f664f1547f02dc (plain)
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