how call function in domain Ono2many field odoo 8 - odoo

message Error:
TypeError: old_api() takes at least 3 arguments (1 given)
code py:
#api.model
def domain_users(self):
if self.env.user.login=="bendjeddou.o":
domain=[('exp_P','>',0)]
else:
domain=[]
return domain
o2m_materiels fields.One2many('gmat.journaleline','rapJor_ids',string='Materiel',domain=domain_users)
class py:
class Journaleline(models.Model):
_name = 'gmat.journaleline'
_description = 'Detail materiel'
rapJor_ids = fields.Many2one('gmat.rapporjournal',string='num')
exp_P = fields.Float(string='Panne(H)',default=0)

all message error:
Traceback (most recent call last):
File "/opt/odoo/openerp/http.py", line 544, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/openerp/http.py", line 581, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/openerp/http.py", line 317, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/openerp/http.py", line 314, in checked_call
return self.endpoint(*a, **kw)
File "/opt/odoo/openerp/http.py", line 810, in __call__
return self.method(*args, **kw)
File "/opt/odoo/openerp/http.py", line 410, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/openerp/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo/openerp/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/odoo/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3148, in read
result = BaseModel.read(records, fields, load=load)
File "/opt/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3183, in read
self._read_from_database(stored, inherited)
File "/opt/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3370, in _read_from_database
res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
File "/opt/odoo/openerp/osv/fields.py", line 773, in get
domain = self._domain(obj) if callable(self._domain) else self._domain
File "/opt/odoo/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
TypeError: old_api() takes at least 3 arguments (1 given)

Try this:
# remove the decorator
def domain_users(self):
domain = False
if self.env.user.login=="bendjeddou.o":
domain=[('exp_P','>',0)]
else:
domain=[]
return domain
o2m_materiels = fields.One2many('gmat.journaleline',
'rapJor_ids',
string='Materiel',
domain=lambda self: self.domain_users())
or for less typing
# no need to define method
o2m_materiels = fields.One2many('gmat.journaleline',
'rapJor_ids',
string='Materiel',
domain = lambda self: self.env.user.login == "bendjedou.o" and [('exp_P','>',0)] or [])
EDITS:
ok for some reason i think the signature of the method
must be in old api try this:
# or this
# def domain_users(self, cr, uid, ids, context=None):
def domain_users(self, cr, uid, context=None):
domain = False
user = self.pool.get('res.users').browse(cr, uid, uid, context).
if user.login == "bendjeddou.o":
domain=[('exp_P','>',0)]
else:
domain=[]
return domain
o2m_materiels = fields.One2many('gmat.journaleline',
'rapJor_ids',
string='Materiel',
domain=domain_users)
May because your model is created using osv.Model not model.Model

Related

How can override a field default value with default_get in odoo9?

I want to override the default value for a field with the default_get API function in odoo9.
I have this in my code:
#api.model
def default_get(self, fields_list):
res = super(hr_attendance, self).default_get(fields_list)
res.update({
'animal': 'dog'
})
return res
When I create a new register, this error appears in the odoo log:
2016-09-02 11:33:36,680 27542 ERROR mydb openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/etc/odoo/server/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/etc/odoo/server/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/etc/odoo/server/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/etc/odoo/server/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/etc/odoo/server/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/etc/odoo/server/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/etc/odoo/server/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/etc/odoo/server/addons/web/controllers/main.py", line 888, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/etc/odoo/server/addons/web/controllers/main.py", line 880, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/etc/odoo/server/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/etc/odoo/server/openerp/api.py", line 354, in old_api
result = method(recs, *args, **kwargs)
File "/etc/odoo/server/addons_extra/hr_attendance_extend/hr_attendance.py", line 79, in default_get
res.update({
AttributeError: 'tuple' object has no attribute 'update'
What I am doing wrong?
Edit: I had another variable with the same name which provoqued conflict.
Renaming the variable, everything works perfect.
update is a method of dictionary data-type. And you are trying to use it with tuple data-type. That's reason you got error.
Try with following code:
#api.model
def default_get(self, fields):
res = super(hr_attendance, self).default_get(fields)
res['animal'] = 'dog'
return res

Bug in Odoo gamification addon

When I create a goal definition with:
computation mode : (Automatic: sum on a field,
Model : Sale Order Line,
Field to Sum : SubTotal)
When I add this goal definition to a challenge and try to start it, I get this traceback:
Client Traceback (most recent call last):
File "/home/openerp/server/openerp/addons/web/http.py", line 204, in dispatch
response["result"] = method(self, **self.params)
File "/home/openerp/server/openerp/addons/web/controllers/main.py", line 1132, in call_button
action = self._call_kw(req, model, method, args, {})
File "/home/openerp/server/openerp/addons/web/controllers/main.py", line 1120, in _call_kw
return getattr(req.session.model(model), method)(*args, **kwargs)
File "/home/openerp/server/openerp/addons/web/session.py", line 42, in proxy
result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw)
File "/home/openerp/server/openerp/addons/web/session.py", line 30, in proxy_method
result = self.session.send(self.service_name, method, *args)
File "/home/openerp/server/openerp/addons/web/session.py", line 103, in send
raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)
Server Traceback (most recent call last):
File "/home/openerp/server/openerp/addons/web/session.py", line 89, in send
return openerp.netsvc.dispatch_rpc(service_name, method, args)
File "/home/openerp/server/openerp/netsvc.py", line 296, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/home/openerp/server/openerp/service/web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
File "/home/openerp/server/openerp/osv/osv.py", line 190, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "/home/openerp/server/openerp/osv/osv.py", line 132, in wrapper
return f(self, dbname, *args, **kwargs)
File "/home/openerp/server/openerp/osv/osv.py", line 199, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/openerp/server/openerp/osv/osv.py", line 187, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/home/openerp/server/openerp/addons/gamification/plan.py", line 342, in action_start
return self.generate_goals_from_plan(cr, uid, ids, context=context)
File "/home/openerp/server/openerp/addons/gamification/plan.py", line 439, in generate_goals_from_plan
goal_obj.update(cr, uid, [new_goal_id], context=context)
File "/home/openerp/server/openerp/addons/gamification/goal.py", line 278, in update
new_value = res and res[0][field_name] or 0.0
KeyError: u'price_subtotal'
this is a video that shows the scenario that I did: http://youtu.be/b546xTc1ArY

