Odoo 从其他模块检索字段
Odoo retrieve field from other module
Odoo 10
我正在尝试将一个字段从产品复制到销售订单。产品中的字段称为 default_code。我已经尝试从销售订单模块复制代码,因为它已经获得了单价和税金等,但无法正常工作。
from odoo import api, models, fields
class myfieldsinsaleorder(models.Model):
_inherit = 'sale.order.line'
squaremtr = fields.Float("SQ Meter Required")
boxes = fields.Float("Suggested Boxes")
squarebox = fields.Char("Meters Per Box")
@api.onchange('product_id', 'default_code', 'price_unit', 'product_uom', 'product_uom_qty', 'tax_id')
def _onchange_discount(self):
self.discount = 0.0
self.squarebox = 'default_code'
它现在正在做的是插入 default_code 文本而不是字段的值
你应该使用这个:
self.squarebox = self.product_id.default_code
当你这样做时:
self.squarebox = 'default_code'
就像:self.squarebox = 'string not a value of the field'
您设置的是字符串而不是字段,试试这个:
self.squarebox = self.product_id.default_code
Odoo 10
我正在尝试将一个字段从产品复制到销售订单。产品中的字段称为 default_code。我已经尝试从销售订单模块复制代码,因为它已经获得了单价和税金等,但无法正常工作。
from odoo import api, models, fields
class myfieldsinsaleorder(models.Model):
_inherit = 'sale.order.line'
squaremtr = fields.Float("SQ Meter Required")
boxes = fields.Float("Suggested Boxes")
squarebox = fields.Char("Meters Per Box")
@api.onchange('product_id', 'default_code', 'price_unit', 'product_uom', 'product_uom_qty', 'tax_id')
def _onchange_discount(self):
self.discount = 0.0
self.squarebox = 'default_code'
它现在正在做的是插入 default_code 文本而不是字段的值
你应该使用这个:
self.squarebox = self.product_id.default_code
当你这样做时:
self.squarebox = 'default_code'
就像:self.squarebox = 'string not a value of the field'
您设置的是字符串而不是字段,试试这个:
self.squarebox = self.product_id.default_code