This question has been flagged
1 Reply
3159 Views
Here I want to create New Project from a Sale order line ,for that i create a button (create_project_new)
Each line I need to create a single Project .I can create single Project
from single sale order line.I cant Process multiple sale order lines
Suppose I have 10 order line in Sale order then I need to create 10 Projects.
I tried with multiple lines but got error

ValueErrorExpected singleton: sale.order.line(32, 33, 34)


this is my screen shot

http://prnt.sc/avcjdg

this is my code-------------------------

def create_project_new(self,cr,uid,ids,context):
 self.write(cr,uid,ids,{'state':'create_project'})
 invoice_pool = self.pool.get('project.project')
 # product_pool = self.pool.get('product.product')
 default_fields = invoice_pool.fields_get(cr, uid, context=context)
 invoice_default = invoice_pool.default_get(cr, uid, default_fields, context=context)
 for customer in self.browse(cr, uid, ids, context=context):
 temp = customer.order_line.order_id
 for val in temp:
 invoice_data = {
 'name': customer.order_line.product_id.name, }
 invoice_default.update(invoice_data)
 invoice_id = invoice_pool.create(cr, uid, invoice_default, context=context)
 return True






#EDITED WORKING CODE

def create_project_new(self,cr,uid,ids,context):    self.write(cr,uid,ids,{'state':'create_project'})    # for val_obj in self.browse(cr,uid,ids,context):    invoice_pool = self.pool.get('project.project')        # product_pool = self.pool.get('product.product')    default_fields = invoice_pool.fields_get(cr, uid, context=context)    invoice_default = invoice_pool.default_get(cr, uid, default_fields, context=context)    for customer in self.browse(cr, uid, ids, context=context):        temp = customer.order_line            # raise Warning('You can not add instructor as a attendee'+str(temp))        for val in temp:                # raise Warning('You can not add instructor as a attendee'+str(val))            invoice_data = {                                'name': val.product_id.name,                                }            invoice_default.update(invoice_data)            invoice_id = invoice_pool.create(cr, uid, invoice_default, context=context)    return True

Avatar
Discard
Best Answer

I have find  some the logical error here :

temp = customer.order_line.order_id 

customer.order_line.product_id.name

both these two line are wrong,IF  customer will have more than one order line(as you say)  then these two logic will fail.

instead try 

temp = customer.order_line

and now iterate the temp, 

invoice_data = {'name': val.product_id.name,}

this may help you.

Avatar
Discard
Author

Yes corrected with your answer thanj you.......