This question has been flagged
5 Replies
8687 Views

My .py file is

class orion_specific_product(models.Model):
    _name = 'orion.specific.product'
    
    name = fields.Char(required=True)
    mfd_pro = fields.Boolean(default=False)
    active = fields.Boolean(default=True)
    sale_ok = fields.Boolean(default=True)
    product_id = fields.Many2one('orion.product.product')
    attribute_id = fields.Many2one('temp.orion.product.attribute')
    attribute_value_id = fields.Many2one('temp.orion.product.attribute.value')
    
    @api.onchange('mfd_pro')
    def _change_mfd_pro(self):
        if self.name:
            if self.mfd_pro == False:
                if len(self.name)>2:
                    self.name = self.name[1:]
            elif self.mfd_pro == True:
                if len(self.name)>2:
                    self.name='N'+self.name
                    self.mfd_pro = True
    
    @api.onchange('product_id')
    def _change_product(self):
        if (self.product_id):
            # storing short name in name field
            pro_name = self.product_id.name
            try:
                index_value = pro_name.index(' -')
                self.name = pro_name[:index_value]
            except ValueError:
                self.name = pro_name
        #clearing temp table
        self.env.cr.execute("delete from temp_orion_product_attribute")
        #populating data to temp tables
        #1. Attributes
        self.env.cr.execute("""select a.id,a.name from orion_product_attribute a, orion_product_line l where l.att_ids = a.id and l.pro_ids = %s""" %(self.product_id.id))
        rows = self.env.cr.fetchall()
        if rows.count>0:
            for row in rows:
                self.env.cr.execute("""insert into temp_orion_product_attribute(name,a_id) values('%s','%s')""" %(row[1],row[0]))
    
    @api.onchange('attribute_id')
    def _change_attribute(self):
        if (self.attribute_id):
            #populating data to temp tables
            self.env.cr.execute("""select id from orion_product_line where pro_ids = %s and att_ids = %s""" %(self.product_id.id, self.attribute_id.id))
            row = self.env.cr.fetchone()
            if row:
                self.env.cr.execute("""select v.id,v.name from orion_product_attribute_value v, orion_product_orion_pro_value_rel r where r.line_ids = %s and r.value_ids = v.id""" %(row[0]))
                rows = self.env.cr.fetchall()
                for i in rows:
                    self.env.cr.execute("""insert into temp_orion_product_attribute_value(name,v_id) values('%s','%s')""" %(i[1],i[0]))
                    self.env.cr.execute("""delete from temp_orion_product_attribute where a_id='%s'""" %(self.attribute_id.a_id))


And I got this error:


Traceback (most recent call last):
  File "/opt/odoopro/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoopro/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoopro/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoopro/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoopro/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoopro/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/opt/odoopro/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoopro/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoopro/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoopro/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoopro/openerp/api.py", line 372, in old_api
    result = method(recs, *args, **kwargs)
  File "/opt/odoopro/openerp/models.py", line 1728, in name_search
    return self._name_search(name, args, operator, limit=limit)
  File "/opt/odoopro/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoopro/openerp/api.py", line 508, in new_api
    result = method(self._model, cr, uid, *args, **old_kwargs)
  File "/opt/odoopro/openerp/models.py", line 1740, in _name_search
    ids = self._search(cr, user, args, limit=limit, context=context, access_rights_uid=access_rights_uid)
  File "/opt/odoopro/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoopro/openerp/models.py", line 4674, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/opt/odoopro/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoopro/openerp/models.py", line 4485, in _where_calc
    e = expression.expression(cr, user, domain, self, context)
  File "/opt/odoopro/openerp/osv/expression.py", line 659, in __init__
    self.expression = distribute_not(normalize_domain(exp))
  File "/opt/odoopro/openerp/osv/expression.py", line 308, in distribute_not
    elif token in DOMAIN_OPERATORS_NEGATION:
TypeError: unhashable type: 'list'


Avatar
Discard

I formatted your code. Make sure the indents I put are correct. In the future, to paste code, just type enter a few times, open your HTML inspector, pick an empty

element, modify it, paste your code and wrap it with

, then hit save.

wrap it with pre tags (damn !)

Author

I am new to odoo can you help me please!

Best Answer

Hi,

Something wrong the logic & indentation of this part:

    @api.onchange('mfd_pro')
    def _change_mfd_pro(self):
        if self.name:
            if self.mfd_pro == False:
                if len(self.name)>2:
                    self.name = self.name[1:]
                elif self.mfd_pro == True:
                    if len(self.name)>2:
                        self.name='N'+self.name
                        self.mfd_pro = True

I don't know exactly what you are trying to do. Please check n correct it.

Avatar
Discard
Author Best Answer

@Akhil P Sivan

All my indentation are correct

And as per logic i will expain to you:

@api.onchange('mfd_pro')
    def _change_mfd_pro(self):
        if self.name: #checks if name field has value or not
            if self.mfd_pro == False: # checks if the boolean field is false or not
                if len(self.name)>2: # checks the length of characters in the name field 
                    self.name = self.name[1:] # removes the first character
            elif self.mfd_pro == True: # if boolean field is true
                if len(self.name)>2: checks the length and then add 'N' to the start of the value in the name field
                    self.name='N'+self.name
                    self.mfd_pro = True
Avatar
Discard

When does the error occurs exactly ? What action are you doing that throw the error ?

Author

when I click on 'attribute_id' field which is many2one

Author

data gets populated after selecting a value from 'product_id' into 'temp.orion.product.attribute' table

Author

Found the error it was in domain. In xml file i have given domain="[('pro_id','=','')]"