0

我正在尝试从我继承的模型中获取字段。

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)

我收到错误NameError: global name 'price_unit' is not defined

字段在我继承price_unit的模型中。sale.order.line

更新:

我都尝试过price_unitsale.order.line.price_unit但结果相同。

4

2 回答 2

2

您不需要每次都写order_line.price_unit而只需写price_unit

于 2016-02-18T15:00:56.267 回答
1

在 py 中添加继承是进行正确继承的两个步骤之一。我认为您缺少的是在openerp .py 文件中添加它。

在“depends”属性中添加“sale”作为您继承的模块,因为它包含 sale.order.line 声明。

于 2016-02-19T11:21:57.127 回答