2
votes

I have a new fully customized module called Quotes:

Class A: Products (name (text), description (text), deposit (Boolean), Sub-Products (one2many pointing to Class B))

Class B: Sub-Products (name (text), description (text), factor1 (float), factor2 (float), product (many2one pointing to Class A))

Class C: Quotes (name (text), description (text), date (date-time), line_quote (one2many pointing to class D))

Class D: Line_Products (name (text), description (text), Products (many2one pointing to Class A), deposit (boolean), def_onchange (filling all fields according to Product), Line_Sub-Products (one2many pointing to Class E) , quote (many2one pointing to Class C))

Class E: Line-Sub-Products (name (text), description (text), factor1 (float), factor2 (float), product (many2one pointing to Class D), subproducts (many2one pointing to Class B), def_onchange (filling all fields according to Sub-Products))

I need Class E to be filled automatically, when selecting product in Class D, according to the relationship between Class A and Class B

Any help would be appreciated

1

1 Answers

0
votes

Ok after a while, I found a solution:

First, in Class C, create a field product_id(many2one pointing to class A)

In Class D & Class E "def_onchange" won't be needed, so remove it. We will do this from Class C.

Then, over Class C, just create a method that creates the dictionaries acording to the specific needs:

@api.multi
def action_load(self):
    if self.product_id:
        vals_product={'Line_Products':self.product_id.name,'product_id':self.product_id.id,'deposit':True,'descripcion':self.product_id.description,'quote_id':self.id}
        # Create product vals
        new_product = self.env['classD.model'].create(vals_product)
        # Then loop over items in Product
        for Sub-Product in self.product_id.Sub-Products_ids:
            vals_Sub-Product = {'cober_id':Sub-Product.ids[0],'name':Sub-Product.name,'description':Sub-Product.description,'factor1':Sub-Product.factor1,'factor2':Sub-Product.factor2,'subproducts':Sub-Product.id,'product_id':self.product_id.id}
            # Create Sub-Product vals
            new_Sub-Product = self.env['classE.model'].create(vals_Sub-Product)
        # Browse for Product ID
        self.env['classD.model'].browse(new_product.id).onchange_result()
        return
    else:
        return

Hope anyone finds it helpful.