Odoo Help


how to access my field

Pavel Pavlov
on 9/21/13, 10:30 AM 2,605 views


EDIT2: still no solution. the question can be asked also this way - How do I execute this native SQL statement via openERP ORM? self.browse(cr, uid, ids, context=context) does not work in the coding below, neither does self.browse(cr, uid, ids, prod_id, context=context).

This works, but how do I run same SQL with the ORM?

def zCustCode_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
    if prod_id and ids:
        cr.execute('SELECT "zCustomerCode"  
                    FROM product_pricelist_item 
                    WHERE product_id = %s AND price_version_id = %s', (prod_id, ids))
        zCustomerCode = cr.fetchone()[0]
        return zCustomerCode
        return ''

I'd like to try to add a field to a pricelist item, then get the value and use it when creating the sale order line.

So far I've done just dummy call to a method that returns 123455, instead of checking the code from the pricelist.item. I'm not sure, if I should do the same as in the original sale.py, where I see that in product_id_change calls product.pricelist or I can continue the way I've started, by accessing directly product.pricelist.item, where I have my value.

Q: I've tried 4-5 different ways to implement zCustCode_get in order to get in the sale order line the value that I've typed in in the product.pricelist.item->zCustomerCode, but all failed. Could you please share your advice on how can I get my value? My Debug line returns for example "openerp.addons.zFiveSol.z_fivesol_pricelist: pricelist: 3; prod_id: 2; qty: 1", but how do I search for my zCustomerCode via the ORM, instead of with direct SQL(as suggested in dev guides)?

EDIT: Latest code I tried to use is below:

def zCustCode_get(self, cr, uid, ids, prod_id, qty, partner=None, context=None):
    _logger.debug("ids: {}; prod_id: {}; qty: {}". format(ids, prod_id, qty))
    result= []
    for pl in self.browse(cr, uid, ids, context=context):
        name = pl.zCustomerCode
    return result

but it throws "NotImplementedError"

File "/home/pavel/openERP/v8/source/addons/zFiveSol/z_fivesol_pricelist.py", line 19, in zCustCode_get
for pl in self.browse(cr, uid, ids, context=context):
File "/home/pavel/openERP/v8/source/server/openerp/osv/orm.py", line 496, in __iter__
raise NotImplementedError("Iteration is not allowed on %s" % self)

Thank you!

Regards, Pavel

My code, that creates img59.imageshack.us/img59/9457/gmyr.png

class product_pricelist_item(osv.osv):
    _inherit = 'product.pricelist.item'
    _name = 'product.pricelist.item'
    _columns = {
                'zCustomerCode' : fields.char('Customer Code', size=32, help='Custom code for supplier'),

def zCustCode_get(self, cr, uid, pricelist, prod_id, qty, partner=None, context=None):
    _logger.debug("pricelist: {}; prod_id: {}; qty: {}". format(pricelist, prod_id, qty))
        return 123455   


and I need to see the value here img34.imageshack.us/img34/9563/k65.png

class sale_order_line(osv.osv):    
    _inherit = 'sale.order.line'
    _columns = {
                'zCustomerCode': fields.char('Customer Code', size=32, readonly=True, states={'draft': [('readonly', False)]}),                
    #iherit sale.order.line->product_id_change 
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
        #first call super and fill the res array, then process the additioanl fields.   
        res=super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
        uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging=packaging, 
        fiscal_position=fiscal_position, flag=flag, context=context)    

        zCustomerCode = self.pool.get('product.pricelist.item').zCustCode_get(cr, uid, [pricelist],
                product, qty or 1.0, partner_id, {
                    'uom': uom or res.get('product_uom'),
                    'date': date_order,

        res['value']['zCustomerCode'] = zCustomerCode

        return res


Hi, I still haven't found solution for this. I'd appreciate any ideas . Thank you Regards, Pavel

Pavel Pavlov
on 9/23/13, 9:30 AM

Hi, still no solution. the question can be asked also How do I execute this statment via openERP ORM?

" SELECT "zCustomerCode" FROM product_pricelist_item WHERE product_id = 2 AND price_version_id = 3"

Pavel Pavlov
on 9/24/13, 12:26 PM

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 9/24/13, 2:33 AM

try this;

for pl in self.browse(cr, uid, ids[0], context=context)

Hi I get "File "zFS_pricelist.py", line 20, in zCustCode_get for pl in self.browse(cr, uid, ids[0], context=context): TypeError: 'int' object has no attribute '__getitem__'" . I believe browse takes the whole ids...

Pavel Pavlov
on 9/24/13, 4:01 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 9/21/13, 10:30 AM
Seen: 2605 times
Last updated: 3/16/15, 8:10 AM