Skip to content

Commit

Permalink
[UPD] ssi_risk_analysis
Browse files Browse the repository at this point in the history
* Add conclusion
* Add dissenting reason
  • Loading branch information
andhit-r committed Oct 7, 2023
1 parent 7734f63 commit 764908e
Show file tree
Hide file tree
Showing 16 changed files with 374 additions and 39 deletions.
1 change: 1 addition & 0 deletions ssi_risk_analysis/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"menu.xml",
"views/risk_analysis_type_views.xml",
"views/risk_analysis_result_views.xml",
"views/risk_analysis_conclusion_views.xml",
"views/risk_item_views.xml",
"views/risk_analysis_views.xml",
"views/risk_analysis_worksheet_views.xml",
Expand Down
3 changes: 3 additions & 0 deletions ssi_risk_analysis/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
risk_analysis_type,
risk_analysis_type_item,
risk_analysis_type_result,
risk_analysis_type_conclusion,
risk_analysis_result,
risk_analysis_conclusion,
risk_item,
risk_item_result,
risk_item_conclusion,
risk_analysis,
risk_analysis_item,
risk_analysis_worksheet_type,
Expand Down
49 changes: 49 additions & 0 deletions ssi_risk_analysis/models/risk_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,44 @@ class RiskAnalysis(models.Model):
compute="_compute_result_id",
store=True,
)
need_dissenting_reason = fields.Boolean(
string="Need Dissenting Reason",
compute="_compute_need_dissenting_reason",
store=True,
)
dissenting_reason = fields.Text(
string="Dissenting Reason",
readonly=True,
states={
"open": [
("readonly", False),
],
},
)
allowed_conclusion_ids = fields.Many2many(
string="Allowed Risk Analysis Conclusions",
related="type_id.allowed_conclusion_ids",
store=False,
)
conclusion_id = fields.Many2one(
string="Conclusion",
comodel_name="risk_analysis_conclusion",
readonly=True,
states={
"open": [
("readonly", False),
],
},
)
conclusion = fields.Text(
string="Conclusion Reasoning",
readonly=True,
states={
"open": [
("readonly", False),
],
},
)
state = fields.Selection(
string="State",
selection=[
Expand Down Expand Up @@ -229,6 +267,17 @@ def _compute_result_id(self):
record.automatic_result_id = automatic_result
record.result_id = final_result

@api.depends(
"manual_result_id",
"automatic_result_id",
)
def _compute_need_dissenting_reason(self):
for record in self:
result = False
if record.manual_result_id != record.automatic_result_id:
result = True
record.need_dissenting_reason = result

@api.onchange(
"type_id",
)
Expand Down
11 changes: 11 additions & 0 deletions ssi_risk_analysis/models/risk_analysis_conclusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2022 OpenSynergy Indonesia
# Copyright 2022 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import models


class RiskAnalysisConslusion(models.Model):
_name = "risk_analysis_conclusion"
_inherit = ["mixin.master_data"]
_description = "Risk Analysis Conclusion"
18 changes: 18 additions & 0 deletions ssi_risk_analysis/models/risk_analysis_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,28 @@ class RiskAnalysisType(models.Model):
default="result = False",
required=True,
)
conclusion_ids = fields.One2many(
string="Risk Analysis Conclusions",
comodel_name="risk_analysis_type.conclusion",
inverse_name="type_id",
)
allowed_conclusion_ids = fields.Many2many(
string="Allowed Risk Analysis Conclusions",
comodel_name="risk_analysis_conclusion",
compute="_compute_allowed_conclusion_ids",
store=False,
)

def _compute_allowed_result_ids(self):
for record in self:
result = self.env["risk_analysis_result"]
for ra_result in record.result_ids:
result += ra_result.result_id
record.allowed_result_ids = result

def _compute_allowed_conclusion_ids(self):
for record in self:
result = self.env["risk_analysis_conclusion"]
for ra_conclusion in record.conclusion_ids:
result += ra_conclusion.conclusion_id
record.allowed_conclusion_ids = result
29 changes: 29 additions & 0 deletions ssi_risk_analysis/models/risk_analysis_type_conclusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 OpenSynergy Indonesia
# Copyright 2022 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models


class RiskAnalysisTypeConclusion(models.Model):
_name = "risk_analysis_type.conclusion"
_description = "Risk Analysis Type - Conclusion"
_order = "type_id, sequence, id"

type_id = fields.Many2one(
string="Type",
comodel_name="risk_analysis_type",
required=True,
ondelete="cascade",
)
sequence = fields.Integer(
string="Sequence",
default=10,
required=True,
)
conclusion_id = fields.Many2one(
string="Conclusion",
comodel_name="risk_analysis_conclusion",
required=True,
onldete="restrict",
)
49 changes: 49 additions & 0 deletions ssi_risk_analysis/models/risk_analysis_worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,44 @@ class RiskAnalysisWorksheet(models.Model):
compute="_compute_result_id",
store=True,
)
need_dissenting_reason = fields.Boolean(
string="Need Dissenting Reason",
compute="_compute_need_dissenting_reason",
store=True,
)
dissenting_reason = fields.Text(
string="Dissenting Reason",
readonly=True,
states={
"open": [
("readonly", False),
],
},
)
allowed_conclusion_ids = fields.Many2many(
string="Allowed Risk Analysis Conclusions",
related="item_id.allowed_conclusion_ids",
store=False,
)
conclusion_id = fields.Many2one(
string="Conclusion",
comodel_name="risk_analysis_conclusion",
readonly=True,
states={
"open": [
("readonly", False),
],
},
)
conclusion = fields.Text(
string="Conclusion Reasoning",
readonly=True,
states={
"open": [
("readonly", False),
],
},
)
state = fields.Selection(
string="State",
selection=[
Expand Down Expand Up @@ -227,6 +265,17 @@ def _compute_allowed_item_ids(self):
result += item.item_id
record.allowed_item_ids = result

@api.depends(
"manual_result_id",
"automatic_result_id",
)
def _compute_need_dissenting_reason(self):
for record in self:
result = False
if record.manual_result_id != record.automatic_result_id:
result = True
record.need_dissenting_reason = result

@api.depends(
"item_id",
)
Expand Down
31 changes: 24 additions & 7 deletions ssi_risk_analysis/models/risk_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class RiskItem(models.Model):
comodel_name="risk_item.result",
inverse_name="item_id",
)
conclusion_ids = fields.One2many(
string="Conclusions",
comodel_name="risk_item.conclusion",
inverse_name="item_id",
)
method = fields.Selection(
string="Method",
selection=[
Expand All @@ -29,23 +34,35 @@ class RiskItem(models.Model):
string="Worksheet Type",
comodel_name="risk_analysis_worksheet_type",
)

@api.onchange(
"method",
)
def onchange_worksheet_type_id(self):
self.worksheet_type_id = False

allowed_result_ids = fields.Many2many(
string="Allowed Risk Analysis Results",
comodel_name="risk_analysis_result",
compute="_compute_allowed_result_ids",
store=False,
)
allowed_conclusion_ids = fields.Many2many(
string="Allowed Risk Analysis Conclusions",
comodel_name="risk_analysis_conclusion",
compute="_compute_allowed_conclusion_ids",
store=False,
)

@api.onchange(
"method",
)
def onchange_worksheet_type_id(self):
self.worksheet_type_id = False

def _compute_allowed_result_ids(self):
for record in self:
result = self.env["risk_analysis_result"]
for ra_result in record.result_ids:
result += ra_result.result_id
record.allowed_result_ids = result

def _compute_allowed_conclusion_ids(self):
for record in self:
result = self.env["risk_analysis_conclusion"]
for ra_conclusion in record.conclusion_ids:
result += ra_conclusion.conclusion_id
record.allowed_conclusion_ids = result
29 changes: 29 additions & 0 deletions ssi_risk_analysis/models/risk_item_conclusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 OpenSynergy Indonesia
# Copyright 2022 PT. Simetri Sinergi Indonesia
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models


class RiskItemConclusion(models.Model):
_name = "risk_item.conclusion"
_description = "Risk Item Conclusion"
_order = "item_id, sequence, id"

item_id = fields.Many2one(
string="Item",
comodel_name="risk_item",
required=True,
ondelete="cascade",
)
sequence = fields.Integer(
string="Sequence",
default=10,
required=True,
)
conclusion_id = fields.Many2one(
string="Conclusion",
comodel_name="risk_analysis_conclusion",
required=True,
onldete="restrict",
)
6 changes: 6 additions & 0 deletions ssi_risk_analysis/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ access_risk_analysis_type_item_configurator,risk_analysis_type_item - configurat
access_risk_analysis_type_item_all,risk_analysis_type_item - all user,model_risk_analysis_type_item,,1,0,0,0
access_risk_analysis_type_result_configurator,risk_analysis_type_result - configurator,model_risk_analysis_type_result,risk_analysis_type_group,1,1,1,1
access_risk_analysis_type_result_all,risk_analysis_type_result - all user,model_risk_analysis_type_result,,1,0,0,0
access_risk_analysis_type_conclusion_configurator,risk_analysis_type_conclusion - configurator,model_risk_analysis_type_conclusion,risk_analysis_type_group,1,1,1,1
access_risk_analysis_type_conclusion_all,risk_analysis_type_conclusion - all user,model_risk_analysis_type_conclusion,,1,0,0,0
access_risk_analysis_result_configurator,risk_analysis_result - configurator,model_risk_analysis_result,risk_analysis_result_group,1,1,1,1
access_risk_analysis_result_all,risk_analysis_result - all user,model_risk_analysis_result,,1,0,0,0
access_risk_analysis_conclusion_configurator,risk_analysis_conclusion - configurator,model_risk_analysis_conclusion,risk_analysis_conclusion_group,1,1,1,1
access_risk_analysis_conclusion_all,risk_analysis_conclusion - all user,model_risk_analysis_conclusion,,1,0,0,0
access_risk_item_configurator,risk_item - configurator,model_risk_item,risk_item_group,1,1,1,1
access_risk_item_all,risk_item - all user,model_risk_item,,1,0,0,0
access_risk_item_result_configurator,risk_item_result - configurator,model_risk_item_result,risk_item_group,1,1,1,1
access_risk_item_result_all,risk_item_result - all user,model_risk_item_result,,1,0,0,0
access_risk_item_conclusion_configurator,risk_item_conclusion - configurator,model_risk_item_conclusion,risk_item_group,1,1,1,1
access_risk_item_conclusion_all,risk_item_conclusion - all user,model_risk_item_conclusion,,1,0,0,0
access_risk_analysis_worksheet_type_configurator,risk_analysis_worksheet_type - all,model_risk_analysis_worksheet_type,risk_analysis_worksheet_type_group,1,1,1,1
access_risk_analysis_worksheet_type_all,risk_analysis_worksheet_type - all,model_risk_analysis_worksheet_type,,1,0,0,0
access_risk_analysis_all,risk_analysis - all,model_risk_analysis,,1,0,0,0
Expand Down
12 changes: 12 additions & 0 deletions ssi_risk_analysis/security/res_group_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
/>
</record>

<record id="risk_analysis_conclusion_group" model="res.groups">
<field name="name">Risk Analysis Conclusion</field>
<field
name="category_id"
ref="ssi_risk_management.risk_management_configurator_module_category"
/>
<field
name="users"
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
/>
</record>

<record id="risk_analysis_worksheet_type_group" model="res.groups">
<field name="name">Risk Analysis Worksheet Type</field>
<field
Expand Down
56 changes: 56 additions & 0 deletions ssi_risk_analysis/views/risk_analysis_conclusion_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 OpenSynergy Indonesia
Copyright 2022 PT. Simetri Sinergi Indonesia
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<record id="risk_analysis_conclusion_view_search" model="ir.ui.view">
<field name="name">risk_analysis_conclusion - search</field>
<field name="model">risk_analysis_conclusion</field>
<field
name="inherit_id"
ref="ssi_master_data_mixin.mixin_master_data_view_search"
/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<data />
</field>
</record>

<record id="risk_analysis_conclusion_view_tree" model="ir.ui.view">
<field name="name">risk_analysis_conclusion - tree</field>
<field name="model">risk_analysis_conclusion</field>
<field name="inherit_id" ref="ssi_master_data_mixin.mixin_master_data_view_tree" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<data />
</field>
</record>

<record id="risk_analysis_conclusion_view_form" model="ir.ui.view">
<field name="name">risk_analysis_conclusion - form</field>
<field name="model">risk_analysis_conclusion</field>
<field name="inherit_id" ref="ssi_master_data_mixin.mixin_master_data_view_form" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<data>
</data>
</field>
</record>

<record id="risk_analysis_conclusion_action" model="ir.actions.act_window">
<field name="name">Risk Analysis Conclusions</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">risk_analysis_conclusion</field>
<field name="view_mode">tree,form</field>
</record>

<menuitem
id="risk_analysis_conclusion_menu"
name="Conclusions"
parent="menu_risk_analysis_configuration"
action="risk_analysis_conclusion_action"
groups="risk_analysis_conclusion_group"
sequence="140"
/>

</odoo>
Loading

0 comments on commit 764908e

Please sign in to comment.