值错误:字段不存在 [Odoo 12]



我正试图从account.invoice模块的销售订单中获取client_order_ref。我不知道为什么它说这个域不存在,它定义了这个域。请帮我

Python代码

from odoo import models, fields, api, _
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
client_order_ref = fields.Char(string="Client Order Ref", compute="get_client_from_sale_order")
@api.depends('name')
def get_client_from_sale_order(self):
self.ensure_one()
for rec in self:
sale_order = self.env['sale.order'].search(
[('name', '=', rec.origin)]
)
rec.client_order_ref = sale_order.client_order_ref

XML代码

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="invoice_tree" model="ir.ui.view">
<field name="name">account_invoice_tree_inherit</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="client_order_ref"/>
</xpath>
</field>
</record>
</odoo>

回溯

错误:Odoo服务器错误

Traceback(最近一次通话):文件"opt/odo/custom/src/odo/odo/models.py";,第1128行,在_验证字段check(self)File"/opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第351行,在_check_xml中self.postprocess_and_fields(view.model,view_doc,view.id)文件"opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第1138行,在postprocess_and_fields中self.raise_view_error(消息,view_id)文件"opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第568行,在raise_view_error中引发ValueError(消息)ValueError:字段client_order_ref不存在

错误上下文:视图account_invoice_tree_inherit[View_id:1311,xml_id:cloudpiles_custom.invoice_tree,型号:account.invoice,parent_id:681]

在处理上述异常的过程中,发生了另一个异常:

Traceback(最近一次通话):文件"opt/odo/custom/src/odo/odo/tools/convert.py";,第758行,解析中自我_tags[rec.tag](rec,de,mode=mode)文件"/opt/odo/custom/src/odo/odo/tools/convert.py";,第663行,在_标签记录record=model.with_context(rec_context)_load_records([data],self.mode=='update')文件"opt/odo/custom/src/odo/odo/models.py";,第3883行,in_加载记录数据[记录]_load_records_write(data[‘values’])文件"/opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第1542行,在_load_records_write中super(视图,self)_load_records_write(values)File"/opt/odo/custom/src/odo/odo/models.py";,3821行,英寸_load_records_writeself.write(values)文件"/opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第445行,写入res=super(View,self).write(self.compute_defaults(vals))File"/opt/odo/custom/src/odo/odo/models.py";,第3392行,写入fields[0]。determine_ inverse(记录)File"/opt/odoo/custom/src/odoo/odoo/fields.py";,第1200行,英寸确定_逆getattr(records,self.inverse)()文件"opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第275行,在_inverse_arch中view.write(数据)文件"/opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第445行,写入res=super(View,self).write(self.compute_defaults(vals))File"/opt/odo/custom/src/odo/odo/models.py";,第3366行,写入自我_写入(store_vals)文件"/opt/odo/custom/src/odo/odo/models.py";,写入中的第3502行自我_validate_fields(vals)文件"/opt/odo/custom/src/odo/odo/models.py";,第1132行,in验证字段引发验证错误("%s\n\n%s"%(("验证约束时出错"),tools.uster(e)))odoo.exceptions.ValidationError:('错误验证约束时\n\n字段client_order_ref没有存在\n\n错误上下文:\n视图account_invoice_tree_inherit\n[view_id:1311,xml_id:cloudpiles_custom.invoice_tree,型号:account.invoice,parent_id:681]',无)

在处理上述异常的过程中,发生了另一个异常:

Traceback(最近一次通话):文件"opt/odo/custom/src/odo/odo/http.py";,第656行,in_handle_exceptionreturn super(JsonRequest,self)_handle_exception(exception)文件"/opt/odo/custom/src/odo/odo/http.py";,第314行,in_handle_exception提升pycompat.reraise(type(exception),exception,sys.exc_info()[2])文件"opt/odo/custom/src/odo/odo/tools/pycompat.py";,第87行,in加注提升值文件"/opt/odo/custom/src/odo/odo/http.py";,698行,发送中结果=自我_call_function(**self.params)文件"/opt/odo/custom/src/odo/odo/http.py";,_call_function中的第346行return checked_call(self.db,*args,**kwargs)文件"opt/odo/custom/src/odo/odo/service/model.py";,第98行,包装中return f(dbname,*args,**kwargs)文件"opt/odo/custom/src/odo/odo/http.py";,第339行,checked_callresult=self.endpoint(*a,**kw)File"/opt/odo/custom/src/odo/odo/http.py";,第941行,在调用中返回self.method(*args,**kw)File"/opt/odo/custom/src/odo/odo/http.py";,第519行,在response_wrap中响应=f(*args,**kw)文件"/opt/odoo/auto/addons/web/controllers/main.py";,第967行,在呼叫按钮行动=自我_call_kw(模型,方法,args,{})文件"opt/odoo/auto/addons/web/controllers/main.py";,线路955,in _call_kwreturn call_kw(request.env[model],method,args,kwargs)File"opt/odo/custom/src/odo/odo/api.py";,线路759,呼叫_kwreturn _call_kw_multi(方法、模型、args、kwargs)文件"opt/odo/custom/src/odo/odo/api.py";,第746行,在_call_kw_multi中result=方法(recs,*args,**kwargs)文件"&";,第2行,在button_immediate_upgrade文件中"opt/odo/custom/src/odo/odo/addons/base/models/ir_module.py";,线75,在check_and.log中return方法(self,*args,**kwargs)File"opt/odo/custom/src/odo/odo/addons/base/models/ir_module.py";,线628,在button_immediate_upgrade中回归自我_button_immediate_function(type(self).button_pgrade)File/opt/odo/custom/src/odo/odo/addons/base/models/ir_module.py";,第562行,在_button_immediate_function中modules.registry.registry.new(self.cr.dbname,update_module=True)文件"opt/odo/custom/src/odo/odo/modules/register.py";,第86行,in新odoo.modules.load_modules(registry.db,force_demo,status,update_module)文件"opt/odo/custom/src/odo/odo/modules/loading.py";,第417行,in加载模块force、status、report、loaded_modules、update_module、models_to_check)文件"opt/odo/custom/src/odo/odo/modules/loading.py";,第313行,在load_marked_modulesperform_checks=perform_checks,models_to_check=models_to_check文件"opt/odo/custom/src/odo/odo/modules/loading.py";,第222行,in加载模块图load_data(cr,idref,mode,kind='data',package=package,report=report)文件"opt/odo/custom/src/odo/odo/modules/loading.py";,第68行,in加载数据tools.convert_file(cr,package.name,filename,idref,mode,noupdate,kind,report)文件"opt/odo/custom/src/odo/odo/tools/convert.py";,第802行,在convert_fileconvert_xml_import(cr,module,fp,idref,mode,noupdate,report)文件"opt/odo/custom/src/odo/odo/tools/convert.py";,线路865,inconvert_xml_importobj.parse(doc.getroot(),mode=mode)文件"opt/odo/custom/src/odo/odo/tools/convert.py";,第764行,解析中exc_info[2]文件"/opt/odo/custom/src/odo/odo/tools/pycompat.py";,第86行,in加注raise-value.with_traceback(tb)文件"opt/odo/custom/src/odo/odo/tools/convert.py";,第758行,解析中自我_tags[rec.tag](rec,de,mode=mode)文件"/opt/odo/custom/src/odo/odo/tools/convert.py";,第663行,在_标签记录record=model.with_context(rec_context)_load_records([data],self.mode=='update')文件"opt/odo/custom/src/odo/odo/models.py";,第3883行,in_加载记录数据[记录]_load_records_write(data[‘values’])文件"/opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第1542行,在_load_records_write中super(视图,self)_load_records_write(values)File"/opt/odo/custom/src/odo/odo/models.py";,3821行,英寸_load_records_writeself.write(values)文件"/opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第445行,写入res=super(View,self).write(self.compute_defaults(vals))File"/opt/odo/custom/src/odo/odo/models.py";,第3392行,写入fields[0]。determine_ inverse(记录)File"/opt/odoo/custom/src/odoo/odoo/fields.py";,第1200行,英寸确定_逆getattr(records,self.inverse)()文件"opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第275行,在_inverse_arch中view.write(数据)文件"/opt/odo/custom/src/odo/odo/addons/base/models/ir_ui_view.py";,第445行,写入res=super(View,self).write(self.compute_defaults(vals))File"/opt/odo/custom/src/odo/odo/models.py";,第3366行,写入自我_写入(store_vals)文件"/opt/odo/custom/src/odo/odo/models.py";,写入中的第3502行自我_validate_fields(vals)文件"/opt/odo/custom/src/odo/odo/models.py";,第1132行,in验证字段raise ValidationError("%s\n\n%s"%(("验证约束时出错"),tools.uster(e))odoo.tools.covert.ParseError:";错误在验证约束时

字段client_order_ref不存在

错误上下文:视图account_invoice_tree_inherit[View_id:1311,xml_id:cloudpiles_custom.invoice_tree,型号:account.invoice,parent_id:681]无";分析时/opt/odoo/auto/addons/cloudpiles_custom/views/account_invoice_view.xml:3,近的account_invoice_tree_inheritaccount.invoice

我想,您忘记了从odoo模型继承的一个重要点。。。当你在odoo的模块中的现有模型上添加一个新字段时,首先你必须用命令升级你的模块,而不是用odoo接口。。。只需运行以下命令:./odoo-bin -c /etc/odoo-server.conf -d data_base_name -u module_name我希望这对你有帮助。

相关内容

  • 没有找到相关文章

最新更新