Skip to content

Commit 200a01e

Browse files
committed
[IMP] sign_stamp: add test dialog box and fetch company data for auto-fill
Technical Changes: add stamp_sign_stamp and stamp_sign_stamp_frame in res.users for store stamp data fetch company data in sign_request page add test dialog box when user click stamp then test dialog box is open
1 parent f240779 commit 200a01e

File tree

10 files changed

+114
-6
lines changed

10 files changed

+114
-6
lines changed

sign_stamp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
from . import controllers
12
from . import models

sign_stamp/__manifest__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
'description': """
55
add stamp field in sing app
66
""",
7+
'depends': ['sign', 'web'],
78
'data': [
89
'data/sign_data.xml',
910
'views/sign_request_templates.xml'
1011
],
11-
'depends': ['sign'],
12+
"assets": {
13+
"web.assets_backend": [
14+
"sign_stamp/static/src/components/sign_request/**/*.js",
15+
"sign_stamp/static/src/components/sign_request/**/*.xml",
16+
],
17+
"sign.assets_public_sign": [
18+
"sign_stamp/static/src/components/sign_request/**/*.js",
19+
"sign_stamp/static/src/components/sign_request/**/*.xml",
20+
],
21+
},
1222
'license': 'LGPL-3',
1323
'application': True,
1424
'installable': True

sign_stamp/controllers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main

sign_stamp/controllers/main.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from odoo import http
2+
from odoo.addons.sign.controllers.main import Sign
3+
4+
class Sign(Sign):
5+
def get_document_qweb_context(self, sign_request_id, token, **post):
6+
result = super().get_document_qweb_context(sign_request_id, token, **post)
7+
context = result.get('rendering_context', {})
8+
current_request_item = context.get('current_request_item')
9+
sign_item_types = context.get('sign_item_types')
10+
company_logo = http.request.env.user.company_id.logo
11+
if company_logo:
12+
context['logo'] = "data:image/png;base64,%s" % company_logo.decode()
13+
else:
14+
context['logo'] = False
15+
if current_request_item and sign_item_types:
16+
user_stamp = current_request_item._get_user_stamp('stamp_sign_stamp')
17+
user_stamp_frame = current_request_item._get_user_stamp_frame('stamp_sign_stamp_frame')
18+
encoded_stamp = ("data:image/png;base64,%s" % user_stamp.decode() if user_stamp else False)
19+
encoded_frame = ("data:image/png;base64,%s" % user_stamp_frame.decode() if user_stamp_frame else False)
20+
for item_type in sign_item_types:
21+
if item_type.get('item_type') == 'stamp':
22+
item_type['auto_value'] = encoded_stamp
23+
item_type['frame_value'] = encoded_frame
24+
break
25+
result['rendering_context'] = context
26+
return result
27+
28+
@http.route(["/sign/update_user_signature"], type="jsonrpc", auth="user")
29+
def update_signature(self, sign_request_id, role, signature_type=None, datas=None, frame_datas=None):
30+
sign_request_item_sudo = http.request.env['sign.request.item'].sudo().search([('sign_request_id', '=', sign_request_id), ('role_id', '=', role)], limit=1)
31+
user = http.request.env.user
32+
if not user:
33+
return False
34+
allowed = sign_request_item_sudo.partner_id.id == user.partner_id.id
35+
if not allowed or signature_type not in ['sign_signature', 'sign_initials', 'stamp_sign_stamp']:
36+
return False
37+
user[signature_type] = datas[datas.find(',') + 1:]
38+
user[signature_type+'_frame'] = frame_datas[frame_datas.find(',') + 1:] if frame_datas else False
39+
return True

