我想在点击上下文按钮时为任何客户打开销售订单列表视图。为此我在终端上获取所有ID但没有获得列表视图。那么,如何打开客户销售订单清单(Sales)。为此,我的代码如下。
Python代码:
sale_order_count = fields.Integer(compute='_compute_sale_order_count', string='# of Sales Order')
def _compute_sale_order_count(self):
ir_model_data = self.env['ir.model.data']
try:
view_id = ir_model_data.get_object_reference('sale', 'view_order_tree')[1]
except ValueError:
view_id = False
record_id = self.env['sale.order'].search([('partner_id', '=', self.ren9.id)]).ids
print "viewssss:::", view_id, record_id
if not record_id:
print "Not found"
else:
print "return,,", record_id[0]
return {
'view_type': 'tree',
'view_mode': 'tree',
'views': [(view_id, 'tree')],
'res_model': 'sale.order',
'view_id': view_id,
'type': 'ir.actions.act_window',
'res_id': record_id,
'target': 'new',
}
XML代码:
<div name="button_box" position="inside">
<button class="oe_stat_button" type="action" name="_compute_sale_order_count"
icon="fa-usd">
<field string="Sales" name="sale_order_count" widget="statinfo"/>
</button>
</div>
在终端上打印4个销售订单:
viewssss ::: 506 [101,100,99,98]
return ,, 101
提前致谢,
答案 0 :(得分:0)
请尝试下面的
Python代码:
def _view_sale_orders(self):
ir_model_data = self.env['ir.model.data']
try:
tree_id = ir_model_data.get_object_reference('sale', 'view_order_tree').id
form_id = ir_model_data.get_object_reference('sale', 'view_order_form').id
except ValueError:
view_id = False
partner_id = self.ren9.id
return {
'name': _('Sale Orders'),
'type': 'ir.actions.act_window',
'domain': [('partner_id', '=', partner_id)],
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'sale.order',
'view_id': False,
'views': [(tree_id, 'tree'),(form_id, 'form')],
'target': 'current',
'context': ctx,
}
XML代码:
<div name="button_box" position="inside">
<button class="oe_stat_button" type="object" name="_view_sale_orders" icon="fa-usd">
<field string="Sales" name="sale_order_count" widget="statinfo"/>
</button>
</div>