Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
3848 Ansichten

Getting this error while trying to add a display notification in the create method.
How do I go about this?

Error:

Odoo Server Error


Traceback (most recent call last):

  File "/home/g/odoo/odoo14/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch

    result = request.dispatch()

  File "/home/g/odoo/odoo14/odoo/odoo/http.py", line 696, in dispatch

    result = self._call_function(**self.params)

  File "/home/g/odoo/odoo14/odoo/odoo/http.py", line 370, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/home/g/odoo/odoo14/odoo/odoo/service/model.py", line 94, in wrapper

    return f(dbname, *args, **kwargs)

  File "/home/g/odoo/odoo14/odoo/odoo/http.py", line 358, in checked_call

    result = self.endpoint(*a, **kw)

  File "/home/g/odoo/odoo14/odoo/odoo/http.py", line 919, in __call__

    return self.method(*args, **kw)

  File "/home/g/odoo/odoo14/odoo/odoo/http.py", line 544, in response_wrap

    response = f(*args, **kw)

  File "/home/g/odoo/odoo14/odoo/addons/web/controllers/main.py", line 1370, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "/home/g/odoo/odoo14/odoo/addons/web/controllers/main.py", line 1362, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/home/g/odoo/odoo14/odoo/odoo/api.py", line 402, in call_kw

    result = _call_kw_model_create(method, model, args, kwargs)

  File "/home/g/odoo/odoo14/odoo/odoo/api.py", line 383, in _call_kw_model_create

    return result.id if isinstance(args[0], Mapping) else result.ids

Exception


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File "/home/g/odoo/odoo14/odoo/odoo/http.py", line 652, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/home/g/odoo/odoo14/odoo/odoo/http.py", line 317, in _handle_exception

    raise exception.with_traceback(None) from new_cause

AttributeError: 'dict' object has no attribute 'id'


Here is my code.

def create(self, vals):
credit = 0
debit = 0
if "line_ids" in vals.keys():
for line in vals['line_ids']:
if line[2]['credit']:
account = self.env['account.account'].browse(line[2]['account_id'])
account_lines = self.env['account.move.line'].search([('account_id', '=', account.id)])
for lines in account_lines:
credit += lines.credit
debit += lines.debit
if account.account_credit_limit:
if (credit + line[2]['credit'] - debit) > account.account_credit_limit:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': _('Warning'),
'type': 'warning',
'message': _(
'Limit will Exceed! Making this transaction will exceed the limit defined for "%s" account') % account.name,
'sticky': True,
}
}
result = super(AccountMove, self).create(vals)
return self.browse(result['id']) if isinstance(result, dict) else result


Avatar
Verwerfen

Account Move returns an object not a dictionary. Please check the last return statement once.

Beste Antwort

Hi,
The error may be thrown from the last line of the code, instead of returning as you did, you can just change it to:

return super().create(vals)


Replace:   return self.browse(result['id']) if isinstance(result, dict) else result

With :  return result



Thanks

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Feb. 24
1513
0
Feb. 24
1797
0
Juli 23
1779
1
Juni 23
2916
1
Apr. 23
128