跳至内容
菜单
此问题已终结
1 回复
26526 查看

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?

形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
0
4月 19
2576
0
3月 15
3293
2
3月 15
8329
5
4月 20
9872
0
8月 25
50