首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从继承模型Odoo 9中获取字段

从继承模型Odoo 9中获取字段
EN

Stack Overflow用户
提问于 2016-02-18 14:48:48
回答 2查看 664关注 0票数 0

我正试图从我继承的模型中获得字段。

代码语言:javascript
复制
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,但是结果是一样的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-18 15:00:56

你不需要每次写order_line.price_unit,而只需要写price_unit

票数 2
EN

Stack Overflow用户

发布于 2016-02-19 11:21:57

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

在“依赖”attr中,添加"sale“作为您继承的模块,因为它包含sale.order.line声明。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35484646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档