diff --git a/ssi_risk_analysis/models/__init__.py b/ssi_risk_analysis/models/__init__.py index 0c7c739..31434ff 100644 --- a/ssi_risk_analysis/models/__init__.py +++ b/ssi_risk_analysis/models/__init__.py @@ -13,4 +13,5 @@ risk_analysis_item, risk_analysis_worksheet_type, risk_analysis_worksheet, + mixin_risk_analysis, ) diff --git a/ssi_risk_analysis/models/mixin_risk_analysis.py b/ssi_risk_analysis/models/mixin_risk_analysis.py new file mode 100644 index 0000000..9ef20a9 --- /dev/null +++ b/ssi_risk_analysis/models/mixin_risk_analysis.py @@ -0,0 +1,38 @@ +# 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 api, fields, models + + +class MixinRiskAnalysis(models.AbstractModel): + _name = "mixin.risk_analysis" + _description = "Mixin for Object With Risk Analysis" + + risk_analysis_id = fields.Many2one( + string="# Risk Analysis", + comodel_name="risk_analysis", + ) + risk_analysis_state = fields.Selection( + related="risk_analysis_id.state", + store=True, + ) + risk_analysis_result_id = fields.Many2one( + string="Risk Analysis Result", + comodel_name="risk_analysis_result", + compute="_compute_risk_analysis_result_id", + store=True, + ) + + @api.depends( + "risk_analysis_id", + "risk_analysis_id.state", + "risk_analysis_id.result_id", + ) + def _compute_risk_analysis_result_id(self): + for record in self: + result = False + 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