sign_stamp/data/sign_data.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<record id="sign_item_type_test_stamp" model="sign.item.type">
44
<field name="name">Test Stamp</field>
55
<field name="item_type">stamp</field>
6-
<field name="auto_field">stamp</field>
76
<field name="placeholder">Company&#10;Address&#10;City&#10;Country&#10;VAT Number</field>
87
<field name="default_width" type="float">0.3</field>
98
<field name="default_height" type="float">0.1</field>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { patch } from "@web/core/utils/patch";
2+
import { Document } from "@sign/components/sign_request/document_signable";
3+
4+
patch(Document.prototype, {
5+
getDataFromHTML() {
6+
super.getDataFromHTML();
7+
const { el: parentEl } = this.props.parent;
8+
this.signerInfo = {};
9+
this.signerInfo.company = parentEl.querySelector("#o_sign_signer_company_input_info")?.value;
10+
this.signerInfo.address = parentEl.querySelector("#o_sign_signer_address_input_info")?.value;
11+
this.signerInfo.city = parentEl.querySelector("#o_sign_signer_city_input_info")?.value;
12+
this.signerInfo.country = parentEl.querySelector("#o_sign_signer_country_input_info")?.value;
13+
this.signerInfo.vat = parentEl.querySelector("#o_sign_signer_vat_input_info")?.value;
14+
console.log(this.signerInfo)
15+
}
16+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { patch } from "@web/core/utils/patch";
2+
import { SignablePDFIframe } from "@sign/components/sign_request/signable_PDF_iframe";
3+
import { TestDialog } from "./test_dialog";
4+
5+
patch(SignablePDFIframe.prototype, {
6+
enableCustom(signItem) {
7+
super.enableCustom(signItem);
8+
const signItemType = this.signItemTypesById[signItem.data.type_id];
9+
if (signItemType.item_type !== "stamp") {
10+
return;
11+
}
12+
signItem.el.addEventListener("click", (ev) => {
13+
console.log("STAMP CLICKED => opening dialog");
14+
this.env.services.dialog.add(TestDialog);
15+
});
16+
},
17+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from "@odoo/owl";
2+
import { Dialog } from "@web/core/dialog/dialog";
3+
4+
export class TestDialog extends Component {
5+
static template = "sign_stamp.test_dialog";
6+
static components = { Dialog };
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
<t t-name="sign_stamp.test_dialog">
4+
<Dialog title="'Stamp Dialog'">
5+
<div style="padding:16px; font-size:16px;">
6+
Test Dialog
7+
</div>
8+
<div class="mt16 small">
9+
By signing, I agree that the chosen signature/initials will be a valid electronic representation of my hand-written signature/initials for all purposes when it is used on documents, including legally binding contracts.
10+
</div>
11+
<t t-set-slot="footer">
12+
<button class="btn btn-primary">Sign all</button>
13+
<button class="btn btn-secondary">Sign</button>
14+
<button class="btn btn-secondary">Cancel</button>
15+
</t>
16+
</Dialog>
17+
</t>
18+
</templates>

sign_stamp/views/sign_request_templates.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
<input
1111
id="o_sign_signer_address_input_info"
1212
type="hidden"
13-
t-att-value="current_request_item.partner_id.street if current_request_item and current_request_item.partner_id else None"
13+
t-att-value="current_request_item.partner_id.company_id.partner_id.street if current_request_item and current_request_item.partner_id else None"
1414
/>
1515
<input
1616
id="o_sign_signer_city_input_info"
1717
type="hidden"
18-
t-att-value="current_request_item.partner_id.city if current_request_item and current_request_item.partner_id else None"
18+
t-att-value="current_request_item.partner_id.company_id.partner_id.city if current_request_item and current_request_item.partner_id else None"
1919
/>
2020
<input
2121
id="o_sign_signer_country_input_info"
2222
type="hidden"
23-
t-att-value="current_request_item.partner_id.country_id.name if current_request_item and current_request_item.partner_id else None"
23+
t-att-value="current_request_item.partner_id.company_id.partner_id.country_id.name if current_request_item and current_request_item.partner_id else None"
2424
/>
2525
<input
2626
id="o_sign_signer_vat_input_info"
2727
type="hidden"
28-
t-att-value="current_request_item.partner_id.vat if current_request_item and current_request_item.partner_id else None"
28+
t-att-value="current_request_item.partner_id.company_id.partner_id.vat if current_request_item and current_request_item.partner_id else None"
2929
/>
3030
</xpath>
3131
</template>

0 commit comments

Comments
 (0)