Skip to Content
Menu
This question has been flagged
1 Reply
2590 Views

I have 3 custom models (model_one,model_one_line and model_two)

In my model_one, I have a tree view that displays the o2m field which data are from the model_one_line (model_one is o2m to model_one_line and model_one_line is m2o to model_one).

The data from the model_one_line were fetched from stock.move, Now I displayed The o2m field of model_one(product,pcs,kgs,amount), in every product there's a corresponding customers who bought it.


So I created the model_two which is for customer for every product (model_one_line is o2m to model_two and model_two is m2o of model_one_line * I added these fields on model_two and model_one_line), I want to when I click a row from model_one, a new tree view appeared and displayed the customers based on the product of the row I clicked, 


How can I achieved this?I already have the view for the model_two and it's already displays nothing for now. This is my first time encounter a task o2m inside a o2m.



Avatar
Discard
Best Answer

Hello,

You can achieve this by using onchange of product_id in model: 'model_one_line'. Suppose name of customer's o2m in both models model_one_line and 'product.product' is 'customer_ids' corresponding customers who bought product.You can write the code something like this.

class ProductProduct(models.Model):
_name = 'product.product'

customer_ids = fields.One2many('res.partner', domain=[('active', '=', True),('customer', '=', True)])


class model_one_line(models.Model):
_name = 'model_one_line'

customer_ids = fields.One2many('res.partner', domain=[('active', '=', True),('customer', '=', True)])

@api.onchange('product_id')
def product_id_change(self):
for line in self:
line.customer_ids = line.product_id.customer_ids


Regards,




Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   



Avatar
Discard
Related Posts Replies Views Activity
2
Mar 16
28348
0
Mar 15
4014
1
May 22
2010
0
Feb 19
3394
2
Aug 24
121