[IMP] sale_coupon: refactor the coupon stages and usability improvement
Fix the layout of logo to the printed coupon. The traceability of the coupons is not clear. for Ex. coupon is send or not? should I resend? so updated the stages of the coupon Now the stages will be like -pending(previously reserved) -- hidden by default -Valid -Sent : updated when mail is sent to customer -used -expired -cancelled : hidden by default(added button to cancel the new coupon) Cron added to expire coupon automatically. PS: model sale.coupon do not inherit the thread so instead of message_post change the state 'sent' from mail_compose_message. Task-ID: 2027296 Closes #34620
This commit is contained in:
@@ -101,5 +101,17 @@
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="user_signature" eval="False"/>
|
||||
</record>
|
||||
|
||||
<record id="expire_coupon_cron" model="ir.cron">
|
||||
<field name="name">Coupon: expire coupon based on date</field>
|
||||
<field name="model_id" ref="sale_coupon.model_sale_coupon"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model.cron_expire_coupon()</field>
|
||||
<field name="active" eval="True"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="numbercall">-1</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import mail_compose_message
|
||||
from . import sale_coupon
|
||||
from . import sale_coupon_reward
|
||||
from . import sale_coupon_rules
|
||||
|
||||
@@ -27,16 +27,18 @@ class SaleCoupon(models.Model):
|
||||
code = fields.Char(default=_generate_code, required=True, readonly=True)
|
||||
expiration_date = fields.Date('Expiration Date', compute='_compute_expiration_date')
|
||||
state = fields.Selection([
|
||||
('reserved', 'Reserved'),
|
||||
('reserved', 'Pending'),
|
||||
('new', 'Valid'),
|
||||
('used', 'Consumed'),
|
||||
('expired', 'Expired')
|
||||
], required=True, default='new')
|
||||
('sent', 'Sent'),
|
||||
('used', 'Used'),
|
||||
('expired', 'Expired'),
|
||||
('cancel', 'Cancelled')
|
||||
], required=True, default='new')
|
||||
partner_id = fields.Many2one('res.partner', "For Customer")
|
||||
program_id = fields.Many2one('sale.coupon.program', "Program")
|
||||
order_id = fields.Many2one('sale.order', 'Order Reference', readonly=True,
|
||||
help="The sales order from which coupon is generated")
|
||||
sales_order_id = fields.Many2one('sale.order', 'Applied on order', readonly=True,
|
||||
sales_order_id = fields.Many2one('sale.order', 'Used in', readonly=True,
|
||||
help="The sales order on which the coupon is applied")
|
||||
discount_line_product_id = fields.Many2one('product.product', related='program_id.discount_line_product_id', readonly=False,
|
||||
help='Product used in the sales order to apply the discount.')
|
||||
@@ -98,6 +100,8 @@ class SaleCoupon(models.Model):
|
||||
default_template_id=template.id,
|
||||
default_composition_mode='comment',
|
||||
custom_layout='mail.mail_notification_light',
|
||||
mark_coupon_as_sent=True,
|
||||
force_email=True,
|
||||
)
|
||||
return {
|
||||
'name': _('Compose Email'),
|
||||
@@ -109,3 +113,18 @@ class SaleCoupon(models.Model):
|
||||
'target': 'new',
|
||||
'context': ctx,
|
||||
}
|
||||
|
||||
def action_coupon_cancel(self):
|
||||
for coupon in self:
|
||||
coupon.state = 'cancel'
|
||||
|
||||
def cron_expire_coupon(self):
|
||||
self._cr.execute("""
|
||||
SELECT C.id FROM SALE_COUPON as C
|
||||
INNER JOIN SALE_COUPON_PROGRAM as P ON C.program_id = P.id
|
||||
WHERE C.STATE in ('reserved', 'new', 'sent')
|
||||
AND P.validity_duration > 0
|
||||
AND C.create_date + interval '1 day' * P.validity_duration < now()""")
|
||||
|
||||
expired_ids = [res[0] for res in self._cr.fetchall()]
|
||||
self.browse(expired_ids).write({'state': 'expired'})
|
||||
|
||||
@@ -30,8 +30,9 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Coupons" create="false" edit="false" delete="false">
|
||||
<header>
|
||||
<button name="action_coupon_sent" type="object" string="Send by Email" class="oe_highlight"/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="new,used,expired" context="{'state': state}"/>
|
||||
<button name="action_coupon_sent" type="object" string="Send by Email" class="oe_highlight" attrs="{'invisible': [('state', 'not in', ['new', 'sent'])]}"/>
|
||||
<button name="action_coupon_cancel" type="object" string="Cancel" class="oe_highlight" attrs="{'invisible': [('state', '!=', 'new')]}"/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="new,sent,used,expired" context="{'state': state}"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<group>
|
||||
|
||||
@@ -42,5 +42,5 @@ class SaleCouponGenerate(models.TransientModel):
|
||||
@api.depends('partners_domain')
|
||||
def _compute_has_partner_email(self):
|
||||
for record in self:
|
||||
domain = expression.AND([safe_eval(record.partners_domain), [('email', '=', False)]])
|
||||
domain = expression.AND([ast.literal_eval(record.partners_domain), [('email', '=', False)]])
|
||||
record.has_partner_email = self.env['res.partner'].search_count(domain) == 0
|
||||
|
||||
Reference in New Issue
Block a user