jeudi 26 mars 2015

Need explanation of syntax and use of search/browse return variables


Vote count:

0




This is probably in part a python question, but I still think I need to pull odoo into this question.


Here's my code. I just copied it from another piece, without fully understanding what it would do (well I thought I did...)



sale_line_ids = self.pool.get('sale.order.line').search(cr, uid, [('order_id', '=', order_id)], context=context)
print sale_line_ids
print 'that was sale_line_ids'
for sale_line_id in self.pool.get('sale.order.line').browse(cr, uid, sale_line_ids, context=context):
print sale_line_id
print 'that was one sale_line_id'
print sale_line_id.product_id
print 'that was one the product id'
product_obj = self.pool.get('product.template').browse(cr, uid, sale_line_id.product_id, context=context)
print product_obj.name


And this is the result, interspersed with my questions:



[6]
that was sale_line_ids


This is expected, the returned variable is just a python list.



sale.order.line(6,)
that was one sale_line_id


Now, what's this? It looks like a function with the second parameter missing. This surely can't be the contents of the 'sale_line_id' variable? Now it gets even stranger, because in the code the variable sale_line_id.product_id is accessed, which could mean sale.order.line(6,).product_id, which again prints a similar strange string of text:



product.product(2,)
that was one the product id


Ok, I don't get it, but it's similar to the previous outcome. Now after this I get a stack trace, which ends in:



File "/opt/odoo/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/p711/odoo-addons/p711/models.py", line 67, in paypal_form_generate_values
print product_obj.name
File "/opt/odoo/openerp/fields.py", line 817, in __get__
self.determine_value(record)
File "/opt/odoo/openerp/fields.py", line 910, in determine_value
record._prefetch_field(self)
File "/opt/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3211, in _prefetch_field
result = records.read(list(fnames), load='_classic_write')
File "/opt/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3156, in read
self._read_from_database(stored, inherited)
File "/opt/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3279, in _read_from_database
cr.execute(query_str, [tuple(sub_ids)] + where_params)
File "/opt/odoo/openerp/sql_db.py", line 158, in wrapper
return f(self, *args, **kwargs)
File "/opt/odoo/openerp/sql_db.py", line 234, in execute
res = self._obj.execute(query, params)
File "/home/odoo/odoo/lib/python2.7/site-packages/psycopg2/extensions.py", line 129, in getquoted
pobjs = [adapt(o) for o in self._seq]
ProgrammingError: can't adapt type 'product.product'


Clearly the result of trying to access 'product_obj.name', but now I'm lost, can someone give me some insight into this, and maybe explain how and why to do this right?



asked 1 min ago







Need explanation of syntax and use of search/browse return variables

Aucun commentaire:

Enregistrer un commentaire