I am currently working in Odoo 11 on odoo.sh, but my local development environment is the official Odoo 11 Docker image. It is in the Docker container that I am getting the error and I can't push to Odoo.sh until that is fixed.
I am writing a custom module to interact with our ShipStation account. This particular problem is when I try to convert a ShipStation Order Line Item into an Odoo Sales Order Line. Here is my code:
@api.model
def convert_order_line_to_sales_line(self,data,line_number):
s_o_l =None
if not data.product_id:
self.env['shipstation.log'].create({
'title':"Create SO",
'type':'NO Got prod',
'message':"No Product for SO with SKU: "+ data.sku
})
returnNone
write_dict ={
'order_id': data.order_id.id,
'price_unit': data.unitPrice,
'product_id': data.product_id,
'name': data.product_id.name,
'product_uom_qty': data.quantity,
'sequence': line_number,
'product_uom': data.product_id.product_tmpl_id.uom_id,
'order_partner_id': data.order_id.partner_id.id,
}
s_o_l =self.search([
('order_id','=', data.order_id.id ),
('sequence','=', line_number )
])
if s_o_l:
self.env['shipstation.log'].create({
'title':"Create SO",
'type':'WRITE',
'message':"trying to write: "+repr( write_dict )
})
s_o_l.write( write_dict )
else:
self.env['shipstation.log'].create({
'title':"Create SO",
'type':'CREATE',
'message':"trying to create: "+repr( write_dict )
})
s_o_l =self.create( write_dict )
return s_o_l
If I comment out the create statement, my log (just above it) looks like this:
|
| ||
| |||
So, the I have checked all of the object references in the write_dict dictionary and (from what I can see) they are all present and valid. I don't see any other required fields in the sale.order.line. I have tried to remove or change values like 'sequence' and 'name', but I get the same error.
What am I missing?
EDIT:
Now that I look at it I think my third line of my dictionary in the log needs to be:
EDIT (part 2):
Nope, that didn't fix it. I now get res.partner( 7,), in the write_dict, but still get the same error. HELP PLEASE!
EDIT (part 3)
I think I figured it out.
I removed the .id from 'order_id': data.order_id.id, to 'order_id': data.order_id, and got a new error that gave me great insight into my problem -- I have been dealing with too many order_id's. The one used here is not the sale.order.id like it should be. Now I just have to figure out how to do it right.
I needed to pass in the sale.order.id as a parameter and then change the order of the process that calls this one to create the sale.order first to get the ID, then call this with that ID . . . and it works!!
Here it is:
@api.model
def convert_order_line_to_sales_line(self, data, sale_order_line_id,line_number):
s_o_l =None
if not data.product_id:
self.env['shipstation.log'].create({
'title':"Create SO",
'type':'NO Got prod',
'message':"No Product for SO with SKU: "+ data.sku
})
returnNone
write_dict ={
'order_id': sale_order_line_id,
'price_unit': data.unitPrice,
'product_id': data.product_id.id,
'name': data.product_id.name,
'product_uom_qty': data.quantity,
'sequence': line_number,
'product_uom': data.product_id.product_tmpl_id.uom_id.id,
'order_partner_id': data.order_id.partner_id.id,
}
s_o_l =self.search([
('order_id','=', sale_order_line_id ),
('sequence','=', line_number )
])
if s_o_l:
self.env['shipstation.log'].create({
'title':"Create SO",
'type':'WRITE',
'message':"trying to write: "+repr( write_dict )
})
s_o_l.write( write_dict )
else:
self.env['shipstation.log'].create({
'title':"Create SO",
'type':'CREATE',
'message':"trying to create: "+repr( write_dict )
})
s_o_l =self.create( write_dict )
return s_o_l
REPLY TO subbarao:
Thank you for your reply. Actually, that last code I posted works great. I have all required fields included. I was passing the shipstation order ID, not the Odoo Sales Order ID like Odoo was expecting.