如何覆盖Odoo v.9中的search_read()方法?

时间:2016-07-29 05:24:50

标签: python openerp odoo-8 odoo-9

受影响的版本:9.0

我尝试根据类别限制某些产品。

我有覆盖 name_search()方法,该方法适用于 Many2one 字段。但是当我从 Many2one 字段中的搜索更多选项中搜索产品或从列表视图中的搜索菜单搜索产品时,它会向我显示该产品。

我尝试过以下代码:

2016-07-29 05:09:01,167 9750 ERROR enterprise openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/home/odoo9/odoo-9.0e-20160127/openerp/http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/http.py", line 680, in dispatch
    result = self._call_function(**self.params)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/http.py", line 316, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/http.py", line 309, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/http.py", line 959, in __call__
    return self.method(*args, **kw)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/http.py", line 509, in response_wrap
    response = f(*args, **kw)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/addons/web/controllers/main.py", line 847, in search_read
    return self.do_search_read(model, fields, offset, limit, domain, sort)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/addons/web/controllers/main.py", line 868, in do_search_read
    request.context)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/http.py", line 1064, in proxy
    result = meth(cr, request.uid, *args, **kw)
  File "/home/odoo9/odoo-9.0e-20160127/openerp/api.py", line 250, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: search_read() takes at most 7 arguments (9 given)

但它会给我跟踪追溯。

id | value | datestamp
-----------------------
1  | 89    | 2015-05-25 16:49:25
2  | 60    | 2015-05-26 16:49:25
3  | 42    | 2015-05-27 16:49:25
4  | 12    | 2015-05-28 16:49:25
5  | 3     | 2015-05-29 16:49:25
6  | 95    | 2015-05-30 16:49:25
7  | 75    | 2015-06-01 16:49:25
8  | 52    | 2015-06-02 16:49:25
9  | 31    | 2015-06-03 16:49:25
10 | 12    | 2015-06-04 16:49:25
11 | 99    | 2015-06-05 16:49:25
...

问题

  1. 如何限制用户绕过从搜索菜单中选择产品?

  2. 如何覆盖 search_read()方法?

1 个答案:

答案 0 :(得分:2)

它应该是这样的:

@api.model
def search_read(
        self, domain=None, fields=None, offset=0,
        limit=None, order=None):
    res = super(ProductTemplate, self).search_read(
        domain, fields, offset, limit, order)
    return res