【发布时间】:2023-03-27 16:07:01
【问题描述】:
我从 product.template 继承来添加一些客户字段,我试图让这些字段出现在网站的产品页面中,但它不起作用,我遇到了这个错误:
'NoneType' 对象没有属性 '_fields' Traceback(最近 最后调用):文件“c:\程序文件(x86)\odoo 12.0\server\odoo\addons\base\models\qweb.py",第 347 行,在 _compiled_fn 返回已编译(self、append、new、options、log)文件“”,第 1 行,在 template_website_sale_product_price_297
文件“c:\程序文件(x86)\odoo 12.0\server\odoo\addons\base\models\ir_qweb.py",第 368 行,在 _get_field field = record._fields[field_name] AttributeError: 'NoneType' 对象没有属性 '_fields'渲染编译 AST AttributeError 时出错:“NoneType”对象没有 属性“_fields”模板:website_sale.product_price 路径: /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>
这是 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')])
提前致谢 =)
【问题讨论】:
-
在
product()中,您总是将一个空字符串传递给父级的category和search参数,而不是传递调用者提供的值。这当然是问题的一部分...... -
我仍然有同样的问题 @kindall class WebsiteSaleInherit(WebsiteSale): @http.route(['/shop/product/
'], type ='http', auth="public", website=True) def product(self, product, category='', search='', **kwargs): res = super(WebsiteSaleInherit, self).product(product,类别,搜索)返回资源
标签: python python-3.x odoo odoo-11 odoo-12