assign task to multiple users in odoo

in odoo (fromerly openERP) i want to customize Project management module.
currently a task can be assigned to a single user. model code is:
class task(osv.osv):
_name = "project.task"
_description = "Task"
'user_id': fields.many2one('res.users', 'Assigned to', select=True, track_visibility='onchange'),
Now want to assign a task to multiple users. and i have modified user_id field like this:
'user_id': fields.many2many('res.users', 'Assigned to', select=True, track_visibility='onchange'),
but it shows following traceback:
Traceback (most recent call last):
File "/home/hardik/odoo/odoo/openerp/http.py", line 537, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/hardik/odoo/odoo/openerp/http.py", line 574, in dispatch
result = self._call_function(**self.params)
File "/home/hardik/odoo/odoo/openerp/http.py", line 310, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/hardik/odoo/odoo/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/home/hardik/odoo/odoo/openerp/http.py", line 307, in checked_call
return self.endpoint(*a, **kw)
File "/home/hardik/odoo/odoo/openerp/http.py", line 803, in __call__
return self.method(*args, **kw)
File "/home/hardik/odoo/odoo/openerp/http.py", line 403, in response_wrap
response = f(*args, **kw)
File "/home/hardik/odoo/odoo/addons/web/controllers/main.py", line 884, in search_read
return self.do_search_read(model, fields, offset, limit, domain, sort)
File "/home/hardik/odoo/odoo/addons/web/controllers/main.py", line 905, in do_search_read
request.context)
File "/home/hardik/odoo/odoo/openerp/http.py", line 908, in proxy
result = meth(cr, request.uid, *args, **kw)
File "/home/hardik/odoo/odoo/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/hardik/odoo/odoo/openerp/models.py", line 5146, in search_read
result = self.read(cr, uid, record_ids, fields, context=read_ctx)
File "/home/hardik/odoo/odoo/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/hardik/odoo/odoo/openerp/models.py", line 3141, in read
result = BaseModel.read(records, fields, load=load)
File "/home/hardik/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/home/hardik/odoo/odoo/openerp/models.py", line 3176, in read
self._read_from_database(stored, inherited)
File "/home/hardik/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/home/hardik/odoo/odoo/openerp/models.py", line 3354, in _read_from_database
res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
File "/home/hardik/odoo/odoo/openerp/osv/fields.py", line 1012, in get
cr.execute(query, [tuple(ids),] + where_params)
File "/home/hardik/odoo/odoo/openerp/sql_db.py", line 158, in wrapper
return f(self, *args, **kwargs)
File "/home/hardik/odoo/odoo/openerp/sql_db.py", line 234, in execute
res = self._obj.execute(query, params)
ProgrammingError: syntax error at or near "to"
LINE 1: SELECT Assigned to.res_users_id, Assigned to.project_task_id...
^
please guide me how to deal with this. thanks in advance
When we create many2many type field, than we must to give a name of relation table where in that table record will store. In below example 'task_user_rel' is a relational table.
You may try this code:
'user_ids': fields.many2many('res.users', 'task_user_rel', 'user_id', 'id', 'Assigned to', select=True, track_visibility='onchange'),
Now add new user_ids field in xml side and hide/invisible a exists user_id field.

Odoo 8 error when trying to open customer

