Files
odoo_source/addons/website_payment/models/payment_transaction.py
T
Gorash 880954ebfc [IMP] *: remove _render from ir.ui.view and simplify report
There were inconsistencies in the calls to `_render`.
* the view context could contain information that misled developers.
Indeed, the context and value of the view are not supposed to be found
in the rendering. Thus by calling `ir.qweb` with the name of the
template, we ensure that there is no unwanted information and in
addition the cache key is that of the name of the template which saves
a query.
* the context used for rendering was modified by a method on
`ir.ui.view`, except this is not information used by this model. There
is now a `_prepare_environment` method residing on `ir.qweb`. This
method allows to modify the value dictionary as well as the context in
which the rendering will be done. This preparation of the data as well
as my security check is done only once per rendering. This also saves
some queries
* Freeze options for rendering were inconsistent. It could be that
options on which rendering depends were not part of the cache key. Thus,
depending on the user who generated the generation of the rendering
function, there was or was not information in the template. For example
for automatic branding. This is no longer possible, because it is the
context that is used. The options serving as a cache key are only
recorded for information (for the profiling system for example). A
simplification of the `ir.qweb.field` models could be made.

The report rendering and call `ir.qweb` instead of `ir.ui.view`.

Part-of: odoo/odoo#85110
2022-03-29 10:56:15 +02:00

47 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, fields, models
class PaymentTransaction(models.Model):
_inherit = "payment.transaction"
is_donation = fields.Boolean(string="Is donation", help="Is the payment a donation")
def _finalize_post_processing(self):
super()._finalize_post_processing()
for tx in self.filtered('is_donation'):
tx._send_donation_email()
msg = [_('Payment received from donation with following details:')]
for field in ['company_id', 'partner_id', 'partner_name', 'partner_country_id', 'partner_email']:
field_name = tx._fields[field].string
value = tx[field]
if value:
if hasattr(value, 'name'):
value = value.name
msg.append('<br/>- %s: %s' % (field_name, value))
tx.payment_id._message_log(body=''.join(msg))
def _send_donation_email(self, is_internal_notification=False, comment=None, recipient_email=None):
self.ensure_one()
if is_internal_notification or self.state == 'done':
subject = _('A donation has been made on your website') if is_internal_notification else _('Donation confirmation')
body = self.env['ir.qweb']._render('website_payment.donation_mail_body', {
'is_internal_notification': is_internal_notification,
'tx': self,
'comment': comment,
}, minimal_qcontext=True)
self.env.ref('website_payment.mail_template_donation').send_mail(
self.id,
email_layout_xmlid="mail.mail_notification_light",
email_values={
'email_to': recipient_email if is_internal_notification else self.partner_email,
'email_from': self.company_id.email_formatted,
'author_id': self.partner_id.id,
'subject': subject,
'body_html': body,
},
force_send=True,
)