[ADD] Addon: project_required_field_by_stage#1650
[ADD] Addon: project_required_field_by_stage#1650
Conversation
8e2d9a3 to
f51f3e4
Compare
f51f3e4 to
709ab1c
Compare
6af46a5 to
d973054
Compare
d973054 to
60b2afd
Compare
|
Code LGTM. |
|
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: |
There was a problem hiding this comment.
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,
}
)
)
There was a problem hiding this comment.
Ah yes I agree, I see that stage_id is a Many2one field
There was a problem hiding this comment.
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.
reopening #1341 with original commits.
Added changes requested in that original MR-.