Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
[UPD] improving function
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatnm0612 committed Nov 6, 2023
1 parent 9806346 commit ac8afe9
Showing 1 changed file with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,47 +85,11 @@ def _create_compliance_manager(self, program):
self.ensure_one()
program.ensure_one()
self._check_compliance_manager_info()
if self.compliance_kind == "g2p.program_membership.manager.default":
manager = (
self.env[self.compliance_kind]
.sudo()
.create(
{
"name": "Default",
"program_id": program.id,
"admin_area_ids": [(6, 0, self.admin_area_ids.ids)],
"eligibility_domain": self.compliance_domain,
}
)
)
elif self.compliance_kind == "g2p.program_membership.manager.sql":
manager = (
self.env[self.compliance_kind]
.sudo()
.create(
{
"name": "SQL Query",
"program_id": program.id,
"sql_query": self.compliance_sql,
"sql_query_valid": "valid",
"sql_query_valid_message": "",
"sql_record_count": 0,
}
)
)
elif self.compliance_kind == "g2p.program_membership.manager.tags":
manager = (
self.env[self.compliance_kind]
.sudo()
.create(
{
"name": "Tags Manager",
"program_id": program.id,
"tags_id": self.compliance_tag_id.id,
"area_id": self.area_id.id,
}
)
)
manager = (
self.env[self.compliance_kind]
.sudo()
.create(self._prepare_compliance_criteria_create_vals(program))
)
program.write(
{
"compliance_managers": [
Expand All @@ -140,3 +104,47 @@ def _create_compliance_manager(self, program):
],
}
)

def _prepare_compliance_criteria_create_vals(self, program):
"""
Preparing vals for creating compliance criteria manager for new program.
:param program: instance of g2p.program()
:return (dictionary): create vals for compliance criteria manager
:raise: NotImplementedError for compliance_kind not yet existed
How to inherit this function:
```python
def _prepare_compliance_criteria_create_vals(self, program):
if self.compliance_kind = "new.manager.type":
return {
"key": "value",
...
}
return super()._prepare_compliance_criteria_create_vals(program)
```
"""
if self.compliance_kind == "g2p.program_membership.manager.default":
return {
"name": "Default",
"program_id": program.id,
"admin_area_ids": [(6, 0, self.admin_area_ids.ids)],
"eligibility_domain": self.compliance_domain,
}
elif self.compliance_kind == "g2p.program_membership.manager.sql":
return {
"name": "SQL Query",
"program_id": program.id,
"sql_query": self.compliance_sql,
"sql_query_valid": "valid",
"sql_query_valid_message": "",
"sql_record_count": 0,
}
elif self.compliance_kind == "g2p.program_membership.manager.tags":
return {
"name": "Tags Manager",
"program_id": program.id,
"tags_id": self.compliance_tag_id.id,
"area_id": self.area_id.id,
}
raise NotImplementedError()

0 comments on commit ac8afe9

Please sign in to comment.