Skip to content

[ADD] Addon: project_required_field_by_stage#1650

Open
gfcapalbo wants to merge 3 commits intoOCA:16.0from
gfcapalbo:16.0-add-project_required_field_by_stage
Open

[ADD] Addon: project_required_field_by_stage#1650
gfcapalbo wants to merge 3 commits intoOCA:16.0from
gfcapalbo:16.0-add-project_required_field_by_stage

Conversation

@gfcapalbo
Copy link
Contributor

reopening #1341 with original commits.
Added changes requested in that original MR-.

@gfcapalbo gfcapalbo force-pushed the 16.0-add-project_required_field_by_stage branch from 8e2d9a3 to f51f3e4 Compare January 9, 2026 16:36
@gfcapalbo gfcapalbo force-pushed the 16.0-add-project_required_field_by_stage branch from f51f3e4 to 709ab1c Compare January 9, 2026 16:38
@gfcapalbo gfcapalbo force-pushed the 16.0-add-project_required_field_by_stage branch 2 times, most recently from 6af46a5 to d973054 Compare January 12, 2026 15:53
@gfcapalbo gfcapalbo force-pushed the 16.0-add-project_required_field_by_stage branch from d973054 to 60b2afd Compare January 12, 2026 16:05
@ddejong-therp
Copy link

Code LGTM.
I've tested it, and run the tests as well.
All looks good.

@UrzaBlock
Copy link

Tested its functionality on runboat, and it does what it's supposed to do: When you have added fields in the Required Field section of a stage, a task that gets put in that stage will have those fields highlighted as required.


@api.constrains("stage_id")
def _check_stage_id_(self):
for this in self:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I miss something, but I do not see why the inner loops are necessary. A project can only be in one stage, so why would this be wrong?

    @api.constrains("stage_id")
    def _check_stage_id_(self):
        for this in self:
            required_fields = this.stage_id.required_field_ids
            if not required_fields:
                continue
            for field in required_fields:
                if hasattr(this, field.name) and not getattr(this, field.name):
                    raise UserError(
                        _(  
                            "Field '%(field)s' is mandatory in stage '%(stage)s'."
                        )   
                        % ( 
                            {   
                                "field": field.display_name.split(" (")[0],
                                "stage": this.stage_id.display_name,
                            }   
                        )   
                    ) 

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I agree, I see that stage_id is a Many2one field

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every record has one stage. we only need to check mandatory fields for that one stage, not all stages every time. thank you @NL66278 , i will simplify this , by removing the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants