I am customizing the POS receipt in Odoo 19.
I want to add a savings/congratulations message at the bottom of the receipt like:
Congrats! You saved 70 on this purchase
The savings amount should be calculated as:
(MRP - List Price) × Quantity
Example:
- Product 1:
MRP = 150
List Price = 100
Qty = 1
Savings = 50 - Product 2:
MRP = 60
List Price = 50
Qty = 2
Savings = 20
Total savings = 70
I tried patching Orderline and now I am trying to extend OrderReceipt, but I am not sure how to properly access all receipt order lines and display the computed total in the QWeb receipt template.
What is the best approach to implement this in Odoo POS receipt?
Thanks in advance.
my code-
from odoo import api, models
class ProductProduct(models.Model):
_inherit = 'product.product'
@api.depends('name', 'mrp')
def _compute_display_name(self):
for product in self:
mrp = product.mrp or ''
name = product.name or ''
if mrp:
product.display_name = f"[{mrp}] {name}"
else:
product.display_name = name
def _load_pos_data_fields(self, config_id):
fields = super()._load_pos_data_fields(config_id)
fields.append('mrp')
return fields
/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import { OrderReceipt } from "@point_of_sale/app/screens/receipt_screen/receipt/order_receipt";
patch(OrderReceipt.prototype, {
get totalSavedAmount() {
const order = this.props.data;
let totalSaved = 0;
order.orderlines.forEach(line => {
const mrp = line.product_id?.mrp || 0;
const listPrice = line.product_id?.lst_price || 0;
const qty = line.qty || 1;
const diff = (mrp - listPrice) * qty;
totalSaved += diff;
});
return totalSaved;
},
});
/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import { Orderline } from "@point_of_sale/app/components/orderline/orderline";
patch(Orderline.prototype, {
get lineScreenValues() {
const res = super.lineScreenValues;
const line = this.line;
if (line?.order_id && this.props?.mode === "receipt" && line.price !== 0) {
const mrp = line.product_id?.mrp || 0;
const listPrice = line.product_id?.lst_price || 0;
const uomName = line.product_id?.uom_id?.name || "unit";
res.displayPriceUnit = `MRP: ${mrp} @ ${listPrice}/${uomName}`;
}
return res;
},
});
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<t t-name="odoometer_price_extn.OrderReceipt"
t-inherit="point_of_sale.OrderReceipt"
t-inherit-mode="extension">
<xpath expr="//div[contains(@class,'pos-receipt-order-data')]" position="after">
<t t-if="totalSavedAmount > 0">
<div style="text-align:center; margin-top:10px; font-weight:bold;">
Congrats! You saved
<t t-esc="totalSavedAmount"/>
on this purchase
</div>
</t>
</xpath>
</t>
</odoo>
Hello,
I'll let you know.
The code sent to your email. Please check.