我有这些方法:
@api.depends('order_lines', 'order_lines.isbn')
def _get_products(self):
isbn = self.env['product.product']
for prodtmpl in self.order_lines:
isbn |= prodtmpl.isbn
return isbn
@api.model
def _get_act_window_dict(self, name):
mod_obj = self.env['ir.model.data']
result = mod_obj.xmlid_to_object(name)
if not result:
result = {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'stock.quant',
'name': 'Stock On Hand',
'type': 'ir.actions.act_window',
}
else:
result = result[0].read()[0]
return result
@api.multi
def action_open_isbn(self):
isbn = self._get_products()
result = self._get_act_window_dict('stock.product_open_quants')
result['domain'] = "[('isbn','in',[" + ','.join(map(str, isbn.ids)) + "])]"
result['context'] = "{'search_default_locationgroup': 1, 'search_default_internal_loc': 1}"
return result
在方法get_act_window_dict
上,它应该返回有关数量的产品,例如product.template
但它让我觉得这个:
Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 944, in call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\stock\stock.py", line 331, in read_group
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 2082, in read_group
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 4498, in _where_calc
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\osv\expression.py", line 662, in __init__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\osv\expression.py", line 830, in parse
ValueError: Invalid field u'isbn' in leaf "<osv.ExtendedLeaf: (u'isbn', u'in', [59]) on stock_quant (ctx: )>"
我试过这样做:
@api.model
def _get_act_window_dict(self, name):
mod_obj = self.env['ir.model.data']
result = mod_obj.xmlid_to_object(name)
if not result:
result = {
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'stock.quant',
'name': 'Stock On Hand',
'isbn': 'product_id',
'type': 'ir.actions.act_window',
}
else:
result = result[0].read()[0]
return result
将isbn
添加到dict结果为product_id
,但结果相同。
那么,有什么想法吗?
PS:这是我班上的isbn
字段:
isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
当然它在isbn
上不会以stock.quant
的形式存在,但它只是{2}到product
所以它应该以某种方式通过。
答案 0 :(得分:1)
这一行:
result['domain'] = "[('isbn','in',[" + ','.join(map(str, isbn.ids)) + "])]"
应该是:
result['domain'] = "[('product_id','in',[" + ','.join(map(str, isbn.ids)) + "])]"
库存中没有任何领域。由于isbn是object product.product,我认为它与stock.quant的product_id相同.quant