Hello All,
I want to open sales orders list view for any customer when click on context button. For this i getting all the ids on terminal but not getting list view. So, How to open customer sales orders list(Sales). For this my code is below.
Python Code:
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 Code:
<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>
For 4 sales orders print on terminal:
viewssss::: 506 [101, 100, 99, 98]
return,, 101
Thanks in advance,
Also functional field in Python Code:
sale_order_count = fields.Integer(compute='_compute_sale_order_count', string='# of Sales Order')