'NoneType'对象没有属性'_fields' (ODOO 12)



我从 product.template 继承了一些客户字段,我正在尝试让这些字段出现在网站上的产品页面中,但它不起作用,我遇到了这个错误:

">

NoneType"对象没有属性"_fields"回溯(最新 最后调用):文件 "c:\program files (x86)\odoo 12.0\服务器\odoo\addons\base\models\qweb.py",第 347 行,_compiled_fn 返回编译(自身、追加、新建、选项、日志) 文件 ",第 1 行,在 template_website_sale_product_price_297
文件 "c:\program files (x86)\odoo 12.0\服务器\odoo\addons\base\models\ir_qweb.py",第 368 行,_get_field field = record._fields[field_name] 属性错误:"NoneType"对象没有属性"_fields">

呈现编译 AST 属性错误时出错:"NoneType"对象没有 属性"_fields"模板:website_sale.产品价格路径:/templates/t/span 节点:

这是我在控制器主中的代码:

from odoo import http
from odoo.http import request
from odoo.addons.website_sale.controllers.main import WebsiteSale

class WebsiteSaleInherit(WebsiteSale):
@http.route(['/shop/product/<model("product.template"):product>'], type='http', auth="public", website=True)
def product(self, product, category='', search='', **kwargs):
res = super(WebsiteSaleInherit, self).product(product, category='', search='', **kwargs)
return res

这是XML代码:

<odoo>
<template id="website_inherit" inherit_id="website_sale.product_price" customize_show="True" name="property details">
<xpath expr="//div[@class='product_price mt16']" position="after">
<p> Informations :</p>
<span t-field="Catimmo.surface"/>
</xpath>
</template>
</odoo>

这是蟒蛇文件:

import logging
from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)

class Catimmo(models.Model):
#_name = "catimmo"
_inherit = 'product.template'
surface = fields.Float(string='Surface')
prop = fields.Char(string="Proprietaire")
ref = fields.Char(string="Reference")
immo_cat = fields.Selection(string='Categorie', selection=
[('appartement', 'Appartement'), ('maison', 'Maison'), ('terrain', 'Terrain'), ('local', 'Local commercial'),
('bureau', 'Bureau'), ('garage_parking', 'Garage/Parking')], required=True)
immo_titre = fields.Char('Titre de l'"annonce", required=True)
immo_date = fields.Datetime('Date de publication')
img_one = fields.Binary('Image Num 1 ')
img_two = fields.Binary('Image Num 2 ')
nbre_ch = fields.Integer(string="Nombre des chambres", required=True)
pr = fields.Float(string="Prix du bien immobilier")
type_immob = fields.Selection(selection=
[('appartement', 'Appartement'), ('maison', 'Maison'), ('terrain', 'Terrain'),
('local', 'Local commercial'),
('bureau', 'Bureau'), ('garage_parking', 'Garage/Parking')])

提前感谢=)

t-field指令只能在对"智能">记录(browse方法的结果)执行字段访问(a.b)时使用。

错误消息告诉我们CatimmoNoneType(可能在声明之前使用)

在模板中,当您使用:

<span t-field="Catimmo.surface"/>

Odoo将尝试从Catimmo记录中获取surface字段,确保Catimmo已定义并且它是一个智能记录。

product记录可用,可以在website_sale.product_price内部使用。

设置产品的表面并尝试使用product而不是变量Catimmo

<span t-field="product.surface"/>

最新更新