-
Notifications
You must be signed in to change notification settings - Fork 30.1k
[IMP] website_sale*: move stock check at checkout #192183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lipiraux
wants to merge
2
commits into
odoo:master
Choose a base branch
from
odoo-dev:master-stock-check-at-checkout-lipi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import main | ||
from . import payment | ||
from . import sale |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo.fields import Command | ||
from odoo.tests import HttpCase, tagged | ||
|
||
from odoo.addons.website_event_sale.tests.common import TestWebsiteEventSaleCommon | ||
from odoo.addons.website_sale.controllers.main import WebsiteSale as CheckoutController | ||
from odoo.addons.website_sale.tests.common import MockRequest | ||
|
||
|
||
@tagged('post_install', '-at_install') | ||
class TestEventCheckout(TestWebsiteEventSaleCommon, HttpCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.CheckoutController = CheckoutController() | ||
|
||
def test_checkout_impossible_if_tickets_are_expired(self): | ||
self.ticket.write({ | ||
'seats_max': 1, | ||
'seats_limited': True, | ||
}) | ||
|
||
so1 = self._create_so(order_line=[Command.create({ | ||
'product_id': self.ticket.product_id.id, | ||
'event_id': self.event.id, | ||
'event_ticket_id': self.ticket.id, | ||
})]) | ||
so2 = self._create_so(order_line=[Command.create({ | ||
'product_id': self.ticket.product_id.id, | ||
'event_id': self.event.id, | ||
'event_ticket_id': self.ticket.id, | ||
})]) | ||
self.env['event.registration'].create([ | ||
{ | ||
'state': 'draft', | ||
'sale_order_id': so1.id, | ||
'partner_id': so1.partner_id.id, | ||
'event_id': self.event.id, | ||
'event_ticket_id': self.ticket.id, | ||
}, | ||
]) | ||
|
||
so2.action_confirm() | ||
self.assertEqual(self.event.seats_available, 0) | ||
self.assertEqual(self.event.seats_taken, 1) | ||
|
||
website = self.website.with_user(self.public_user) | ||
with MockRequest(website.env, website=website, path='/shop/checkout', sale_order_id=so1.id): | ||
response = self.CheckoutController.shop_checkout() | ||
|
||
# SO2 was too quick and registered before SO1 => redirected to change tickets | ||
self.assertEqual(response.status_code, 303, 'SEE OTHER') | ||
self.assertURLEqual(response.location, '/shop/cart') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ def cart(self, id=None, access_token=None, revive_method='', **post): | |
|
||
values.update({ | ||
'website_sale_order': order_sudo, | ||
'order': order_sudo, | ||
'shop_warnings': order_sudo._pop_shop_warnings(), | ||
'date': fields.Date.today(), | ||
'suggested_products': [], | ||
}) | ||
|
@@ -223,31 +225,7 @@ def add_to_cart( | |
) | ||
def quick_add(self, product_template_id, product_id, quantity=1.0, **kwargs): | ||
values = self.add_to_cart(product_template_id, product_id, quantity=quantity, **kwargs) | ||
|
||
IrUiView = request.env['ir.ui.view'] | ||
order_sudo = request.cart | ||
values['website_sale.cart_lines'] = IrUiView._render_template( | ||
'website_sale.cart_lines', { | ||
'website_sale_order': order_sudo, | ||
'date': fields.Date.today(), | ||
'suggested_products': order_sudo._cart_accessories(), | ||
} | ||
) | ||
values['website_sale.shorter_cart_summary'] = IrUiView._render_template( | ||
'website_sale.shorter_cart_summary', { | ||
'website_sale_order': order_sudo, | ||
'show_shorter_cart_summary': True, | ||
**self._get_express_shop_payment_values(order_sudo), | ||
**request.website._get_checkout_step_values(), | ||
} | ||
) | ||
values['website_sale.quick_reorder_history'] = IrUiView._render_template( | ||
'website_sale.quick_reorder_history', { | ||
'website_sale_order': order_sudo, | ||
**self._prepare_order_history(), | ||
} | ||
) | ||
values['cart_ready'] = order_sudo._is_cart_ready() | ||
values.update(self._get_cart_update_values(request.cart)) | ||
return values | ||
|
||
def _get_express_shop_payment_values(self, order, **kwargs): | ||
|
@@ -298,7 +276,6 @@ def update_cart(self, line_id, quantity, product_id=None, **kwargs): | |
""" | ||
order_sudo = request.cart | ||
quantity = int(quantity) # Do not allow float values in ecommerce by default | ||
IrUiView = request.env['ir.ui.view'] | ||
|
||
# This method must be only called from the cart page BUT in some advanced logic | ||
# eg. website_sale_loyalty, a cart line could be a temporary record without id. | ||
|
@@ -309,34 +286,43 @@ def update_cart(self, line_id, quantity, product_id=None, **kwargs): | |
)[:1].id | ||
|
||
values = order_sudo._cart_update_line_quantity(line_id, quantity, **kwargs) | ||
values.update(self._get_cart_update_values(order_sudo)) | ||
return values | ||
|
||
def _get_cart_update_values(self, order_sudo): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method name seems kinda confusing to me, sounds like the values you provide to a method call, not the values you get as feedback from the request. |
||
"""Construct the values needed to update the UI after a cart update. | ||
|
||
:param sale.order order_sudo: The current cart order. | ||
:rtype: dict | ||
""" | ||
IrUiView = request.env['ir.ui.view'] | ||
|
||
values['cart_quantity'] = order_sudo.cart_quantity | ||
values['cart_ready'] = order_sudo._is_cart_ready() | ||
values['amount'] = order_sudo.amount_total | ||
values['minor_amount'] = ( | ||
order_sudo and payment_utils.to_minor_currency_units( | ||
return { | ||
'cart_quantity': order_sudo.cart_quantity, | ||
'cart_ready': order_sudo._is_cart_ready_for_checkout(), | ||
'amount': order_sudo.amount_total, | ||
'minor_amount': payment_utils.to_minor_currency_units( | ||
order_sudo.amount_total, order_sudo.currency_id | ||
) | ||
) or 0.0 | ||
values['website_sale.cart_lines'] = IrUiView._render_template( | ||
'website_sale.cart_lines', { | ||
'website_sale_order': order_sudo, | ||
'date': fields.Date.today(), | ||
'suggested_products': order_sudo._cart_accessories() | ||
} | ||
) | ||
values['website_sale.total'] = IrUiView._render_template( | ||
'website_sale.total', { | ||
'website_sale_order': order_sudo, | ||
} | ||
) | ||
values['website_sale.quick_reorder_history'] = IrUiView._render_template( | ||
'website_sale.quick_reorder_history', { | ||
'website_sale_order': order_sudo, | ||
**self._prepare_order_history(), | ||
} | ||
) | ||
return values | ||
), | ||
'website_sale.cart_lines': IrUiView._render_template( | ||
'website_sale.cart_lines', { | ||
'website_sale_order': order_sudo, | ||
'date': fields.Date.today(), | ||
'suggested_products': order_sudo._cart_accessories(), | ||
'order': order_sudo, | ||
'shop_warnings': order_sudo._pop_shop_warnings(), | ||
} | ||
), | ||
'website_sale.total': IrUiView._render_template( | ||
'website_sale.total', {'website_sale_order': order_sudo} | ||
), | ||
'website_sale.quick_reorder_history': IrUiView._render_template( | ||
'website_sale.quick_reorder_history', { | ||
'website_sale_order': order_sudo, | ||
**self._prepare_order_history(), | ||
} | ||
), | ||
} | ||
|
||
def _prepare_order_history(self): | ||
"""Prepare the order history of the current user. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.