fields.function with type=M2O and store=True fails to be read on read().

Bug #594504 reported by Ferdinand
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
High
Anup(SerpentCS)

Bug Description

branch-server 2066
branch-addons official 2735
branch-addons chricar_5.0_price_unit 2609
stable_5.0-extra-addons 4412
branch/openobject-client/5.0 1076

What I did
Stock/Location Structure/open one internal location (leave all fields empty)/ All stock moves / Print screen

but I think this is introduced by 5.0.11, because it worked until recently

the object and view stock moves is modified
    def _partner_id(self, cr, uid, ids, field_name, arg, context={}):
         result = {}

         for partner in self.browse(cr, uid, ids, context):
            if not partner.partner_id and (partner.sale_line_id or partner.purchase_line_id) :

                 pname=''
                 if partner.sale_line_id:
                     pname = partner.sale_line_id.order_id.partner_id.id
                 if partner.purchase_line_id:
                     pname = partner.purchase_line_id.order_id.partner_id.id
                 if pname:
                     result[partner.id] = int(pname)

         return result
.....
        'partner_id' : fields.function(_partner_id, method=True, string="Partner ID", type='many2one', relation='res.partner',store=True ),

I had to set int(pname) - to make it work in views - but may be this causes printscreen etc to crash

it looks like a data dependent error - because selecting some lines can be printed, some not

Environment Information :
System : Linux-2.6.31.12-0.2-desktop-x86_64-with-SuSE-11.2-x86_64
OS Name : posix
LSB Version: core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64:desktop-4.0-amd64:desktop-4.0-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.2-amd64:graphics-3.2-noarch:graphics-4.0-amd64:graphics-4.0-noarch
Distributor ID: SUSE LINUX
Description: openSUSE 11.2 (x86_64)
Release: 11.2
Codename: n/a
Operating System Release : 2.6.31.12-0.2-desktop
Operating System Version : #1 SMP PREEMPT 2010-03-16 21:25:39 +0100
Operating System Architecture : 64bit
Operating System Locale : en_US.UTF8
Python Version : 2.6.2
OpenERP-Client Version : 5.0.6
Last revision No. & ID :Bazaar Package not Found !Traceback (most recent call last):
  File "/home/terp/OpenERP/branch/server/5.0/bin/service/web_services.py", line 683, in go
    (result, format) = obj.create(cr, uid, ids, datas, context)
  File "/home/terp/OpenERP/branch/server/5.0/bin/report/printscreen/ps_list.py", line 81, in create
    res = self._create_table(uid, datas['ids'], result['fields'], fields_order, rows, context, model_desc)
  File "/home/terp/OpenERP/branch/server/5.0/bin/report/printscreen/ps_list.py", line 150, in _create_table
    line[f]= line[f][1]
TypeError: 'int' object is unsubscriptable

thanks for looking into this

Related branches

Revision history for this message
Ferdinand (office-chricar) wrote :

just want to correct myself
after comparing a printable with not printable line I believe it's not data dependant.

the lines with fixed text from the following statement are printable the others not.

    def _partner_name(self, cr, uid, ids, field_name, arg, context={}):
         result = {}
         for partner in self.browse(cr, uid, ids, context):
             #pname=''
             pname = None
             if partner.partner_id and not (partner.sale_line_id or partner.purchase_line_id) :
                   pname = partner.partner_id.name
             if partner.sale_line_id:
                 pname = partner.sale_line_id.order_id.partner_id.name
             if partner.purchase_line_id:
                 pname = partner.purchase_line_id.order_id.partner_id.name
             if not pname and partner.location_id.usage == 'internal':
                 if partner.location_dest_id.usage == 'production':
                     pname = ' Used for Production'
                 if partner.location_dest_id.usage == 'inventory':
                     pname = ' Inventory'
                 if partner.location_dest_id.usage == 'internal':
                     pname = ' Internal'
             if not pname and (partner.location_id.usage == 'production' and partner.location_dest_id.usage == 'internal' ):
                 pname = ' Production'

             result[partner.id] = pname
         return result

....
        'partner_name' : fields.function(_partner_name, method=True, string="Partner",type='char', size=132,store=True ),

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hi Dr. Ferdinand,

This looks like a problem of fields.function with store attribute and relation M2O.
I investigated further and came to know that, the field is not treated as a foreign key reference , but just an integer.

I will post more as I come across a valid solution.

Thanks.

Changed in openobject-server:
status: New → Confirmed
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Dr. Ferdinand,

    I have found a solution for this. I have attached a patch would you please check it and notify us.

Thanks.

Changed in openobject-server:
assignee: nobody → Anup (Open ERP) (ach-openerp)
status: Confirmed → In Progress
Revision history for this message
Ferdinand (office-chricar) wrote :

No - with the patch "stock moves" raise an error

Environment Information :
System : Linux-2.6.31.12-0.2-desktop-x86_64-with-SuSE-11.2-x86_64
OS Name : posix
LSB Version: core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64:desktop-4.0-amd64:desktop-4.0-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.2-amd64:graphics-3.2-noarch:graphics-4.0-amd64:graphics-4.0-noarch
Distributor ID: SUSE LINUX
Description: openSUSE 11.2 (x86_64)
Release: 11.2
Codename: n/a
Operating System Release : 2.6.31.12-0.2-desktop
Operating System Version : #1 SMP PREEMPT 2010-03-16 21:25:39 +0100
Operating System Architecture : 64bit
Operating System Locale : en_US.UTF8
Python Version : 2.6.2
OpenERP-Client Version : 5.0.6
Last revision No. & ID :Bazaar Package not Found !Traceback (most recent call last):
  File "/home/terp/OpenERP/branch/server/5.0/bin/netsvc.py", line 247, in dispatch
    result = LocalService(service_name)(method, *params)
  File "/home/terp/OpenERP/branch/server/5.0/bin/netsvc.py", line 76, in __call__
    return getattr(self, method)(*params)
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/base_module_record/base_module_record.py", line 38, in execute
    res = super(recording_objects_proxy, self).execute(*args, **argv)
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/audittrail/audittrail.py", line 364, in execute
    return fct_src(db, uid, passwd, model, method, *args)
  File "/home/terp/OpenERP/branch/server/5.0/bin/service/web_services.py", line 577, in execute
    res = service.execute(db, uid, object, method, *args)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/osv.py", line 58, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/osv.py", line 119, in execute
    res = pool.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/osv.py", line 111, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 2228, in read
    result = self._read_flat(cr, user, select, fields, context, load)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 2362, in _read_flat
    res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/fields.py", line 310, in get
    record_name = dict(obj.name_get(cr, user, [record], context))
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/product/product.py", line 609, in name_get
    result = map(_name_get, self.read(cr, user, ids, ['variants','name','default_code','price_unit_id'], context))
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 2240, in read
    if type == 'many2one' and self._columns[key].__class__._type =='function' and v:
KeyError: 'price_unit_id'

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hi,

Here is the modified patch.

Thanks.

Revision history for this message
Ferdinand (office-chricar) wrote :

thanks - the patch works for me

summary: - 5.0.11 - Print Screen - Export - Exception: 'int' object is
- unsubscriptable
+ fields.function with type=M2O and store=True fails to be read on read().
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Thanks for the feedback.
We are trying to improve it more.

Changed in openobject-server:
importance: Undecided → High
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Dr Ferdinand,

   I have a better solution for this problem. I have attached it here. Would you please check it and notify us?

Thanks.

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello

      I have created a module which can be used for testing the above issue. Would you please check it and let us notify.
    For Testing :

      1. Create a sale order which will create stock moves.
      2. Go to Stock Moves and select Any Record which is having a partner.
      3. Click on Reports and select "Print Screen". You'll get Error
      4. Apply Patch
      5. Repeat step 1 to 3. "Error Disappears".

Thanks.

Revision history for this message
Ferdinand (office-chricar) wrote :

As I said in https://bugs.launchpad.net/openobject-server/+bug/594504/comments/6

the last supplied patch works for me

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Ferdinand,

It has been fixed by revision 2095 <email address hidden>

Thanks.

Changed in openobject-server:
milestone: none → 5.0.13
status: In Progress → Fix Released
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.