[FIX] loyalty, pos_loyalty: download, print, mail gift card
- Gift cards can now be sent alongside the receipt via mail in the Receipt Screen. - The gift card report no longer show n² gift cards - Properly download all PDF files for the gift cards when there are multiple gift card programs closes odoo/odoo#102910 X-original-commit: 5b269ebb3e725ff84c437e204874c14251ed1d78 Signed-off-by: Masereel Pierre <pim@odoo.com> Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
This commit is contained in:
@@ -75,36 +75,34 @@
|
||||
|
||||
<template id="gift_card_report">
|
||||
<t t-call="web.html_container">
|
||||
<t t-foreach="docs" t-as="o">
|
||||
<t t-call="web.external_layout">
|
||||
<div style="margin:0px; font-size:24px; font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:36px; color:#333333; text-align: center">
|
||||
Here is your gift card!
|
||||
</div>
|
||||
<div style="padding-top:20px; padding-bottom:20px">
|
||||
<img src="/loyalty/static/img/gift_card.png" style="display:block; border:0; outline:none; text-decoration:none; margin:auto;" width="300"/>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:35px; padding-bottom:35px; text-align:center;">
|
||||
<h3 style="margin:0px; line-height:48px; font-family:arial, 'helvetica neue', helvetica, sans-serif; font-size:40px; font-style:normal; font-weight:normal; color:#333333; text-align:center">
|
||||
<strong><span t-esc="o.points" t-options="{'widget': 'monetary', 'display_currency': o.currency_id}"/></strong>
|
||||
</h3>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:35px; padding-bottom:35px; background-color:#efefef; text-align:center;">
|
||||
<p style="margin:0px; font-size:14px;font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:21px; color:#333333">
|
||||
<strong>Gift Card Code</strong>
|
||||
</p>
|
||||
<p style="margin:0px; font-size:25px;font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:38px; color:#A9A9A9">
|
||||
<span t-field="o.code"/>
|
||||
</p>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:10px; padding-bottom:10px; text-align:center;">
|
||||
<h3 style="margin:0px; line-height:17px; font-family:arial, 'helvetica neue', helvetica, sans-serif; font-size:14px; font-style:normal; font-weight:normal; color:#A9A9A9; text-align:center">
|
||||
Card expires <span t-field="o.expiration_date"/>
|
||||
</h3>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:10px; padding-bottom:10px; text-align:center;">
|
||||
<img t-att-src="'/report/barcode/Code128/'+o.code" style="width:400px;height:75px" alt="Barcode"/>
|
||||
</div>
|
||||
</t>
|
||||
<t t-call="web.external_layout">
|
||||
<div style="margin:0px; font-size:24px; font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:36px; color:#333333; text-align: center">
|
||||
Here is your gift card!
|
||||
</div>
|
||||
<div style="padding-top:20px; padding-bottom:20px">
|
||||
<img src="/loyalty/static/img/gift_card.png" style="display:block; border:0; outline:none; text-decoration:none; margin:auto;" width="300"/>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:35px; padding-bottom:35px; text-align:center;">
|
||||
<h3 style="margin:0px; line-height:48px; font-family:arial, 'helvetica neue', helvetica, sans-serif; font-size:40px; font-style:normal; font-weight:normal; color:#333333; text-align:center">
|
||||
<strong><span t-esc="o.points" t-options="{'widget': 'monetary', 'display_currency': o.currency_id}"/></strong>
|
||||
</h3>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:35px; padding-bottom:35px; background-color:#efefef; text-align:center;">
|
||||
<p style="margin:0px; font-size:14px;font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:21px; color:#333333">
|
||||
<strong>Gift Card Code</strong>
|
||||
</p>
|
||||
<p style="margin:0px; font-size:25px;font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:38px; color:#A9A9A9">
|
||||
<span t-field="o.code"/>
|
||||
</p>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:10px; padding-bottom:10px; text-align:center;">
|
||||
<h3 style="margin:0px; line-height:17px; font-family:arial, 'helvetica neue', helvetica, sans-serif; font-size:14px; font-style:normal; font-weight:normal; color:#A9A9A9; text-align:center">
|
||||
Card expires <span t-field="o.expiration_date"/>
|
||||
</h3>
|
||||
</div>
|
||||
<div style="padding:0; margin:0px; padding-top:10px; padding-bottom:10px; text-align:center;">
|
||||
<img t-att-src="'/report/barcode/Code128/'+o.code" style="width:400px;height:75px" alt="Barcode"/>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
@@ -50,7 +50,7 @@ class PosConfig(models.Model):
|
||||
if invalid_reward_products_msg:
|
||||
prefix_error_msg = _("To continue, make the following reward products available in Point of Sale.")
|
||||
raise UserError(f"{prefix_error_msg}\n{invalid_reward_products_msg}")
|
||||
if gift_card_programs:
|
||||
if gift_card_programs:
|
||||
for gc_program in gift_card_programs:
|
||||
# Do not allow a gift card program with more than one rule or reward, and check that they make sense
|
||||
if len(gc_program.reward_ids) > 1:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from collections import defaultdict
|
||||
from odoo import _, models
|
||||
import base64
|
||||
|
||||
class PosOrder(models.Model):
|
||||
_inherit = 'pos.order'
|
||||
@@ -146,3 +147,30 @@ class PosOrder(models.Model):
|
||||
fields = super(PosOrder, self)._get_fields_for_order_line()
|
||||
fields.extend(['is_reward_line', 'reward_id', 'coupon_id', 'reward_identifier_code', 'points_cost'])
|
||||
return fields
|
||||
|
||||
def _add_mail_attachment(self, name, ticket):
|
||||
attachment = super()._add_mail_attachment(name, ticket)
|
||||
gift_card_programs = self.config_id._get_program_ids().filtered(lambda p: p.program_type == 'gift_card' and
|
||||
p.pos_report_print_id)
|
||||
if gift_card_programs:
|
||||
gift_cards = self.env['loyalty.card'].search([('source_pos_order_id', '=', self.id),
|
||||
('program_id', 'in', gift_card_programs.mapped('id'))])
|
||||
if gift_cards:
|
||||
for program in gift_card_programs:
|
||||
filtered_gift_cards = gift_cards.filtered(lambda gc: gc.program_id == program)
|
||||
if filtered_gift_cards:
|
||||
action_report = program.pos_report_print_id
|
||||
report = action_report._render_qweb_pdf(action_report.report_name, filtered_gift_cards.mapped('id'))
|
||||
filename = name + '.pdf'
|
||||
gift_card_pdf = self.env['ir.attachment'].create({
|
||||
'name': filename,
|
||||
'type': 'binary',
|
||||
'datas': base64.b64encode(report[0]),
|
||||
'store_fname': filename,
|
||||
'res_model': 'pos.order',
|
||||
'res_id': self.ids[0],
|
||||
'mimetype': 'application/x-pdf'
|
||||
})
|
||||
attachment += [(4, gift_card_pdf.id)]
|
||||
|
||||
return attachment
|
||||
|
||||
@@ -148,7 +148,7 @@ export const PosLoyaltyPaymentScreen = (PaymentScreen) =>
|
||||
}
|
||||
if (payload.coupon_report) {
|
||||
for (const report_entry of Object.entries(payload.coupon_report)) {
|
||||
this.env.legacyActionManager.do_action(report_entry[0], {
|
||||
await this.env.legacyActionManager.do_action(report_entry[0], {
|
||||
additional_context: {
|
||||
active_ids: report_entry[1],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user