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

I'm trying to use new API in Odoo. (still not quite familiar with it)

I created a module that inherits 'sale.order' object. I added codes in 'action_button_confirm' ('Confirm Sale' button) method that returns wizard if my condition is true, which I want to transfer the codes in create method but I'm getting the error whenever it returns the wizard:

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

.py file

class sale_order(models.Model):
_inherit = "sale.order"

    @api.model
    def create(self, vals):
        res = super(sale_order, self).create(vals)
        return self.action_try(res)

    def action_try(self, res):
        for order_id in res:
            #codes

            if my_condition:
                return {
                'name': 'My wizard',
                'view_mode': 'form',
                'view_type': 'form',
                'res_model': 'my.wizard',
                'type': 'ir.actions.act_window',
                'nodestroy': True,
                'target': 'new',
                'context': {
                            #fields
                            }
                        }

Other info

Traceback (most recent call last):
  File "/home/workspace/odoo8/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/workspace/odoo8/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/home/workspace/odoo8/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/workspace/odoo8/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/workspace/odoo8/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/home/workspace/odoo8/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/home/workspace/odoo8/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/home/workspace/odoo8/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/workspace/odoo8/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/home/workspace/odoo8/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/workspace/odoo8/openerp/api.py", line 373, in old_api
    return downgrade(recs, result, *args, **kwargs)
  File "/home/workspace/odoo8/openerp/api.py", line 291, in <lambda>
    return lambda self, *args, **kwargs: downgrade(args[0])
  File "/home/workspace/odoo8/openerp/models.py", line 4049, in <lambda>
    @api.returns('self', lambda value: value.id)
AttributeError: 'dict' object has no attribute 'id'

I didn't include my codes since there's nothing wrong with it (as I check manually), the error only appears when it will return the wizard. How can I return the wizard?

Avatar
Discard
Best Answer

You cannot return a wizard dict from the create method. it's not supposed to work like that. If you wanna do it you could put a button for that, all the buttons first will save the data before calling the button action.

Avatar
Discard
Related Posts Replies Views Activity
0
Apr 19
1572
0
Mar 15
2444
2
Mar 15
7019
5
Apr 20
8615
1
Dec 24
31