Skip to content

Commit

Permalink
[MIG] website_sale_coupon_selection_wizard: Migration to version 16.0
Browse files Browse the repository at this point in the history
TT44379
  • Loading branch information
pilarvargas-tecnativa committed Mar 5, 2024
1 parent d11817a commit ee0072c
Show file tree
Hide file tree
Showing 11 changed files with 767 additions and 89 deletions.
12 changes: 6 additions & 6 deletions website_sale_coupon_selection_wizard/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Coupons Selection for eCommerce
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:94c44400c8e0661ca641d2c4de75be1950d9d1107237aa4189128911a9d1b019
!! source digest: sha256:5ae4b00d3be0d04188df62de844bc842cee755c9114dbb25cd4642db1f308fae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Coupons Selection for eCommerce
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github
:target: https://github.com/OCA/sale-promotion/tree/15.0/website_sale_coupon_selection_wizard
:target: https://github.com/OCA/sale-promotion/tree/16.0/website_sale_coupon_selection_wizard
:alt: OCA/sale-promotion
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-promotion-15-0/sale-promotion-15-0-website_sale_coupon_selection_wizard
:target: https://translation.odoo-community.org/projects/sale-promotion-16-0/sale-promotion-16-0-website_sale_coupon_selection_wizard
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -64,7 +64,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-promotion/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-promotion/issues/new?body=module:%20website_sale_coupon_selection_wizard%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-promotion/issues/new?body=module:%20website_sale_coupon_selection_wizard%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -104,6 +104,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-chienandalu|

