# -*- coding: utf-8 -*- from odoo import models, fields, _ class PosConfig(models.Model): _inherit = 'pos.config' def use_coupon_code(self, code, creation_date, partner_id, pricelist_id): res = super().use_coupon_code(code, creation_date, partner_id, pricelist_id) if res.get('successful'): # Fetch the coupon to check custom_end_date coupon_id = res['payload'].get('coupon_id') if coupon_id: coupon = self.env['loyalty.card'].browse(coupon_id) check_date = fields.Date.from_string(creation_date[:11]) if coupon.custom_end_date and coupon.custom_end_date < check_date: return { 'successful': False, 'payload': { 'error_message': _("This coupon's custom end date is expired (%s).", code), }, } return res