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

I'm using odoo 10, I have added the many2one field "task_id" to the model sale.order

python file :

class SaleOrder(models.Model):

_inherit = "sale.order"

task_id = fields.Many2one('project.task', 'Task name')

class ProjectTask (models.Model):

_inherit = "project.task"

order_lines = fields.One2many('task.order.line','task_id',string="Products")

class TaskOrderLine(models.Model):

_name = 'task.order.line'

task_id = fields.Many2one('project.task')

product_id = fields.Many2one('product.product', string='Products')


in xml file i used : 

 <xpath expr="//form/sheet/notebook/page/field/tree/field[@name='product_id']" position="attributes">

<attribute name="domain">[('task_id', 'in', task_id)]</attribute>

  </xpath>


I want to apply domain to the many2one field " product_id" in the sale.order to display only products that belongs to the selected "task_id" 


it shows me error , any suggestions on how to apply correctly the domain in order to filter the products shown in the sale.order depending on the selected "task_id" ?

Avatar
Discard
Best Answer

Hi,

I guess you should do something like that

1. on 'task.order.line', create a new field call product_ids, type many2many which is a computed
2. write a function to get all the products based on task_id and sale.order and sale.order.line

3. change domain to <attribute name="domain">[('id', 'in', product_ids[0][2])]</attribute>

Note: you can search in the Odoo code to see how is the domain working with `[0][2]`

Hope it can help you a bit

Avatar
Discard