Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
14644 Tampilan

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?

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Penulis Jawaban Terbai

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.

Avatar
Buang

Your "depends" in __openerp__.py?

Penulis

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

Post Terkait Replies Tampilan Aktivitas
1
Okt 16
3830
0
Mar 16
3264
0
Des 15
4272
1
Sep 15
10413
3
Mei 23
2087