Skip to content

[ADD] stamp_sign: added stamp field, auto-fill user details & get related stamp #850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: 18.0
Choose a base branch
from

Conversation

alap-odoo
Copy link

@alap-odoo alap-odoo commented Jul 10, 2025

Enhanced the signature module by adding a new stamp field. When clicked on it,
a dialog pops up that auto-fills user details (if internal user). The stamp is
also generated based on user information and includes a logo if uploaded,
with updated fonts.

alap-odoo added 2 commits July 8, 2025 18:54
added new field stamp in the sign module. Moreover, created static component for
stamp field. Further, added logic to get the user details if internal user.
Created the dialog view along with the related fields and added the
Functionality for the sign and sign all buttons.
@robodoo
Copy link

robodoo commented Jul 10, 2025

Pull request status dashboard

@alap-odoo alap-odoo changed the title 18.0 add stamp sign alap [ADD] stamp_sign: added stamp field, auto-fill user details & get related stamp Jul 10, 2025
Copy link

@bit-odoo bit-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, Tag is different in your PR header and commit message.

your branch is red. Please check this https://runbot.odoo.com/runbot/batch/2031643/build/84402052

],
},
"installable": True,
"sequence": 1,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why sequence 1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the sequence from the code.

current_request_item = data["current_request_item"]
sign_item_types = data["sign_item_types"]
data["logo"] = (
"data:image/png;base64,%s" % http.request.env.user.company_id.logo.decode()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will break if the logo is None.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code to handle the error if the logo is None.

Comment on lines 17 to 28
user_stamp = current_request_item._get_user_stamp()
user_stamp_frame = current_request_item._get_user_stamp_frame()
item_type["auto_value"] = (
"data:image/png;base64,%s" % user_stamp.decode()
if user_stamp
else False
)
item_type["frame_value"] = (
"data:image/png;base64,%s" % user_stamp_frame.decode()
if user_stamp_frame
else False
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will always be the same.We can move outside loop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved this out of the loop.

limit=1,
)
)
user = http.request.env.user

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can declare this before .search(). and return False if not user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the code to move the user before the .search() method and return if not user.

if (
not allowed
or signature_type
not in ["sign_signature", "sign_initials", "stamp_sign_stamp"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above you can move this before search()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved this also above the .search() method.

class SignRequest(models.Model):
_inherit = "sign.request"

def _generate_completed_document(self, password=""):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not good practice to write a long function. It is hard to maintain and read.You can split the method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the code to make the small helper functions.

Comment on lines 344 to 249
def _get_user_stamp(self, stamp_type="stamp_sign_stamp"):
self.ensure_one()
sign_user = self.partner_id.user_ids[:1]
if sign_user and stamp_type in ["stamp_sign_stamp"]:
return sign_user["stamp_sign_stamp"]
return False

def _get_user_stamp_frame(self, stamp_type="stamp_sign_stamp_frame"):
self.ensure_one()
sign_user = self.partner_id.user_ids[:1]
if sign_user and stamp_type in ["stamp_sign_stamp_frame"]:
return sign_user["stamp_sign_stamp_frame"]
return False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make one generic method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made a generic method handling the work of both methods.

Comment on lines 10 to 15
this.company = parentEl.querySelector("#o_sign_signer_company_input_info")?.value;
this.address = parentEl.querySelector("#o_sign_signer_address_input_info")?.value;
this.city = parentEl.querySelector("#o_sign_signer_city_input_info")?.value;
this.country = parentEl.querySelector("#o_sign_signer_country_input_info")?.value;
this.vat = parentEl.querySelector("#o_sign_signer_vat_input_info")?.value;
this.logo = parentEl.querySelector("#o_sign_signer_logo_input_info")?.value;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can store it in one variable. And do it with loop (key, value).so it is easy to scalable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the code as told.

* @param { HTMLElement } signatureItem
* @param {*} type
*/
openSignatureDialog(signatureItem, type) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't write a long function. You can create some helper function. A smaller function is easy to debug.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have create some helper functions which makes code easy to debug.

const reader = new FileReader();
reader.onload = () => {
this.props.signature.logo = reader.result;
this.drawCurrentName();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add if (this.state.signMode === "auto") ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the above-mentioned condition.

@alap-odoo
Copy link
Author

In older of version of odoo which is in my laptop, the PDFReadError is import in the same way as I did and runbot is checking with newer version.

@alap-odoo alap-odoo force-pushed the 18.0-add-stamp-sign-alap branch from c805f25 to 49b34f0 Compare July 11, 2025 07:24
…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.
@alap-odoo alap-odoo force-pushed the 18.0-add-stamp-sign-alap branch from 49b34f0 to 4a1c56f Compare July 11, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants