Commit Graph
16 Commits
Author SHA1 Message Date
Christophe Simonis dbb575179f [MERGE] forward port branch saas-11.4 up to 8faebd0cf52 2018-10-01 20:17:14 +02:00
Christophe Simonis a17ddde9a1 [MERGE] forward port branch 11.0 up to 1e8ab568c1f 2018-09-26 20:02:37 +02:00
Christophe Simonis 6b5aadc7ce [MERGE] forward port branch saas-15 up to c74e1ae51a8
closes odoo/enterprise#2707
2018-09-22 19:41:40 +00:00
Nimesh Jethva 5d45235549 [IMP]sale_*: Improvement in model description
Purpose of this commit is to give description more "business oriented"
because those descriptions appears in Odoo Studio which is supposed to be used by end users, not only by developers.

Related Task ID : 37311
2018-09-21 11:48:45 +02:00
Romain Derie 034fb31c40 [FIX] sale_coupon(_delivery): fix some flows (mostly on next order)
This commit is the continuity of a42c27f9 that fixed some bugs.
One of the bug was that a discount was only applied on price without taxes.
E.G: A $100 product with 20% excluded tax would cost $120 but a 50% discount
     would give the user only $50 discount and not $60 as expected.
     User would lose $10 discount.
With these fixes, the discount line would correctly be set to $60 but since the
discount line would not have tax, the merchant would lose the discount amount
on the tax, in this case 50% of $20.

This commit will improve this case by adding a tax on a discount line.
Thus, since a global discount can be applied to multiple products having
different taxes or even multiple taxes on the same product, a discount line
should be split for every product taxes the discount applies on.
Obviously, this is a big behavior change, even if the discount is now finally
correct: the discount is applied on the total price and the merchant does not
lose any taxes.

To make it more clear, the discount lines description will mention on which
taxes it is applied.

There won't be any changes in the e-commerce since we will group the discount
lines so it will appear as before even if there are multiple lines. This is
only possible because we don't show taxes on line on the e-commerce.

This commit also fixes more complex flows/use cases.
Note: Fixes & flows will be illustrated with a SO but the behavior is the
      same with a cart on front-end.

== Fixes ==
===========================================================================
The biggest flow that needed to be fixed is when a promotion program give a
reward on the next order.
Let's illustrate with a promotion program giving a free `product_B` on next
order (so it will generate a coupon) if the SO meets the requirements.
The requirements are: buy a `product_A` and buy for at least $600.
(This program needs a code: 'free_b_on_next')

1. If the SO has a `product_A` and over $600, applying the promotion code
   `free_b_on_next` will error saying that `product_B` is not in the cart.
   This error should not appear, since the `product_B` is the reward for
   the next sale order that will use the generated coupon.

Anyway, if you add `product_B` and apply the promotion code `free_b_on_next`
to generate the coupon to check the rest of the flow. It will generate the
coupon and send email to the customer.

2. Every time you will apply the promotion code `free_b_on_next`, it will
   regenerate a new coupon and resend a new email to the client.

Then, create a second SO, add 2 `product_B` and try to apply the generated
coupon from the first SO.

3. It will error saying that the $600 requirement is not met.
   It should not since the requirement was only required to generate the
   coupon on the first SO. User has now a coupon to enjoy a free `product_B`
   and should not buy $600.

Anyway, let's add some products to meet the 600$ requirement to check the rest
of the flow.

4. It will now error saying that `product_A` is not in the cart.
   As bug 3., it should not since this requirement was also required to
   generate the coupon on the first SO.

Anyway, let's add `product_A` to meet the requirement to check the rest of the
flow.

5. Updating the promotions will remove the reward and you won't be able to
   reapply the coupon since it was `used`.
   This bug was even more critical in front-end since any action on the cart
   will recompute the coupons and automatically delete the reward after adding
   it. The customer never saw the reward on his cart.
   This bug is related to 3. and 4. Indeed, when recomputing coupons, it will
   remove programs that are not applicable anymore. The code wrongly think it is
   the case with this coupon since we don't have $600 or a `product_A`.
   `_remove_invalid_reward_lines` should treat coupon coming from a promotion
   program set on `next_order` differently and not filter on requirements.
===========================================================================

6. (extension of 2.) Every time an user would meet the requirements of a
   promotion program generating a coupon for a next order, it would generate a
   coupon and send an email.
   E.g: If buy 2 iPads get 1 for free on next order. If user add and remove iPad
        for some reason, every time he has 2 iPads in his cart it will receive
        an email with a new coupon.

6'. When applying a promotion code that will reward next order, it will not be
    set in the SO `code_promo_program_id` (I did not change that behavior since
    it could make sense to be able to apply another coupon that will give -20%
    on current order).
    This will allow applying multiple promotion rewarding a next order and/or a
    promotion rewarding current order. (Which would not be possible if was
    stored on `code_promo_program_id` since you can only apply one code on an
    order)
    But this cause a bug: since the promotion program is not stored on the order,
    every time you will apply the coupon it will generate a new coupon and send
    an email.
    So if you work on a draft sale order and do some tests, it will send many
    emails to customer..

7. Having multiple global discounts (on the whole SO) was forbidden: you can't
   apply a coupon promotion or a program promotion if there is already a global
   coupon discount or a global promotion discount with code. But still you could
   apply a global discount if there were a global promotion discount automatically
   applied (without a code).

8. On the generate coupon wizard, if you select `Number of Selected Customers`,
   by default it is set to 'Match all records (X records)'.
   But when you click on generate, it won't generate anything even if visually
   it selected every partner by default.
   This is because the domain default value is an empty string. Thus, the domain
   widget is selecting everything but once it is sent back to the server, since
   it's an empty string it won't get through the `if` condition.
   It was even weirder when you add something to the domain and remove it, you
   then visually come back to where you were at the beginning but the domain got
   changed from '' to '[]' so in this case it will generate the coupon for every
   partner.

