Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

What I can do with this error? ValueError: Expected singleton: sale.order.line(26, 27)

By
beriliox
on 5/18/16, 12:14 PM 892 views

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.

0
Julio Serna
On 5/18/16, 2:51 PM

Hello Beriliox,


The issue is this line,

if self.order_line.product_id.product_tmpl_id.type in 'product':


because at this part of code self.order_line you have the recordset sale.order.line(26, 27) and then you can not continue iterating with product_id because with this sale.order.line(26, 27).product_id  you don't know what product_id if the order_line(26) or order_line(27),  you can use,

if self.order_line.filtered(lambda dat: dat.product_id.product_tmpl_id.type == 'product'):

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/18/16, 12:14 PM
Seen: 892 times
Last updated: 5/18/16, 2:54 PM