Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] Addon: project_required_field_by_stage #1341

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

Tiago370
Copy link

@Tiago370 Tiago370 commented Sep 26, 2024

This PR add the module project_required_field_by_stage that allow to define required fields depending on the stage of the task.

NOTE: I was unable to find a satisfactory way to cover lines 30-33 and 35-37 of the models/project_task.py file with tests, I accept suggestions.

@Tiago370 Tiago370 changed the title [ADD] Addon: project_required_field_by_stage [16.0][ADD] Addon: project_required_field_by_stage Sep 28, 2024
@Tiago370 Tiago370 force-pushed the 16.0-add-project_required_field_by_stage branch 12 times, most recently from 0afd8b1 to e0829bc Compare September 28, 2024 22:03
@Tiago370 Tiago370 force-pushed the 16.0-add-project_required_field_by_stage branch from e0829bc to 8e2d9a3 Compare September 28, 2024 22:28
@Tiago370 Tiago370 marked this pull request as ready for review September 28, 2024 22:37
Copy link

@gjotten gjotten left a comment

Choose a reason for hiding this comment

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

Functional review, LGTM.

Comment on lines +65 to +66
if hasattr(self, "%s" % field.name):
if not getattr(self, "%s" % field.name):
Copy link

Choose a reason for hiding this comment

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

Suggested change
if hasattr(self, "%s" % field.name):
if not getattr(self, "%s" % field.name):
if hasattr(rec, field.name) and not getattr(rec, field.name):

Comment on lines +56 to +57
for rec in self:
stage = self.env["project.task.type"].search([("id", "=", rec.stage_id.id)])
Copy link

Choose a reason for hiding this comment

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

maybe you can only go through the stages that have required fields assigned.

Suggested change
for rec in self:
stage = self.env["project.task.type"].search([("id", "=", rec.stage_id.id)])
stages = self.stage_id.filtered(lambda x: x.required_field_ids)
for stage in stages:
fields = (
self.env["ir.model.fields"]
.sudo()
.search([("id", "in", stage.required_field_ids.ids)])
)
for rec in self.filtered(lambda x: x.stage_id == stage):
for field in fields:
if hasattr(rec, field.name) and not getattr(rec, field.name):
raise error

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.

3 participants