== More like improvements ==

1. `action_cancel` and `action_confirm` would handle correctly the states of the
   applied and generated coupons (valid, consumed, expired..).
   But `action_draft` would not handle the states at all.

2. The generated coupon on a SO are now sent by email only when the SO is validated.
   This is part of the fix n°2 on coupon being generated multiple times and sent by
   email multiple times.
   The coupon sent by email was not usable anyway since it would error saying the
   SO that generated the coupon was not validated.

3. Discount line limited to a max amount (set in the program) will mention on
   the line description that the discount is limited.
   This will avoid cases where you don't understand why 50% discount of $2000
   SO shows $40.

4. If you archive a program and there is still some SO containing this program's
   reward line, these line will be 'floating free' and will never be updated or
   removed. Indeed, the `_remove_invalid_reward_lines` is basically checking
   which programs could be applied on the order and which one are applied on the
   order. If a program is applied on the order but is not supposed to, his
   reward line will be removed.
   Of course, since the program got archived, it won't get retrieve and the line
   will never get removed. Even if the case of a free iPad: if you buy an iPad
   and you removed the paid iPad from the SO. The free iPad will remain forever.
   Note: We can't remove these discount line directly when archiving a program
         because there might be quotations that we don't want to modify since it
         is waiting for customer confirmation.

Improved behavior:
  - Archiving a program archives its related reward product but unarchiving
    the program does not unarchived the product.

task-1866977

opw-1832967
opw-1857843

Closes #2224
Comes with https://github.com/odoo/odoo/pull/24971
2018-09-13 15:16:57 +02:00
Yannick Tivisse bb5a631262 [FIX] sale_coupon: Display the text in mails from generated coupons
Purpose
=======

The text displayed in mails for generated coupons sent to customers is not displayed anymore.
2017-12-28 11:01:42 +01:00
Sagar Ahirrao 96fed80454 [IMP] sale_coupon: Allow to print and send coupons by email
Purpose
=======

A feature was not done when doing the coupon task because of the lack of time : Coupon should be printed from the system and same can be sent to customer via email(attractive email template).

Specification
=============

Ass the possibility to:

- Print coupon
- Send coupon by email with the printed report in attachment
- Generated coupon by sending to the customers the coupon in attachments
2017-12-01 13:04:30 +01:00
Christophe Simonis 7ccd861698 [MERGE] forward port branch saas-16 up to b81f9d89876 2017-11-16 12:41:31 +01:00
Christophe Simonis 1b1dd22d1b [MERGE] forward port branch saas-15 up to e9575185a57 2017-11-15 17:56:16 +01:00
Romain Derie 16531f6548 [FIX] (website_)sale_coupon: Display clearer promo code error on cart
Before this commit:
Coupon error on cart would always show "Invalid or Expired coupon code"
instead of a more accurate error (eg: already applied, can't use 2 code..).
Plus it would still show the error on page refresh because of the error being
stored in URL param.

Now:
It will show the exact error and since the error is not stored in URL, it won't
be still displayed on page refresh.

This closes #1601
2017-11-15 12:34:57 +01:00
Yannick Tivisse 29a5de310e [FIX] sale_coupon: Remove old and buggy compute field (not stored)
Purpose
=======

Click on Generate Coupon gives traceback

Steps to reproduce issue :
>> install coupon.
>> total number of customers are more than 40.
>> debugger mode off.
>> now click on generate the coupon.

Specification
=============

Before the new char domain widget, we were forced to couple the domain Char field with a many2many computed field to display the partners.

Now it's not useful, and this is leading to a traceback if the records count is greater than 40.
2017-09-21 16:11:32 +02:00
Yannick Tivisse ce8b35ee1d [FIX] sale_coupon: Set a valid default value 2017-09-19 14:27:26 +02:00
Pratima Gupta 6d342b79d0 [FIX] sale_coupon: Add default value to char domain field
Otherwise the required field is not validated at wizard validation
2017-07-17 12:54:57 +02:00
xmo-odoo c3ad67cef2 [FIX] implicitly relative imports 2017-04-28 09:07:28 +02:00
qsm-odoo 77de506712 [IMP] sale_coupon, website_crm_score: adapt to new domain widget
Since commit https://github.com/odoo/odoo/commit/e3f99885ca789b338a4cb9ab9a154db50dff500d,
the FieldCharDomain was replaced by the FieldDomain and these form
definitions had to be adapted.
2017-01-03 18:44:20 +01:00
pgu-odoo 5260d22c4d [ADD] sale_coupon: introduce coupon mechanism on sales order
Introduces 2 new concepts:

Promotion programs:
===================

Using promotion programs allows you to propose to your customers:
- Promotional offers limited in time or a limited order number.
- Public code printed in advertisements, magasines, etc.
- Specific offers based on a customers group or a product set.
- A combination of the preceeding points.

You may choose to apply the program reward immediately on the sales order or to propose the reward for a next order. In the second case a coupon will be generated at the order confirmation for the customer to use it later.

Coupon programs:
================

Using coupon programs allows you to propose to your customers:
- Free products or discounts if some conditions on products or purchased amount are met.
- Promotional offers limited in time.
- Generate coupons for a customers group.
- Specific offers based on a customers group or a product set.
- A combination of the preceeding points.

A coupon is applied by entering a valid code if the program rules are met and if the reward is already in the order lines.
2016-12-20 14:46:00 +01:00