콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
3240 화면

When a task is created, it automatically updates the subtasks that I want to pre-define.



아바타
취소
베스트 답변

Hi,

Please try below code 
from odoo import models, fields, api


class ProjectTask(models.Model):

    _inherit = 'project.task'


    @api.model

    def create(self, vals):

        task = super().create(vals)


        # Only create subtasks if this is NOT a subtask already

        if not vals.get('parent_id'):

            predefined_subtasks = [

                {'name': 'Requirement Gathering'},

                {'name': 'Design'},

                {'name': 'Development'},

                {'name': 'Testing'},

                {'name': 'Deployment'},

            ]


            for subtask_data in predefined_subtasks:

                self.create({

                    'name': subtask_data['name'],

                    'project_id': __manifest__.py

'depends': ['project'],


Second Way 

UI-Only (Automated Actions - Odoo Studio)

If you're using Odoo Online (SaaS) or want to do this without code:

Go to: Settings > Technical > Automated Actions

Create a new action:

  • Model : Project Task
  • Trigger : On Creation
  • Action To Do : Create a new record

Add multiple “Create Record” actions with:

  • Model: project.task
  • Fields:
    • Name : Requirement Gathering
    • Parent Task : Record ID
    • Project : Project ID

i hope it is helpfull

아바타
취소
베스트 답변

Hi,

Please refer to the code below:


from odoo import models, api


class ProjectTask(models.Model):

    _inherit = 'project.task'


    @api.model

    def create(self, vals):

        task = super(ProjectTask, self).create(vals)

        # Check if project or any condition needed

        if vals.get('project_id'):  # Or any project-specific logic

            subtasks = ['Design', 'Development', 'Testing'] # sample redefined subtask

            for sub in subtasks:

                self.create({

                    'name': sub,

                    'parent_id': task.id,

                    'project_id': task.project_id.id,

                })

        return task


Hope it helps.

아바타
취소
관련 게시물 답글 화면 활동
2
8월 25
587
2
8월 25
1617
0
2월 25
1685
1
8월 25
2344
2
12월 24
1938