diff options
| author | mgh-odoo <mgh@odoo.com> | 2019-06-28 09:07:44 +0000 |
|---|---|---|
| committer | Damien Bouvy <dbo@odoo.com> | 2020-01-31 12:46:17 +0000 |
| commit | bb87d3f674d593b68d2cceeff0403687f930d2b8 (patch) | |
| tree | a9ba0d0f850d62f26a0a0f070c14ee8b464ee1c4 | |
| parent | c2775164aba0fa6880571197733e9575555bc17e (diff) | |
[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
| -rw-r--r-- | addons/sale_coupon/data/sale_coupon_email_data.xml | 12 | ||||
| -rw-r--r-- | addons/sale_coupon/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/sale_coupon/models/sale_coupon.py | 29 | ||||
| -rw-r--r-- | addons/sale_coupon/views/sale_coupon_views.xml | 5 | ||||
| -rw-r--r-- | addons/sale_coupon/wizard/sale_coupon_generate.py | 2 |
5 files changed, 41 insertions, 8 deletions
diff --git a/addons/sale_coupon/data/sale_coupon_email_data.xml b/addons/sale_coupon/data/sale_coupon_email_data.xml index 9d385b9272c..6d09a51e62c 100644 --- a/addons/sale_coupon/data/sale_coupon_email_data.xml +++ b/addons/sale_coupon/data/sale_coupon_email_data.xml @@ -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>
\ No newline at end of file diff --git a/addons/sale_coupon/models/__init__.py b/addons/sale_coupon/models/__init__.py index 903f2686d6d..f9faf790d5c 100644 --- a/addons/sale_coupon/models/__init__.py +++ b/addons/sale_coupon/models/__init__.py @@ -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 diff --git a/addons/sale_coupon/models/sale_coupon.py b/addons/sale_coupon/models/sale_coupon.py index 4a0ae195bfc..686e697f624 100644 --- a/addons/sale_coupon/models/sale_coupon.py +++ b/addons/sale_coupon/models/sale_coupon.py @@ -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'}) diff --git a/addons/sale_coupon/views/sale_coupon_views.xml b/addons/sale_coupon/views/sale_coupon_views.xml index 2cc22c6f89b..6b7dc0e7cca 100644 --- a/addons/sale_coupon/views/sale_coupon_views.xml +++ b/addons/sale_coupon/views/sale_coupon_views.xml @@ -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> diff --git a/addons/sale_coupon/wizard/sale_coupon_generate.py b/addons/sale_coupon/wizard/sale_coupon_generate.py index cadf07e4016..08bdfffc4e1 100644 --- a/addons/sale_coupon/wizard/sale_coupon_generate.py +++ b/addons/sale_coupon/wizard/sale_coupon_generate.py @@ -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 |