This module is part of the `OCA/sale-promotion <https://github.com/OCA/sale-promotion/tree/15.0/website_sale_coupon_selection_wizard>`_ project on GitHub.
This module is part of the `OCA/sale-promotion <https://github.com/OCA/sale-promotion/tree/16.0/website_sale_coupon_selection_wizard>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
18 changes: 9 additions & 9 deletions website_sale_coupon_selection_wizard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
{
"name": "Coupons Selection for eCommerce",
"summary": "Allows to apply and configure promotions directly from the website",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "eCommerce",
"website": "https://github.com/OCA/sale-promotion",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["chienandalu"],
"license": "AGPL-3",
"depends": [
"sale_coupon_selection_wizard",
"sale_coupon_order_suggestion",
"website_sale_coupon_page",
"sale_loyalty",
"sale_loyalty_order_suggestion",
"website_sale_loyalty_page",
],
"data": ["templates/promotion_templates.xml"],
"data": ["templates/promotion_templates.xml", "templates/templates.xml"],
"assets": {
"web.assets_frontend": [
"/website_sale_coupon_selection_wizard/static/src/scss/"
"website_sale_coupon_selection.scss",
"/sale_coupon_selection_wizard/static/src/js/"
"coupon_selection_wizard_mixin.js",
"/website_sale_coupon_selection_wizard/static/src/js/"
"website_sale_coupon_selection_wizard.js",
"/website_sale_coupon_selection_wizard/static/src/js/*",
# "coupon_selection_wizard_mixin.js",
# "/website_sale_coupon_selection_wizard/static/src/js/"
# "website_sale_coupon_selection_wizard.js",
]
},
}
12 changes: 4 additions & 8 deletions website_sale_coupon_selection_wizard/controllers/coupon_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.http import request, route

from odoo.addons.website_sale_coupon_page.controllers.main import WebsiteSale
from odoo.addons.website_sale_loyalty_page.controllers.main import WebsiteSale


class CouponPage(WebsiteSale):
@route()
def promotion(self, **post):
"""Rules to render the 'Apply promotion' button"""
response = super().promotion(**post)
# import wdb; wdb.set_trace()
order = request.website.sale_get_order(force_create=True)
if not order:
return response

Check warning on line 16 in website_sale_coupon_selection_wizard/controllers/coupon_page.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/coupon_page.py#L16

Added line #L16 was not covered by tests
promo_values = response.qcontext.get("promos", [])
for promo_dict in promo_values:
promo_dict["applicable"] = False
promo = request.env["coupon.program"].sudo().browse(promo_dict["id"])
if (
promo in (order.no_code_promo_program_ids | order.code_promo_program_id)
) or (
promo
not in order.sudo()._available_multi_criteria_multi_gift_programs()
):
promo = request.env["loyalty.program"].sudo().browse(promo_dict["id"])
if promo not in order.sudo()._get_available_programs():
continue
promo_dict["applicable"] = True

Check warning on line 23 in website_sale_coupon_selection_wizard/controllers/coupon_page.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/coupon_page.py#L23

Added line #L23 was not covered by tests
return response
48 changes: 25 additions & 23 deletions website_sale_coupon_selection_wizard/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class WebsiteSaleCouponWizard(WebsiteSale):
["/promotions/<int:program_id>/apply"], type="http", auth="public", website=True
)
def promotion_program_apply(self, program_id, **kwargs):
program = request.env["coupon.program"].sudo().browse(program_id).exists()
# import wdb; wdb.set_trace()
program = request.env["loyalty.program"].sudo().browse(program_id).exists()

Check warning on line 14 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L14

Added line #L14 was not covered by tests
if not program or not program.active or not program.is_published:
return

Check warning on line 16 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L16

Added line #L16 was not covered by tests
# Prevent to apply a promotion to a processed order
Expand All @@ -19,42 +20,43 @@ def promotion_program_apply(self, program_id, **kwargs):
request.session["sale_order_id"] = None
order = request.website.sale_get_order()

Check warning on line 21 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L20-L21

Added lines #L20 - L21 were not covered by tests
# We won't apply it twice
if program in (order.no_code_promo_program_ids | order.code_promo_program_id):
if program in order._get_reward_programs():
return

Check warning on line 24 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L24

Added line #L24 was not covered by tests
# If the promotion is directly applicable (promotion code), just apply without
# further ado.
if program.promo_code_usage == "code_needed" and (
program not in order.sudo()._available_multi_criteria_multi_gift_programs()
if program.program_type == "promo_code" and (
program not in order.sudo()._get_available_programs()
):
return self.pricelist(program.promo_code)
code = program.rule_ids.filtered(lambda x: x.code != " ")[:1]
return self.pricelist(code)

Check warning on line 31 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L31

Added line #L31 was not covered by tests
# Let's inject some context into the view
request.session["promotion_id"] = program.id
return request.redirect("/shop/cart")

Check warning on line 34 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L33-L34

Added lines #L33 - L34 were not covered by tests

@route()
def pricelist(self, promo, **post):
"""When applying a configurable promotion code, we'll offer the customer
to configure it."""
if promo:
order = request.website.sale_get_order()
program = (
request.env["coupon.program"]
.sudo()
.search([("promo_code", "=", promo)])
)
if program in order.sudo()._available_multi_criteria_multi_gift_programs():
request.session["promotion_id"] = program.id
return request.redirect("/shop/cart")
return super().pricelist(promo)
# @route()
# def pricelist(self, promo, **post):
# """When applying a configurable promotion code, we'll offer the customer
# to configure it."""
# if promo:
# order = request.website.sale_get_order()
# program = (
# request.env["loyalty.program"]
# .sudo()
# .search([("promo_code", "=", promo)])
# )
# if program in order.sudo()._available_multi_criteria_multi_gift_programs():
# request.session["promotion_id"] = program.id
# return request.redirect("/shop/cart")
# return super().pricelist(promo)

@route()
def cart(self, **post):
response = super().cart(**post)

Check warning on line 54 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L54

Added line #L54 was not covered by tests
# import wdb; wdb.set_trace()
promotion = request.session.get("promotion_id")

Check warning on line 56 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L56

Added line #L56 was not covered by tests
if promotion:
response.qcontext["promotion_id"] = (
request.env["coupon.program"].sudo().browse(promotion)
)
program_id = request.env["loyalty.program"].browse(promotion)
response.qcontext["promotion_id"] = program_id
return response

Check warning on line 60 in website_sale_coupon_selection_wizard/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/main.py#L58-L60

Added lines #L58 - L60 were not covered by tests

@route(["/promotions/dismiss"], type="http", auth="public", website=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from odoo import _
from odoo.http import request, route

from odoo.addons.sale_coupon_selection_wizard.controllers.main import (
CouponSelectionWizardController,
)
from odoo.addons.website_sale_loyalty.controllers.main import WebsiteSale


class CouponSelectionWizardController(CouponSelectionWizardController):
class CouponSelectionWizardController(WebsiteSale):
@route(
"/website_sale_coupon_selection_wizard/apply",
type="json",
Expand Down Expand Up @@ -38,5 +36,6 @@ def apply_promotion_public(
@route(website=True)
def configure_promotion(self, program_id, **kw):
if not self._get_order(kw.get("sale_order_id")):
# import wdb; wdb.set_trace()
kw["sale_order_id"] = request.website.sale_get_order(force_create=True)
return super().configure_promotion(program_id, **kw)

Check warning on line 41 in website_sale_coupon_selection_wizard/controllers/promotion_wizard.py

View check run for this annotation

Codecov / codecov/patch

website_sale_coupon_selection_wizard/controllers/promotion_wizard.py#L40-L41

Added lines #L40 - L41 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">Coupons Selection for eCommerce</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:94c44400c8e0661ca641d2c4de75be1950d9d1107237aa4189128911a9d1b019
!! source digest: sha256:5ae4b00d3be0d04188df62de844bc842cee755c9114dbb25cd4642db1f308fae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-promotion/tree/15.0/website_sale_coupon_selection_wizard"><img alt="OCA/sale-promotion" src="https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-promotion-15-0/sale-promotion-15-0-website_sale_coupon_selection_wizard"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-promotion/tree/16.0/website_sale_coupon_selection_wizard"><img alt="OCA/sale-promotion" src="https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-promotion-16-0/sale-promotion-16-0-website_sale_coupon_selection_wizard"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to apply multi-gift mult-criteria promotion with a fancy wizard on
the eCommerce.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -411,7 +411,7 @@ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-promotion/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/sale-promotion/issues/new?body=module:%20website_sale_coupon_selection_wizard%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/sale-promotion/issues/new?body=module:%20website_sale_coupon_selection_wizard%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -440,7 +440,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/chienandalu"><img alt="chienandalu" src="https://github.com/chienandalu.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-promotion/tree/15.0/website_sale_coupon_selection_wizard">OCA/sale-promotion</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-promotion/tree/16.0/website_sale_coupon_selection_wizard">OCA/sale-promotion</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Loading

0 comments on commit ee0072c

Please sign in to comment.