Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
7767 Tampilan

For each Project, I have a list of Stages that needs to be created. For each of those Stages, I will also have Tasks... From python, how do I link Stages to Project?


Currently, in a module that inherit from "project.project", I simply do:

self.env['project.task.type'].create({'name': stage_name})

I've seen that stage model have a 'project_ids' field but I don't succeed to append to it from python.

Any help will be appreciated

Avatar
Buang
Jawaban Terbai

In stage there is project_ids field M2M with project. This is the stages that show in projects's task.

You need to link project in state for link all their tasks.

Below module also usefull for define default stage of each new project-

https://www.odoo.com/apps/modules/12.0/project_task_default_stage/

Avatar
Buang
Jawaban Terbai

I have a default field in the project.task.type model to define that the stage is on a new project and normally another many2one field to define the stage usage. 

default_stage = fields.Boolean(string='Stage on new project', default=False)

Then I just extended the project create method to add the default stages to new projects.

@api.model
def create(self, vals):
    ir_values = self.env['ir.values'].get_default('project.config.settings', 'generate_project_alias')
    if ir_values:
         vals['alias_name'] = vals.get('alias_name') or vals.get('name')
         # Prevent double project creation when 'use_tasks' is checked
         self = self.with_context(project_creation_in_progress=True, mail_create_nosubscribe=True)

         default_stages = self.env['project.task.type'].sudo().search([('default_stage', '=', True)])
         stages_list = list()
         for stage in default_stages:
            stages_list.append((4, stage.id))

         if len(stages_list) > 0:
            vals['stage_ids'] = stages_list

         new_project = super(TablaProjectProjectExtension, self).create(vals)
         return new_project 

Avatar
Buang
Jawaban Terbai

Try this code please :)


from odoo import models, api, fields, SUPERUSER_ID, _

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

# Step specific code to identify it
code = fields.Char('Code')

_sql_constraints = [
('code_uniq', 'unique (code)', "Stage code already exists!"),
]

class Project(models.Model):
_inherit = 'project.project'

@api.model
def _read_group_stage_ids(self, stages, domain, order):
# Call Super Function
response = super(Task, self)._read_group_stage_ids(stages, domain, order)
search_domain = [('id', 'in', response.ids)]
# Append my specifik stages [Stages whose code is equal to todo or inprogress or done or canceled]
search_domain = ['|', ('code', 'in', ['todo', 'inprogress', 'done', 'canceled'])] + search_domain
stage_ids = stages._search(search_domain, order=order, access_rights_uid=SUPERUSER_ID)
return stages.browse(stage_ids)
Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Mar 25
1935
2
Okt 24
5765
1
Mar 17
4826
1
Jun 23
3362
2
Mar 23
2526