Skip to content

Commit 036169e

Browse files
[ADD] tier_validation_password_confirm
1 parent 6211f08 commit 036169e

File tree

12 files changed

+199
-0
lines changed

12 files changed

+199
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=====================================
2+
Tier Validation Password Confirm
3+
=====================================
4+
5+
This module adds a new field to the tier definition that allows to set a password confirmation,
6+
so later in the tier validation the system will ask the user to confirm the password.
7+
8+
Credits
9+
=======
10+
11+
Contributors
12+
------------
13+
14+
- ForgeFlow S.L. <contact@forgeflow.com>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizards
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
2+
{
3+
"name": "Tier Validation Password Confirm",
4+
"version": "18.0.1.0.0",
5+
"category": "Server UX",
6+
"author": "ForgeFlow, Odoo Community Association (OCA)",
7+
"license": "AGPL-3",
8+
"website": "https://github.com/OCA/server-ux",
9+
"depends": [
10+
"base_tier_validation",
11+
],
12+
"data": [
13+
"views/tier_definition_view.xml",
14+
"wizards/tier_password_wizard_view.xml",
15+
],
16+
"installable": True,
17+
"auto_install": False,
18+
"application": False,
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import tier_review
2+
from . import tier_validation
3+
from . import tier_definition
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2024 ForgeFlow S.L.
2+
3+
from odoo import fields, models
4+
5+
6+
class TierDefinition(models.Model):
7+
_inherit = "tier.definition"
8+
9+
require_password = fields.Boolean(
10+
help="If checked, the user will be asked to enter "
11+
"the password to validate the tier.",
12+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2024 ForgeFlow S.L.
2+
from odoo import fields, models
3+
4+
5+
class TierReview(models.Model):
6+
_inherit = "tier.review"
7+
8+
require_password = fields.Boolean(
9+
related="definition_id.require_password", readonly=True
10+
)
11+
password_confirmed = fields.Boolean()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2025 ForgeFlow S.L.
2+
3+
from odoo import _, fields, models
4+
from odoo.exceptions import ValidationError
5+
6+
7+
class TierValidation(models.AbstractModel):
8+
_inherit = "tier.validation"
9+
10+
require_password = fields.Boolean(compute="_compute_require_password")
11+
12+
def _compute_require_password(self):
13+
for rec in self:
14+
require_password = rec.review_ids.filtered(
15+
lambda r: r.status == "pending" and (self.env.user in r.reviewer_ids)
16+
).mapped("require_password")
17+
rec.require_password = True in require_password
18+
19+
def validate_tier(self):
20+
self.ensure_one()
21+
sequences = self._get_sequences_to_approve(self.env.user)
22+
reviews = self.review_ids.filtered(
23+
lambda r: r.sequence in sequences or r.approve_sequence_bypass
24+
)
25+
if self.has_comment or self.require_password:
26+
user_reviews = reviews.filtered(
27+
lambda r: r.status == "pending" and (self.env.user in r.reviewer_ids)
28+
)
29+
return self._add_comment("validate", user_reviews)
30+
self._validate_tier(reviews)
31+
self._update_counter()
32+
33+
def _add_comment(self, validate_reject, reviews):
34+
res = super()._add_comment(validate_reject, reviews)
35+
res["context"]["comment"] = self.has_comment
36+
res["context"]["require_password"] = self.require_password
37+
return res
38+
39+
def _validate_tier(self, tiers=False):
40+
self.ensure_one()
41+
tier_reviews = tiers or self.review_ids
42+
user_reviews = tier_reviews.filtered(
43+
lambda r: r.status == "pending" and (self.env.user in r.reviewer_ids)
44+
)
45+
for review in user_reviews:
46+
if review.require_password and not review.password_confirmed:
47+
raise ValidationError(
48+
_(
49+
"You need to request a validation, because "
50+
"the reviewer requires a password to validate."
51+
)
52+
)
53+
return super()._validate_tier(tiers)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2024 ForgeFlow S.L. -->
3+
<odoo>
4+
<record id="complaint_tier_definition_form" model="ir.ui.view">
5+
<field name="name">complaint.tier.definition.form</field>
6+
<field name="model">tier.definition</field>
7+
<field name="inherit_id" ref="base_tier_validation.tier_definition_view_form" />
8+
<field name="arch" type="xml">
9+
<xpath expr="//notebook/page[@name='options']" position="inside">
10+
<group>
11+
<field name="require_password" />
12+
</group>
13+
</xpath>
14+
</field>
15+
</record>
16+
</odoo>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import tier_password_wizard

0 commit comments

Comments
 (0)