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

ValueError Expected singleton: sale.order.line when I Create record from sale order line to Project

By
Odoo
on 4/22/16, 4:11 AM 598 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

2

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 4/22/16, 4:35 AM

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.

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

Odoo
on 4/22/16, 5:13 AM

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

1 follower(s)

Stats

Asked: 4/22/16, 4:11 AM
Seen: 598 times
Last updated: 4/22/16, 5:12 AM