[已解决]继承sale.order添加字段,报错KeyError,是不能related吗
-
在一个
trainee
模块中继承了sale.orderclass Trainee_order(models.Model): _inherit = 'sale.order' order_source_name = fields.Char(string=u'来源姓名')
所有功能都正常,字段也能正常使用,但是在更新sale.order的时候就会报错
File "E:\greenodoo10-win-20170722\shaddockerp\odoo10\odoo\models.py", line 2851, in _setup_fields field.setup_full(self) File "E:\greenodoo10-win-20170722\shaddockerp\odoo10\odoo\fields.py", line 506, in setup_full self._setup_related_full(model) File "E:\greenodoo10-win-20170722\shaddockerp\odoo10\odoo\fields.py", line 543, in _setup_related_full field = target._fields[name] KeyError: 'order_source_name'
开始不知道原因,后来发现好像是related的问题
class Maternity_Matron_Order_Manage(models.Model): _name = 'maternity_matron.order' order_id = fields.Many2one('sale.order', domain=[( 'state', '=', 'sale')], ondelete='cascade', string=u'订单') order_source = fields.Char(related='order_id.order_source_name', string=u'订单来源')
貌似去掉related就不会报错,请教一下这是什么原因,我这么分析的对吗,应该怎么解决这种问题,
trainee
与maternity_matron
不在同一模块中