Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
4384 Vistas

Hi all,

I got an errors when I change from price fields.float to  'price': fields.related('price_id', type='many2one', relation='abs.prod.price', string='Price',), with many2one  field 'price_id': fields.many2one('abs.price', 'Price',),

Please see below error.

class abs_products(osv.Model):
    _name = "abs.products"

    _columns = {
        'prodcode_id': fields.many2one("abs.prod.desc", 'Product Code'),
........
        'price_id': fields.many2one('abs.price', 'Price'),
        'price': fields.related('price_id','name', type='float', string='Price', store=True),
    }

def onchange_prodcode(self, cr, uid, ids, prodcode_id, context=None):

        if prodcode_id:
            description_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).description_id.id
            variants_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).variants_id.id
            sku_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).sku_id.id
            price_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).price_id.id
            return {'value':{'description_id':description_id,'variants_id':variants_id,'sku_id':sku_id,'price_id':price_id}}
        return {}

class descriptionproduct(osv.osv):

    _columns = {

........
        'price_id': fields.many2one('abs.price', 'Price', required=True),
    }

class productprice(osv.osv):
    _description="Product Price"
    _name = 'abs.prod.price'
    _columns = {
        'price_id': fields.many2one('abs.price', 'Price', required=True),
        'name': fields.float('Price', digits=(12,2)),
    }

class price(osv.osv):
    _name = 'abs.price'
    _description = 'Price'
    _columns = {
        'name': fields.float('Price', digits=(12,2)),
    }

Errors

Server Traceback (most recent call last):
  File "/home/philip/wsorig/openerp/web/addons/web/session.py", line 89, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/home/philip/wsorig/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/philip/wsorig/openerp/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/philip/wsorig/openerp/server/openerp/osv/orm.py", line 2410, in name_search
    return self._name_search(cr, user, name, args, operator, context, limit)
  File "/home/philip/wsorig/openerp/server/openerp/osv/orm.py", line 2441, in _name_search
    ids = self._search(cr, user, args, limit=limit, context=context, access_rights_uid=access_rights_uid)
  File "/home/philip/wsorig/openerp/server/openerp/osv/orm.py", line 4939, in _search
    cr.execute('SELECT "%s".id FROM ' % self._table + from_clause + where_str + order_by + limit_str + offset_str, where_clause_params)
  File "/home/philip/wsorig/openerp/server/openerp/sql_db.py", line 161, in wrapper
    return f(self, *args, **kwargs)
  File "/home/philip/wsorig/openerp/server/openerp/sql_db.py", line 226, in execute
    res = self._obj.execute(query, params)
ProgrammingError: operator does not exist: numeric ~~* unknown
LINE 1: ...bs_price"."id" IS NULL)  AND  ("abs_price"."name" ilike '%34...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

Avatar
Descartar
Mejor respuesta

Hi,

Please made change as like below :

Below is your code for two columns.

 'price_id': fields.many2one('abs.price', 'Price',), 
 'price': fields.related('price_id', type='many2one', relation='abs.prod.price', string='Price',),

But you have to wirte your column defination as like below.

 'price_id': fields.many2one('abs.price', 'Price',), 
 'price': fields.related('price_id','name', type='float', string='Price',store=True),

First of all you have to give the name of the field which is used into fields.related and that is part of the related model. In your code the related model is : "abs.price" becasuse you want to take related fields from "price_id" and "price_id" is with relation of : "abs.price". So, you have to take any field from the "abs.price" model.

In you case you have not define any field which is used for fields.related. You have to give the field name next to the "price_id" into fields.related defination. 

In my code you can see that I have given the "name" field for the fields.related means "name" field will automatically filled according to the "price_id". Here you can also set the "store" parameter to define that you want to store that field into database or not.

I hope you can fix you issue.

Avatar
Descartar
Autor

Thank you so much, you right is working now.

Autor Mejor respuesta

Hi, I got an error message below when directly entered to price_id field, unlike other
fields when you directly entered value it will automatically show to lines with "create "value"" and "create and edit.." but in price_id field showing error but if I click OK button I can continue save. ON_CHANGE ----def onchange_prodcode(self, cr, uid, ids, prodcode_id, context=None):
--------if prodcode_id:
------------description_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).description_id.id
------------variants_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).variants_id.id
------------sku_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).sku_id.id
------------price_id = self.pool.get('abs.prod.desc').browse(cr, uid, prodcode_id, context).price_id.id
--------return {'value':{'description_id':description_id,'variants_id':variants_id,'sku_id':sku_id,'price_id':price_id}}
--------return {}
ERROR Server Traceback (most recent call last):
File "/home/philip/wsorig/openerp/web/addons/web/session.py", line 89, in send
return openerp.netsvc.dispatch_rpc(service_name, method, args)
File "/home/philip/wsorig/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/home/philip/wsorig/openerp/server/openerp/service/web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 132, in wrapper
return f(self, dbname, *args, **kwargs)
File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 199, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/philip/wsorig/openerp/server/openerp/osv/osv.py", line 187, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/home/philip/wsorig/openerp/server/openerp/osv/orm.py", line 2410, in name_search
return self._name_search(cr, user, name, args, operator, context, limit)
File "/home/philip/wsorig/openerp/server/openerp/osv/orm.py", line 2441, in _name_search
ids = self._search(cr, user, args, limit=limit, context=context, access_rights_uid=access_rights_uid)
File "/home/philip/wsorig/openerp/server/openerp/osv/orm.py", line 4939, in _search
cr.execute('SELECT "%s".id FROM ' % self._table + from_clause + where_str + order_by + limit_str + offset_str, where_clause_params)
File "/home/philip/wsorig/openerp/server/openerp/sql_db.py", line 161, in wrapper
return f(self, *args, **kwargs)
File "/home/philip/wsorig/openerp/server/openerp/sql_db.py", line 226, in execute
res = self._obj.execute(query, params)
ProgrammingError: operator does not exist: numeric ~~* unknown
LINE 1: ...bs_price"."id" IS NULL) AND ("abs_price"."name" ilike '%9%...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

Avatar
Descartar
Autor

any update here

can you update your code into your question ? it is good to resolve your issue.

Autor

The above code update already, Thanks

Autor

update please

Autor

any update here

Autor

any update here

Autor

UPDATE PLEASE, any can fix the above error