I am using Odoo 8 on Ubuntu.
I have problem opening some customers (some are OK). When I try to open it for editing I get Odoo Server Error...IndexError: list index out of range.
Any idea what could cause this problem ? I tried to search for similar problems but I have not found any solution. So when I want to edit the client I have to create new one, I also tried to merge them after creating new one but the error reappears again.
thank you and here is complete traceback:
Odoo Server Error
Traceback (most recent call last):
File "/opt/odoo/odoo/openerp/http.py", line 530, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/odoo/openerp/http.py", line 567, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/odoo/openerp/http.py", line 303, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/odoo/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/odoo/openerp/http.py", line 300, in checked_call
return self.endpoint(*a, **kw)
File "/opt/odoo/odoo/openerp/http.py", line 796, in __call__
return self.method(*args, **kw)
File "/opt/odoo/odoo/openerp/http.py", line 396, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 949, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 932, in _call_kw
records = getattr(request.session.model(model), method)(*args, **kwargs)
File "/opt/odoo/odoo/openerp/http.py", line 900, in proxy
result = meth(cr, request.uid, *args, **kw)
File "/opt/odoo/odoo/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3109, in read
result = BaseModel.read(records, fields, load=load)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3141, in read
self._read_from_database(stored)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3305, in _read_from_database
res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
File "/opt/odoo/odoo/openerp/osv/fields.py", line 1361, in get
result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
File "/opt/odoo/odoo/addons/account/partner.py", line 246, in _invoice_total
result[partner.id] = sum(inv.user_currency_price_total for inv in invoices)
File "/opt/odoo/odoo/addons/account/partner.py", line 246, in <genexpr>
result[partner.id] = sum(inv.user_currency_price_total for inv in invoices)
File "/opt/odoo/odoo/openerp/fields.py", line 760, in __get__
self.determine_value(record)
File "/opt/odoo/odoo/openerp/fields.py", line 853, in determine_value
record._prefetch_field(self)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3196, in _prefetch_field
result = records.read(list(fnames), load='_classic_write')
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3141, in read
self._read_from_database(stored)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3292, in _read_from_database
res2 = self._columns[fs[0]].get(cr, self._model, ids, fs, user, context=context, values=result)
File "/opt/odoo/odoo/openerp/osv/fields.py", line 1361, in get
result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
File "/opt/odoo/odoo/addons/account/report/account_invoice_report.py", line 40, in _compute_amounts_in_user_currency
currency_rate_id = currency_rate_obj.search(cr, uid, [('rate', '=', 1)], limit=1, context=context)[0]
IndexError: list index out of range
in the searching of currency_rate_id, the search function is getting an empty list and you are trying to select the first element from the empty list which causes the error
The solution is to add an exchange rate for the currency.
1 - Settings->Companies
2 - Edit your commpany
3 - Modify the Currency update configuration
4 - Add values for "Currencies to update" tab
Image 1
Image 2
Image 3

Odoo 8 error when trying to open product with multiple attributes

Our Odoo is version 8 and is running on Ubuntu.
When I try to open product which has multiple attributes (colours, sizes) I get KeyError: 57. Other simple products are OK.
Any idea what can cause this problem ?
here is complete traceback:
Odoo Server Error
Traceback (most recent call last):
File "/opt/odoo/odoo/openerp/http.py", line 530, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/odoo/openerp/http.py", line 567, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/odoo/openerp/http.py", line 303, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/odoo/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/odoo/openerp/http.py", line 300, in checked_call
return self.endpoint(*a, **kw)
File "/opt/odoo/odoo/openerp/http.py", line 796, in __call__
return self.method(*args, **kw)
File "/opt/odoo/odoo/openerp/http.py", line 396, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 949, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo/odoo/addons/web/controllers/main.py", line 932, in _call_kw
records = getattr(request.session.model(model), method)(*args, **kwargs)
File "/opt/odoo/odoo/openerp/http.py", line 900, in proxy
result = meth(cr, request.uid, *args, **kw)
File "/opt/odoo/odoo/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3109, in read
result = BaseModel.read(records, fields, load=load)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3141, in read
self._read_from_database(stored)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3305, in _read_from_database
res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
File "/opt/odoo/odoo/openerp/osv/fields.py", line 1361, in get
result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
File "/opt/odoo/odoo/addons/sale/sale.py", line 1283, in _sales_count
res[template.id] = sum([p.sales_count for p in template.product_variant_ids])
File "/opt/odoo/odoo/openerp/fields.py", line 760, in __get__
self.determine_value(record)
File "/opt/odoo/odoo/openerp/fields.py", line 853, in determine_value
record._prefetch_field(self)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3196, in _prefetch_field
result = records.read(list(fnames), load='_classic_write')
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3141, in read
self._read_from_database(stored)
File "/opt/odoo/odoo/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/odoo/openerp/models.py", line 3308, in _read_from_database
vals[f] = res2[vals['id']]
KeyError: 57
I got same error like your log, but I don't know your code details. You should check field type.
In my case, I used field function.
I was make mistaken like below:
rec = obj.browse(cr,...)
result = {}
# result[id] = val # wrong
result[rec.id] = val # correct
I hope this helps..