-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[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
base: 18.0
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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
stamp_sign/__manifest__.py
Outdated
], | ||
}, | ||
"installable": True, | ||
"sequence": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why sequence 1?
There was a problem hiding this comment.
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.
stamp_sign/controllers/main.py
Outdated
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
stamp_sign/controllers/main.py
Outdated
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 | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
stamp_sign/controllers/main.py
Outdated
limit=1, | ||
) | ||
) | ||
user = http.request.env.user |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
stamp_sign/controllers/main.py
Outdated
if ( | ||
not allowed | ||
or signature_type | ||
not in ["sign_signature", "sign_initials", "stamp_sign_stamp"] |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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=""): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
stamp_sign/models/sign_request.py
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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")
?
There was a problem hiding this comment.
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.
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. |
c805f25
to
49b34f0
Compare
…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.
49b34f0
to
4a1c56f
Compare
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.