Skip to content

Commit

Permalink
QC
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevhe18 committed Oct 20, 2023
1 parent 42a7870 commit 2204095
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions ssi_risk_analysis/models/risk_analysis_worksheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0-standalone.html).

from odoo import _, api, fields, models
from odoo.tools.safe_eval import safe_eval
from odoo.exceptions import Warning as UserError
from odoo.tools.safe_eval import safe_eval


class RiskAnalysisWorksheet(models.Model):
Expand Down Expand Up @@ -308,23 +308,29 @@ def _get_automatic_result(self):
result = False
return result

# revisi ssi_risk_analysis
@api.constrains('item_id')
@api.constrains(
"item_id",
)
def _check_item_id(self):
for record in self:
items = self.env["risk_analysis_worksheet"].search([
('item_id', '=', record.item_id.id),
('risk_analysis_id', '=', record.risk_analysis_id.id),
('id', '!=', record.id)
])
items = self.env["risk_analysis_worksheet"].search(
[
("item_id", "=", record.item_id.id),
("risk_analysis_id", "=", record.risk_analysis_id.id),
("id", "!=", record.id),
]
)
if items:
error_message = _(
"""
Context: You can not select the same risk item
Context: You cannot select the same Risk Item for each Risk Analysis
Database ID: %s
Problem: Risk item: %s is used
Solution: Use another risk item
Problem: Risk Item: %s is used
Solution: Use another Risk Item
"""
% (record.id, record.item_id.name,)
% (
record.id,
record.item_id.name,
)
)
raise UserError(error_message)

0 comments on commit 2204095

Please sign in to comment.