Skip to content

Commit

Permalink
[UPD] ssi_risk_analysis
Browse files Browse the repository at this point in the history
* Implementing view template
* Restrict risk analysis choice based on partner
* Remove risk analysis if partner change
  • Loading branch information
andhit-r committed Oct 9, 2023
1 parent 416f851 commit 51142af
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions ssi_risk_analysis/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"data/approval_template_data.xml",
"data/policy_template_data.xml",
"menu.xml",
"templates/mixin_risk_analysis_templates.xml",
"views/risk_analysis_type_views.xml",
"views/risk_analysis_result_views.xml",
"views/risk_analysis_conclusion_views.xml",
Expand Down
49 changes: 49 additions & 0 deletions ssi_risk_analysis/models/mixin_risk_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@

from odoo import api, fields, models

from odoo.addons.ssi_decorator import ssi_decorator


class MixinRiskAnalysis(models.AbstractModel):
_name = "mixin.risk_analysis"
_inherit = [
"mixin.decorator",
]
_description = "Mixin for Object With Risk Analysis"
_risk_analysis_create_page = False
_risk_analysis_page_xpath = "//page[last()]"
_risk_analysis_partner_field_name = False

allowed_risk_analysis_ids = fields.Many2many(
string="Allowed Risk Analysis",
comodel_name="risk_analysis",
compute="_compute_allowed_risk_analysis_ids",
store=False,
)
risk_analysis_id = fields.Many2one(
string="# Risk Analysis",
comodel_name="risk_analysis",
Expand All @@ -23,6 +37,7 @@ class MixinRiskAnalysis(models.AbstractModel):
comodel_name="risk_analysis_result",
compute="_compute_risk_analysis_result_id",
store=True,
compute_sudo=True,
)

@api.depends(
Expand All @@ -36,3 +51,37 @@ def _compute_risk_analysis_result_id(self):
if record.risk_analysis_id and record.risk_analysis_id.state == "done":
result = record.risk_analysis_id.result_id
record.risk_analysis_result_id = result

def _get_allowed_risk_analysis_ids_trigger(self):
result = []
if self._risk_analysis_partner_field_name:
result += [self._risk_analysis_partner_field_name]
return result

@api.depends(lambda self: self._get_allowed_risk_analysis_ids_trigger())
def _compute_allowed_risk_analysis_ids(self):
for record in self:
result = []
record.risk_analysis_id = False
if self._risk_analysis_partner_field_name and hasattr(
record, self._risk_analysis_partner_field_name
):
partner = getattr(record, self._risk_analysis_partner_field_name)
if partner:
criteria = [
("partner_id", "=", partner.commercial_partner_id.id),
("state", "!=", "cancel"),
]
result = self.env["risk_analysis"].search(criteria).ids
record.allowed_risk_analysis_ids = result

@ssi_decorator.insert_on_form_view()
def _risk_analysis_insert_form_element(self, view_arch):
if self._risk_analysis_create_page:
view_arch = self._add_view_element(
view_arch=view_arch,
qweb_template_xml_id="ssi_risk_analysis.risk_analysis",
xpath=self._risk_analysis_page_xpath,
position="after",
)
return view_arch
20 changes: 20 additions & 0 deletions ssi_risk_analysis/templates/mixin_risk_analysis_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="risk_analysis">
<page string="Risk Analysis" name="risk_analysis">
<group>
<field
name="allowed_risk_analysis_ids"
widget="many2many_tags"
invisible="1"
/>
<field
name="risk_analysis_id"
domain="[('id','in',allowed_risk_analysis_ids)]"
/>
<field name="risk_analysis_state" />
<field name="risk_analysis_result_id" />
</group>
</page>
</template>
</odoo>

0 comments on commit 51142af

Please sign in to comment.