Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3609 Widoki

Hi everyone,
I have a issue, example:
​"""

class Materials(models.Model):
_name = 'materials.materials'

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


class Task(models.Model):
_inherit = 'project.task'

materials_ids = One2many('materials.materials', 'task_id')

​"""

At here, when I add a line Materials on Subtask(Form View), on Parent Task, this line is still available. (But it is still a record Materials)

 Is there any solution for this case?
Thanks and Regards.



Awatar
Odrzuć
Najlepsza odpowiedź

try this way:


class Materials(models.Model):

_name = 'materials.materials'


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

is_child_material = fields.Boolean("Is Child Material", default=False)


class Task(models.Model):

_inherit = 'project.task'


materials_ids = fields.One2many('materials.materials', 'task_id')

parent_materials_ids = fields.One2many('materials.materials', 'task_id', domain=[('is_child_material', '=', False)])


@api.onchange('materials_ids')

def _onchange_materials_ids(self):

# Set the 'is_child_material' field to True for materials added to subtasks

for subtask in self:

subtask.materials_ids.filtered(lambda m: not m.is_child_material).update({'is_child_material': True})


you want to prevent materials added to a subtask (child task) from being displayed on the parent task. In Odoo, by default, related fields like One2many fields will display all related records, including those created on child records. To achieve the behavior you want, where materials added to a child task are not displayed on the parent task, you can use a computed field to filter the related materials based on some criteria.
from odoo import api, fields, models

Awatar
Odrzuć
Autor

No, I want want to display materials added to a subtask (child task) and display on the parent task

Powiązane posty Odpowiedzi Widoki Czynność
1
kwi 23
5646
1
sty 16
21063
3
paź 23
5204
0
kwi 18
5037
1
wrz 17
4306