Odoo Help


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.


Create multiple sale_order_line recursively

Jerome Guerriat
on 10/19/15, 4:14 PM 277 views

Hi everyone. I'm new to odoo and i need your help (again).

So i created a module in which you can link products with a m2m relation.
A specific product can have "linked" product. When buying that specific product, the "linked" products have to be added to the order.
I overrided the create method of sale_order_line to be able to generate new lines for my order for any new product. This seems to work as intended.
If one of my product is linked with another one, which is also linked to a third product, it will also work, and every item will be added correctly.

But i still have one problem. When one of my product cause lines to be created (for its linked products) AND i try to manually add a product that has already been added automaticaly, my algorithm crashes with this error:

File "**********************/parts/odoo/openerp/models.py", line 4048, in <lambda>

@api.returns('self', lambda value: value.id)

AttributeError: 'NoneType' object has no attribute 'id

And the code that provoke the crash:

def create(self, vals):
     is_new_product = True
     for linked_product in self.env["product.product"].browse(vals["product_id"]).linked_products:
         new_order_line["product_uos_qty"] = vals["product_uos_qty"]
         [...other assignation...]

#check if this product is already is this order. If it does, overwrite the line with new quantity
     for previous_order_line in self.env["sale.order"].browse(vals["order_id"]).order_line:
         if previous_order_line.product_id.id == vals["product_id"]:
             new_values = {"product_uos_qty":previous_order_line["product_uos_qty"]+vals["product_uos_qty"],
             is_new_product = False

    if is_new_product:
         return super(sale_order_line, self).create(vals)

The crash seems to happen somewhere in my the second FOR iteration (in which i check if the product is already in the order).

Again, the only way i succeeded to make my crash happen is:

- I add the product A which has a relation with product B.
- Product B is then automatically added to the order
- I try to add another B product to the order

Does anybody see what could be wrong?

Do everything without calling to create the individual order lines using the wirte format of the one2mamy

Axel Mendoza
on 10/20/15, 1:53 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

2 follower(s)


Asked: 10/19/15, 4:14 PM
Seen: 277 times
Last updated: 10/20/15, 1:53 AM