Problem with related fields

Bug #816889 reported by Manfred Rockel
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Invalid
Low
OpenERP's Framework R&D

Bug Description

client 6.1 rev. 1928
server 6.1 rev. 3520

Extension of the class product_supplierinfo by 2 Columns:

"prod code" ----- will show the items which the supplier delivers
"price" ----- to show the price of the first article in the supplierpartner form

With the new column "price" in object product_supplierinfo I can not save a price. The value remains at 0

class product_supplierinfo(osv.osv):
    _name = "product.supplierinfo"
    _inherit = "product.supplierinfo"

    _columns = {
        'prod_code' : fields.related('product_id', type="many2one", relation="product.template", string='Bezeichnung'),
        'price' : fields.related('pricelist_ids', 'price', type='float', string='Price'),
    }

product_supplierinfo()

Extension of product-formview

        <record id="product_supplierinfo_tree_view_1" model="ir.ui.view">
            <field name="name">rockel_product.supplierinfo.tree.view1</field>
            <field name="model">product.supplierinfo</field>
            <field name="type">tree</field>
            <field name="priority" eval="1"/>
            <field name="arch" type="xml">
                <tree string="Supplier Partner Information">
                    <field name="name"/>
                    <field name="sequence"/>
                    <field name="delay"/>
                    <field name="min_qty"/>
                    <field name="product_code"/>
                    <field name="product_name"/>
-------> <field name="price"/>
               </tree>
            </field>
        </record>

With above formextension i get this error:

Environment Information :
System : Linux-2.6.35.13-92.fc14.i686-i686-with-fedora-14-Laughlin
OS Name : posix
Operating System Release : 2.6.35.13-92.fc14.i686
Operating System Version : #1 SMP Sat May 21 17:39:42 UTC 2011
Operating System Architecture : 32bit
Operating System Locale : de_DE.UTF8
Python Version : 2.7.0
OpenERP-Client Version : 6.1-dev
Last revision No. & ID :1928 <email address hidden>
Traceback (most recent call last):
  File "/home/openerp/trunk/server/openerp/netsvc.py", line 440, in dispatch
    result = ExportService.getService(service_name).dispatch(method, auth, params)
  File "/home/openerp/trunk/server/openerp/service/web_services.py", line 588, in dispatch
    res = fn(db, uid, *params)
  File "/home/openerp/trunk/server/openerp/osv/osv.py", line 118, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/openerp/trunk/server/openerp/osv/osv.py", line 172, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/openerp/trunk/server/openerp/osv/osv.py", line 163, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1994, in fields_view_get
    xarch, xfields = self.__view_look_dom_arch(cr, user, result['arch'], view_id, context=ctx)
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1656, in __view_look_dom_arch
    fields_def = self.__view_look_dom(cr, user, node, view_id, False, fields, context=context)
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1605, in __view_look_dom
    fields.update(self.__view_look_dom(cr, user, f, view_id, in_tree_view, model_fields, context))
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1558, in __view_look_dom
    field = model_fields[node.get('name')]
KeyError: 'price'

Extension of partner form:

       <record id="supplier_productinfo_tree_view" model="ir.ui.view">
            <field name="name">rockel.supplier.productinfo.tree.view</field>
            <field name="model">product.supplierinfo</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Supplier Product Information">
                    <field name="prod_code"/>
                    <field name="sequence"/>
                    <field name="delay"/>
                    <field name="min_qty"/>
                    <field name="product_code"/>
                    <field name="product_name"/>
                </tree>
            </field>
        </record>

        <record id="supplier_productinfo_form_view" model="ir.ui.view">
            <field name="name">rockel.supplier.productinfo.form.view</field>
            <field name="model">product.supplierinfo</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Supplier Product Information">
--------> <field name="prod_code"/>
                    <field name="sequence"/>
                    <field name="product_code"/>
                    <field name="product_name"/>
                    <field name="delay"/>
                    <field name="min_qty"/>
                    <field colspan="4" groups="base.group_extended" name="pricelist_ids" nolabel="1" widget="one2many_list">
                        <tree editable="bottom" string="Pricelist">
                            <field name="min_quantity"/>
                            <field name="price"/>
                        </tree>
                        <form>
                            <field name="min_quantity"/>
                            <field name="price"/>
                        </form>
                    </field>
                </form>
            </field>
        </record>

When i press the search button in field prod_code in supplier_productinfo_form_view i get this error:

Environment Information :
System : Linux-2.6.35.13-92.fc14.i686-i686-with-fedora-14-Laughlin
OS Name : posix
Operating System Release : 2.6.35.13-92.fc14.i686
Operating System Version : #1 SMP Sat May 21 17:39:42 UTC 2011
Operating System Architecture : 32bit
Operating System Locale : de_DE.UTF8
Python Version : 2.7.0
OpenERP-Client Version : 6.1-dev
Last revision No. & ID :1928 <email address hidden>
Traceback (most recent call last):
  File "/home/openerp/trunk/server/openerp/netsvc.py", line 440, in dispatch
    result = ExportService.getService(service_name).dispatch(method, auth, params)
  File "/home/openerp/trunk/server/openerp/service/web_services.py", line 588, in dispatch
    res = fn(db, uid, *params)
  File "/home/openerp/trunk/server/openerp/osv/osv.py", line 118, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/openerp/trunk/server/openerp/osv/osv.py", line 172, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/openerp/trunk/server/openerp/osv/osv.py", line 163, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1994, in fields_view_get
    xarch, xfields = self.__view_look_dom_arch(cr, user, result['arch'], view_id, context=ctx)
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1656, in __view_look_dom_arch
    fields_def = self.__view_look_dom(cr, user, node, view_id, False, fields, context=context)
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1605, in __view_look_dom
    fields.update(self.__view_look_dom(cr, user, f, view_id, in_tree_view, model_fields, context))
  File "/home/openerp/trunk/server/openerp/osv/orm.py", line 1558, in __view_look_dom
    field = model_fields[node.get('name')]
KeyError: 'prod_code'

In Version 6.02 it works.

Related branches

Revision history for this message
Vishal Parmar(Open ERP) (vpa-openerp) wrote :

Hello Manfred Rockel,

I have checked your issued with latest updated code with stable6 and trunk both but I did't face any problem.

I have also apply your end scenario as per your specification and it is working as expected.

Would you please elaborate more on this issue and provide related screenshot or video with proper steps so we can

reproduce same at my end.

Thanks and waiting for your reply.

Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Manfred Rockel (mrockel) wrote :

Please try with this module :

product_test.zip

Revision history for this message
Manfred Rockel (mrockel) wrote :

Video with client v6.02

Revision history for this message
Manfred Rockel (mrockel) wrote :

Video with client v6.1

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Low
status: Incomplete → Confirmed
Changed in openobject-server:
status: Confirmed → Fix Committed
Revision history for this message
Manfred Rockel (mrockel) wrote :

Why will that not fixed in version 6.03(stable)

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello Manfred,

I've just tried your product_test module and tested the sames cases as your video shows and I must say that this is not actually a bug. BTW I could not reproduce any of the tracebacks you mention in the bug description, so I assume they are unrelated.

Looking at your videos, you're testing both cases against a 6.1 server, only the version of the client changes. So if there is any change, it should be on the client side only, right? But actually what you're seeing is random, and depends on the version of Python, etc. For example I can reproduce the same behavior as your video for 6.1 shows, but using the 6.0.2 client.

Let me explain: when you press "Save" in the form after changing the price field, the client send an RPC request to the server to save the changes. This is all done in a single call to the write() method (you can see it if you enable RPC debug logging), that receives the values as a map, e.g in the form:

{'packaging': [],
 'seller_ids': [[1, 10,
  {'company_id': 1,
   'delay': 1,
   'min_qty': 1.0,
   'name': 11,
   'price': False,
   'pricelist_ids': [[1,
   2,
  {'min_quantity': 1.0,
   'price': 23.0}]],
  ...
}

The write() method will then process all the values in the map to save then in the database. But the order in which the fields are saved is not absolute, because there is no order for keys in a map/dictionary. So the order in which the fields will be processed depends on many things (like the python version), and can be considered semi-random.

As you have added a read/write related 'price' field on the supplier info object, when its value of '0.0' is saved, it will overwrite the price value of the first price in the lines. You can test that easily by setting a value in the related "price" field while having multiple pricelist lines: you will see the first line gets set to the related field value.
If you want to do this, you need to make sure the related field is never written to. One way to do it is to make it read-only.
If you look at the RPC call for the write() after making the related price field read-only, you will see that it does not receive a value anymore.

To summarize, the behavior you are showing seems perfectly normal, and I should now close this bug.
Do not hesitate to provide more feedback or reopen the bug if I misunderstood the situation.

Thanks,

Changed in openobject-server:
status: Fix Committed → Invalid
Revision history for this message
Manfred Rockel (mrockel) wrote :

Thanks for your answer. I have set field 'price' to readonly and it works for me

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.