mokiSRB
mokiSRB

Reputation: 1162

Get field from inherited model Odoo 9

I am trying to get field from model I inherited.

from openerp import api, fields, models

class Calculate(models.Model):
    _inherit = 'sale.order.line'
    company_discount = fields.Float(string='Company Discount')
    customer_discount = fields.Float(string='Customer Discount')
    company_price_amount_total = fields.Monetary(string='Price after discount', store=True, readonly=True, compute='_calc_company_price', track_visibility='always')
    customer_price_amount = fields.Monetary(string='Customer price', store=True, readonly=True, compute='_calc_customer_price', track_visibility='always')
    transport  = fields.Float(string='Transport')
    transport_amount = fields.Monetary(string='Transport amount', store=True, readonly=True, compute='_calc_transport', track_visibility='always')

    @api.depends('order_line.price_unit', 'customer_discount')
    def _calc_customer_price(self):
        self.customer_price_amount = self.order_line.price_unit * ((100 - self.customer_discount) / 100)

    @api.depends('order_line.price_unit', 'company_discount', 'customer_discount')
    def _calc_company_price(self):
         self.company_price_amount_total = self.order_line.price_unit * ((100 - self.customer_discount) / 100) * ((100 - self.company_discount) / 100)

    @api.depends('customer_price_amount', 'transport')
    def _calc_transport(self):
        self.transport_amount = self.customer_price_amount * ((100 - self.transport) / 100)

I am getting error NameError: global name 'price_unit' is not defined.

Field price_unit is in model sale.order.line which I inherit.

UPDATE:

I have tried both price_unit and sale.order.line.price_unit but with same result.

Upvotes: 0

Views: 670

Answers (2)

dccdany
dccdany

Reputation: 836

Adding inheriting in the py is one of the two steps to do the correct inheriting. What i think you are missing is adding it on the openerp.py file.

In the "depends" attr add "sale" as the module you inherit since it contains the sale.order.line declaration.

Upvotes: 1

Alessandro Ruffolo
Alessandro Ruffolo

Reputation: 1575

You don't need to write everytime order_line.price_unit but just price_unit

Upvotes: 2

Related Questions