Skip to Content
Menu
This question has been flagged
1 Reply
5276 Views

Hello,

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
    else:
        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
        result.append((pl.id,name))
    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   

product_pricelist_item()

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

sale_order_line()
Avatar
Discard
Author

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

Author

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"

Best Answer

try this;

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

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