Skip to content

Commit 4a1c56f

Browse files
committed
[IMP] stamp_sign: added values in stamp dialog & generated its stamp sign
added auto-filling of user details (if internal user) in the stamp dialog. Furthermore, generated a stamp sign based on the user's details and logo, if provided. Moreover, changed the default fonts of the stamp signature.
1 parent 39601a8 commit 4a1c56f

19 files changed

+756
-360
lines changed

stamp_sign/__manifest__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"category": "Sign",
66
"data": [
77
"data/sign_data.xml",
8-
"views/sign_template_views.xml",
8+
"views/sign_request_templates.xml",
99
],
1010
"assets": {
1111
"web.assets_backend": [
@@ -18,7 +18,6 @@
1818
],
1919
},
2020
"installable": True,
21-
"sequence": 1,
2221
"application": True,
2322
"license": "OEEL-1",
2423
}

stamp_sign/controllers/main.py

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,72 @@
22
from odoo.addons.sign.controllers.main import Sign
33

44

5-
class SignController(Sign):
5+
class Sign(Sign):
66
def get_document_qweb_context(self, sign_request_id, token, **post):
77
data = super().get_document_qweb_context(sign_request_id, token, **post)
88
current_request_item = data["current_request_item"]
99
sign_item_types = data["sign_item_types"]
10-
data["logo"] = (
11-
"data:image/png;base64,%s" % http.request.env.user.company_id.logo.decode()
12-
)
10+
company_logo = http.request.env.user.company_id.logo
11+
if company_logo:
12+
data["logo"] = "data:image/png;base64,%s" % company_logo.decode()
13+
else:
14+
data["logo"] = False
1315

1416
if current_request_item:
15-
for item_type in sign_item_types:
16-
if item_type["item_type"] == "stamp":
17-
user_stamp = current_request_item._get_user_stamp()
18-
user_stamp_frame = current_request_item._get_user_stamp_frame()
19-
item_type["auto_value"] = (
20-
"data:image/png;base64,%s" % user_stamp.decode()
21-
if user_stamp
22-
else False
23-
)
24-
item_type["frame_value"] = (
25-
"data:image/png;base64,%s" % user_stamp_frame.decode()
26-
if user_stamp_frame
27-
else False
28-
)
17+
user_stamp = current_request_item._get_user_signature_asset("stamp_sign_stamp")
18+
user_stamp_frame = current_request_item._get_user_signature_asset("stamp_sign_stamp_frame")
19+
20+
encoded_user_stamp = (
21+
"data:image/png;base64,%s" % user_stamp.decode()
22+
if user_stamp
23+
else False
24+
)
25+
encoded_user_stamp_frame = (
26+
"data:image/png;base64,%s" % user_stamp_frame.decode()
27+
if user_stamp_frame
28+
else False
29+
)
30+
31+
stamp_item_type = next(
32+
(
33+
item_type
34+
for item_type in sign_item_types
35+
if item_type["item_type"] == "stamp"
36+
),
37+
None,
38+
)
39+
40+
if stamp_item_type:
41+
stamp_item_type["auto_value"] = encoded_user_stamp
42+
stamp_item_type["frame_value"] = encoded_user_stamp_frame
2943

3044
return data
45+
46+
@http.route(["/sign/update_user_signature"], type="json", auth="user")
47+
def update_signature(
48+
self, sign_request_id, role, signature_type=None, datas=None, frame_datas=None
49+
):
50+
user = http.request.env.user
51+
if not user or signature_type not in [
52+
"sign_signature",
53+
"sign_initials",
54+
"stamp_sign_stamp",
55+
]:
56+
return False
57+
58+
sign_request_item_sudo = (
59+
http.request.env["sign.request.item"]
60+
.sudo()
61+
.search(
62+
[("sign_request_id", "=", sign_request_id), ("role_id", "=", role)],
63+
limit=1,
64+
)
65+
)
66+
67+
allowed = sign_request_item_sudo.partner_id.id == user.partner_id.id
68+
if not allowed:
69+
return False
70+
user[signature_type] = datas[datas.find(",") + 1 :]
71+
if frame_datas:
72+
user[signature_type + "_frame"] = frame_datas[frame_datas.find(",") + 1 :]
73+
return True

stamp_sign/data/sign_data.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<field name="name">Stamp</field>
55
<field name="item_type">stamp</field>
66
<field name="tip">stamp</field>
7-
<field name="placeholder">Stamp It</field>
8-
<field name="default_width" type="float">0.200</field>
9-
<field name="default_height" type="float">0.050</field>
7+
<field name="placeholder">Stamp</field>
8+
<field name="default_width" type="float">0.300</field>
9+
<field name="default_height" type="float">0.10</field>
1010
<field name="icon">fa-certificate</field>
1111
</record>
1212
</odoo>

stamp_sign/models/res_users.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
from odoo import models, api, fields
2-
import base64
1+
from odoo import models, fields
2+
3+
SIGN_USER_FIELDS = ["stamp_sign"]
34

45

56
class ResUsers(models.Model):
67
_inherit = "res.users"
78

8-
stamp_sign = fields.Binary(string="Digital Stamp", copy=False, groups="base.group_user")
9-
stamp_sign_frame = fields.Binary(string="Digital Stamp Frame", copy=False, groups="base.group_user")
9+
@property
10+
def SELF_READABLE_FIELDS(self):
11+
return super().SELF_READABLE_FIELDS + SIGN_USER_FIELDS
12+
13+
@property
14+
def SELF_WRITEABLE_FIELDS(self):
15+
return super().SELF_WRITEABLE_FIELDS + SIGN_USER_FIELDS
1016

11-
@api.model
12-
def get_current_user_company_details(self):
13-
user = self.env.user
14-
details = {
15-
"name": user.name,
16-
"company": user.company_id.name if user.company_id else "",
17-
"address": user.company_id.street if user.company_id else "",
18-
"city": user.company_id.city if user.company_id else "",
19-
"country": user.company_id.country_id.name
20-
if user.company_id and user.company_id.country_id
21-
else "",
22-
"vat": user.company_id.vat if user.company_id else "",
23-
"logo_url": False,
24-
}
25-
if user.company_id and user.company_id.logo:
26-
details["logo_url"] = "data:image/png;base64," + base64.b64encode(
27-
user.company_id.logo
28-
).decode("utf-8")
29-
return details
17+
stamp_sign_stamp = fields.Binary(
18+
string="Company Stamp", copy=False, groups="base.group_user"
19+
)
20+
stamp_sign_stamp_frame = fields.Binary(
21+
string="Company Stamp Frame", copy=False, groups="base.group_user"
22+
)

0 commit comments

Comments
 (0)