Skip to Content
Menu
This question has been flagged
1 Reply
2011 Views

I am trying to add field "company_registry" to the footer layout of my company documents.

Initially I thought I succeeded in doing so: After I made a code change in layout external_layout_background, both the preview and the actual documents come out correctly,.

However when  invoking the "settings", "general settings", business documents, "configure document layout", the system produces the error:

AttributeError: 'base.document.layout' object has no attribute 'company_registry'


All I did in the code of external_layout_background, was to make a copy of the line which displays the website and replace the field "company.website", by the field "company.company_registry". It is filled out correctly in my company data.


Full error message:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 685, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 361, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 349, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 914, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 533, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1394, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1386, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 399, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 386, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 6278, in onchange
    snapshot1 = Snapshot(record, nametree)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 6069, in __init__
    self.fetch(name)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 6079, in fetch
    self[name] = record[name]
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 5686, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1021, in __get__
    self.compute_value(recs)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1177, in compute_value
    records._compute_field_value(self)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4069, in _compute_field_value
    getattr(self, field.compute)()
  File "/usr/lib/python3/dist-packages/odoo/addons/web/models/base_document_layout.py", line 102, in _compute_preview
    wizard.preview = ir_ui_view._render_template('web.report_invoice_wizard_preview', {'company': wizard, 'preview_css': preview_css})
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1708, in _render_template
    return self.browse(self.get_view_id(template))._render(values, engine)
  File "/usr/lib/python3/dist-packages/odoo/addons/web_editor/models/ir_ui_view.py", line 28, in _render
    return super(IrUiView, self)._render(values=values, engine=engine, minimal_qcontext=minimal_qcontext)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1716, in _render
    return self.env[engine]._render(self.id, qcontext)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_qweb.py", line 55, in _render
    result = super(IrQWeb, self)._render(id_or_xml_id, values=values, **context)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 258, in _render
    self.compile(template, options)(self, body.append, values or {})
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 333, in _compiled_fn
    raise e
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 331, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "", line 1, in template_web_report_invoice_wizard_preview_308
  File "", line 2, in body_call_content_306
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 333, in _compiled_fn
    raise e
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 331, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "", line 1, in template_web_external_layout_319
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 338, in _compiled_fn
    raise QWebException("Error to render compiling AST", e, path, node and etree.tostring(node[0], encoding='unicode'), name)
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 641, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
odoo.addons.base.models.qweb.QWebException: 'base.document.layout' object has no attribute 'company_registry'
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 793, in get
    return field_cache[record._ids[0]]
KeyError: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 972, in __get__
    value = env.cache.get(record, self)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 796, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'base.document.layout(,).preview'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/qweb.py", line 331, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "", line 1, in template_web_external_layout_background_336
AttributeError: 'base.document.layout' object has no attribute 'company_registry'

Error to render compiling AST
AttributeError: 'base.document.layout' object has no attribute 'company_registry'
Template: web.external_layout_background
Path: /t/div[3]/div/ul/li[4]
Node: 
  • :

  • Avatar
    Discard
    Best Answer

    Hi,


    When we read Odoo source code for BaseDocumentLayout in src/odoo/addons/web/models/base_document_layout.py we notice that company_registry is not add to it.


    So a solution is to inherit from BaseDocumentLayout and add company_registry related field.


    # -*- coding: utf-8 -*-
    from odoo import models, fields, api

    classBaseDocumentLayout(models.TransientModel):
        """
        Inherit BaseDocumentLayout to add Company fields
    that Odoo don't have taken into account
        """ _inherit ='base.document.layout'
        # Those following fields are required as a company to create invoice report
    company_registry = fields.Char(related='company_id.company_registry', readonly=True)

    Avatar
    Discard