Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to display subfields in a tree view?

By
Malte Jörgens
on 3/23/15, 10:55 AM 2,079 views

We have a franchise as a customer and as they all are treated as single customers for invoicing, the customer names are pretty similar. In the account.invoice view, we therefore want to add a column containing the city of the customer. So I changed account.invoice.tree to include the partner_id.city field as shown below.

<?xml version="1.0"?>
<tree colors="blue:state == 'draft';black:state in ('proforma','proforma2','open');gray:state == 'cancel'" string="Invoice">
<field name="partner_id" groups="base.group_user"/>
    <field name="partner_id.city"/>
    <field name="commercial_partner_id" invisible="1"/>
    <field name="date_invoice"/>
    <field name="number"/>
    <field name="reference" invisible="1"/>
    <field name="name" invisible="1"/>
    <field name="journal_id" invisible="1"/>
    <field name="period_id" invisible="1" groups="account.group_account_user"/>
    <field name="company_id" groups="base.group_multi_company" widget="selection"/>
    <field name="user_id" string="Responsible"/>
    <field name="date_due"/>
    <field name="origin"/>
    <field name="currency_id" groups="base.group_multi_currency"/>
    <field name="residual" sum="Residual Amount"/>
  <field name="amount_untaxed" sum="Untaxed Amount"/>
  <field name="amount_total" sum="Total Amount"/>
    <field name="state"/>
</tree>

However, upon saving I get this error:

ValidateError
Field(s) `arch` failed against a constraint: Ungültige Ansichtendefinition [Invalid view definition]
Error details:
Das Feld `partner_id.city` existiert nicht [Field does not exist]
Fehler Kontext:
Ansicht `account.invoice.tree`
[view_id: 584, xml_id: account.invoice_tree, model: account.invoice, parent_id: k. A.]

As I have not seen the use of attributes of contained fields, I wonder if this attempt actually works. Can anyone point me in the right direction?

2

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 3/27/15, 7:44 AM

In new api with models.Model there is not anymore fields.related fields. Try this:


from openerp import models, fields, api

class invoice_city(models.Model):

     _inherit = 'account.invoice'

     city = fields.Char(string='City', related='partner_id.city')

1
Michael Pol
On 3/23/15, 11:21 AM

The one of right direction could be to use related field if you have limited fields to be shown from Customer in Invoice. Inherit account.invoice class and put a new filed. For example

'city': fields.related('partner_id', 'city', type='char', string='City' ),

Instead of using 

<field name="partner_id.city"/>

just use

<field name="city"/>

0
Malte Jörgens
On 3/27/15, 7:14 AM

As Micheal Pol suggested, I created a new module inheriting account.invoice. This works very well, until the server is restarted/the module is loaded again (e.g. updating). The server will then return an Internal Server Error (500) with this stacktrace:

[...]

File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 498, in _button_immediate_function registry = openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True) File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 366, in new openerp.modules.load_modules(registry._db, force_demo, status, update_module) File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 351, in load_modul es force, status, report, loaded_modules, update_module) File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 255, in load_marke d_modules loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_module s=loaded_modules, perform_checks=perform_checks) File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 152, in load_modul e_graph models = registry.load(cr, package) File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 162, in load model = cls._build_model(self, cr) File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 592, in _build_model original_module = pool[name]._original_module if name in parents else cls._module File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 101, in __getitem __ return self.models[model_name] KeyError: 'account.invoice'


The module I created looks like this:

 from openerp import models, fields, api 

class invoice_city(models.Model): 
    _inherit = 'account.invoice' 
    city = fields.related('partner_id', 'city', type='char', string='City')

EDIT:
I changed the last line to the new API as zkib suggested, but I still get the above error message upon updating/restarting the module. This is important as the server is restarted every night for maintanence reasons (Backup). I tried this on a fresh Odoo Installation with the same behaviour.

Your "depends" in __openerp__.py?

zbik
on 3/30/15, 7:47 AM

Oh. Hah. Yeah, that was it. I added 'account' to it and now it works properly. Thank you!

Malte Jörgens
on 3/30/15, 9:54 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 3/23/15, 10:55 AM
Seen: 2079 times
Last updated: 9/16/15, 6:05 PM