1
votes

i inherited from the product.template to add some customer fields , i'm trying to make those fields appear in the product page on the website and it's not working , i had this error:

'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:

this is my code in the main of controllers :

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

this the xml code :

<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>

this the python file :

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')])

THANKS IN ADVANCE =)

1
In product(), you are always passing an empty string to the parent's category and search parameters, rather than passing along the values supplied by the caller. Surely this is part of the problem...kindall
i still have the same problem @kindall 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) return resHello_world

1 Answers

0
votes

The t-field directive can only be used when performing field access (a.b) on a "smart" record (the result of the browse method).

The error message tells us that Catimmo is of NoneType (maybe used before declaration)

In your template, when you use:

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

Odoo will try to get the surface field from Catimmo record, make sure Catimmo is defined and it is a smart record.

The product record is available and can be used inside website_sale.product_price.

Set the surface of your product and try to use product instead of Catimmo variable:

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