-
-
Notifications
You must be signed in to change notification settings - Fork 70
[16.0][IMP] sign_oca: use mail.template instead of static mails #142
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: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| <?xml version="1.0" ?> | ||
| <odoo noupdate="1"> | ||
| <!-- A mail template for signing a document --> | ||
| <record id="email_template_sign_document" model="mail.template"> | ||
| <field name="name">New document to sign</field> | ||
| <field name="model_id" ref="sign_oca.model_sign_oca_request_signer" /> | ||
| <field name="email_from">{{ object.request_id.create_uid.email or '' }}</field> | ||
| <field name="partner_to">{{ object.partner_id.id }}</field> | ||
| <field name="subject">New document to sign</field> | ||
| <field name="description">A notification to sign a document</field> | ||
| <field name="body_html" type="html"> | ||
| <t t-set="sender" t-value="object.request_id.create_uid" /> | ||
| <t t-if="sender.name in ['OdooBot', 'Public User']"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should never use this hard code.... what happens if the user changes the name of OdooBot to MyCompanyBot?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Never underestimate users "creativity" ;-) |
||
| <t t-set="sender" t-value="False" /> | ||
| </t> | ||
| <t t-set="link" t-value="object.env.context.get('link')" /> | ||
| <t t-set="body" t-value="object.env.context.get('body')" /> | ||
| <div> | ||
| <span> | ||
| <t t-if="sender"> | ||
| <t t-out="sender.name" /> | ||
| <a | ||
| t-if="sender.email" | ||
| t-att-href="'mailto:%s?subject=%s' % (sender.email, 'Re: %s' % subject)" | ||
| style="color:#428BCA; text-decoration:none;" | ||
| target="_blank" | ||
| ><t t-out="sender.email" /></a> | ||
| has requested your signature on a document. | ||
| </t> | ||
| <t t-else=""> | ||
| A document has been requested for your signature. | ||
| </t> | ||
| </span> | ||
| <span t-if="body"> | ||
| <div | ||
| style="margin: 16px 0px 16px 0px; padding: 8px 16px 8px 16px; background-color: #F1F1F1;" | ||
| > | ||
| <span> | ||
| <t t-out="body" /> | ||
| </span> | ||
| </div> | ||
| </span> | ||
| <span t-if="link"> | ||
| <div style="margin:16px auto; text-align:center;"> | ||
| <a | ||
| t-att-href="link" | ||
| style="padding: 8px 16px 8px 16px; border-radius: 3px; background-color:#875A7B; text-align:center; text-decoration:none; color: #FFFFFF;" | ||
| > | ||
| Sign document | ||
| </a> | ||
| </div> | ||
| </span> | ||
| <span> | ||
| <div style="opacity: 0.7;"> | ||
| <strong | ||
| >Warning</strong> do not forward this email to other people!<br | ||
| /> | ||
| They will be able to access this document and sign it as yourself.<br | ||
| /> | ||
| </div> | ||
| </span> | ||
| </div> | ||
| </field> | ||
| <field name="lang">{{ object.request_id.user_id.partner_id.lang }}</field> | ||
| <field name="auto_delete" eval="False" /> | ||
| </record> | ||
|
|
||
| <!-- A mail template for signed document --> | ||
| <record id="email_template_signed_document" model="mail.template"> | ||
| <field name="name">New Document has been signed</field> | ||
| <field name="model_id" ref="sign_oca.model_sign_oca_request_signer" /> | ||
| <field name="email_from">{{ object.request_id.create_uid.email or '' }}</field> | ||
| <field name="partner_to">{{ object.partner_id.id }}</field> | ||
| <field name="subject">New Document has been signed</field> | ||
| <field name="description">Notification for signed document</field> | ||
| <field name="body_html" type="html"> | ||
| <t t-set="sender" t-value="object.request_id.create_uid" /> | ||
| <t t-if="sender.name in ['OdooBot', 'Public User']"> | ||
| <t t-set="sender" t-value="False" /> | ||
| </t> | ||
| <div> | ||
| <span> | ||
| <t t-if="sender"> | ||
| <t t-out="sender.name" /> | ||
| (<a | ||
| t-att-href="'mailto:%s?subject=%s' % (sender.email, 'Re: %s' % subject)" | ||
| style="color:#428BCA; text-decoration:none;" | ||
| target="_blank" | ||
| ><t t-out="sender.email" /></a>) | ||
| has sent the signed document. | ||
| </t> | ||
| <t t-else=""> | ||
| A fully signed document has been sent to you. | ||
| </t> | ||
| </span> | ||
| </div> | ||
| </field> | ||
| <field name="lang">{{ object.request_id.user_id.partner_id.lang }}</field> | ||
| <field name="auto_delete" eval="False" /> | ||
| </record> | ||
| </odoo> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,19 +258,10 @@ def action_send(self, sign_now=False, message=""): | |
| signer._portal_ensure_token() | ||
| if sign_now and signer.partner_id == self.env.user.partner_id: | ||
| continue | ||
| render_result = self.env["ir.qweb"]._render( | ||
| "sign_oca.sign_oca_template_mail", | ||
| {"record": signer, "body": message, "link": signer.access_url}, | ||
| engine="ir.qweb", | ||
| minimal_qcontext=True, | ||
| ) | ||
| self.env["mail.thread"].message_notify( | ||
| body=render_result, | ||
| partner_ids=signer.partner_id.ids, | ||
| subject=_("New document to sign"), | ||
| subtype_id=self.env.ref("mail.mt_comment").id, | ||
| mail_auto_delete=False, | ||
| email_layout_xmlid="mail.mail_notification_light", | ||
| template = self.env.ref("sign_oca.email_template_sign_document") | ||
| template.with_context(body=message, link=signer.access_url).send_mail( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method is ok if we log the same message in chatter, I can't use the mail template with sign request, but it is very easy for me and customizable to use with signer model. you see me setting variables in the start of HTML, then I do the free full customization. This is what we want so UX team can work straight forward. |
||
| signer.id, | ||
| force_send=True, | ||
| ) | ||
|
|
||
| def action_send_signed_request(self): | ||
|
|
@@ -292,19 +283,14 @@ def action_send_signed_request(self): | |
| ] | ||
| ) | ||
| ) | ||
| # The message will not be linked to the record because we do not want | ||
| # it happen. | ||
| self.env["mail.thread"].message_notify( | ||
| body=_( | ||
| "%(name)s (%(email)s) has sent the signed document.", | ||
| name=self.create_uid.name, | ||
| email=self.create_uid.email, | ||
| ), | ||
| partner_ids=signer.partner_id.ids, | ||
| subject=_("Signed document"), | ||
| subtype_id=self.env.ref("mail.mt_comment").id, | ||
| mail_auto_delete=False, | ||
| attachment_ids=attachments.ids, | ||
| template = self.env.ref("sign_oca.email_template_signed_document") | ||
| email_values = { | ||
| "attachment_ids": [(6, 0, attachments.ids)], | ||
| } | ||
| template.send_mail( | ||
| signer.id, | ||
| force_send=True, | ||
| email_values=email_values, | ||
| ) | ||
|
|
||
| def _check_signed(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.