I am modifying a button (Confirm sale) in the sale.order.form so that when I press , I immediately take the inventory (stock.picking.form). This works perfectly . but when I want to validate the function for when a product is stockable type . It works only when I select only one product in the order .
The problem is when I select more than one product , as in the following image:
Image: http://es.zimagez.com/zimage/12345633.php
This is the function of the 'Confirm sale' button.
@api.multi
def action_confirm(self):
for order in self:
order.state = 'sale'
if self.env.context.get('send_email'):
self.force_quotation_send()
order.order_line._action_procurement_create()
if not order.project_id:
for line in order.order_line:
if line.product_id.invoice_policy == 'cost':
order._create_analytic_account()
break
if self.env['ir.values'].get_default('sale.config.settings', 'auto_done_setting'):
self.action_done()
****HERE BEGINS THE CHANGING FUNCTION****************
if self.order_line.product_id.product_tmpl_id.type in 'product':
action = self.env.ref('stock.action_picking_tree_all')
result = {
'name': action.name,
'help': action.help,
'type': action.type,
'view_type': action.view_type,
'view_mode': action.view_mode,
'target': action.target,
'context': action.context,
'res_model': action.res_model,
}
pick_ids = sum([order.picking_ids.ids for order in self], [])
if len(pick_ids) > 1:
result['domain'] = "[('id','in',["+','.join(map(str, pick_ids))+"])]"
elif len(pick_ids) == 1:
form = self.env.ref('stock.view_picking_form', False)
form_id = form.id if form else False
result['views'] = [(form_id, 'form')]
result['res_id'] = pick_ids[0]
return result
If someone could help me with this problem. How it could validate that the system can accept more than one product in the order? Thank you very much for your help.