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

'NoneType' object has no attribute '_fields' (ODOO 12)

我从 product.template 继承来添加一些客户字段,我试图让这些字段出现在网站的产品页面中,但它不起作用,我有这个错误:

'NoneType' object has no attribute '_fields' Traceback (most recent call last): File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\qweb.py", line 347, in _compiled_fn return compiled(self, append, new, options, log) File "", line 1, in template_website_sale_product_price_297
File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_qweb.py", line 368, in _get_field field = record._fields[field_name] AttributeError: 'NoneType' object has no attribute '_fields'

Error to render compiling AST AttributeError: 'NoneType' object has no attribute '_fields' Template: website_sale.product_price Path: /templates/t/span Node:

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

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>

这是 python 文件 :

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指令只能在对“智能”记录执行字段访问(a.b)时使用(browse方法)。

报错信息告诉我们Catimmo属于NoneType(可能在声明前使用)

在您的模板中,当您使用:

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

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

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

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

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