-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by simahawk
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,3 +1,4 @@ | ||
* Laurent Mignon <[email protected]> | ||
* Stéphane Bidoul <[email protected]> | ||
* Marie Lejeune <[email protected]> | ||
* Simone Orsi <[email protected]> |
This file contains 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,4 +1,6 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# Copyright 2024 Camptocamp (http://www.camptocamp.com). | ||
# @author Simone Orsi <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from collections import OrderedDict | ||
from typing import Annotated | ||
|
@@ -56,6 +58,22 @@ def sync( | |
return Sale.from_sale_order(cart) if cart else Response(status_code=204) | ||
|
||
|
||
@cart_router.post("/new", status_code=201) | ||
def new( | ||
data: CartSyncInput, | ||
env: Annotated[api.Environment, Depends(authenticated_partner_env)], | ||
partner: Annotated["ResPartner", Depends(authenticated_partner)], | ||
) -> Sale | None: | ||
"""Create a new cart on demand. | ||
You can use this endpoint to create multiple carts for the same customer. | ||
""" | ||
cart = env["shopinvader_api_cart.cart_router.helper"]._sync_cart( | ||
partner, None, None, data.transactions | ||
) | ||
return Sale.from_sale_order(cart) if cart else Response(status_code=204) | ||
|
||
|
||
@cart_router.post("/update/{uuid}", deprecated=True) | ||
@cart_router.post("/{uuid}/update") | ||
@cart_router.post("/current/update") | ||
|
This file contains 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,4 +1,6 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# Copyright 2024 Camptocamp (http://www.camptocamp.com). | ||
# @author Simone Orsi <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import json | ||
|
@@ -7,6 +9,7 @@ | |
from requests import Response | ||
|
||
from odoo.exceptions import AccessError, MissingError | ||
from odoo.tests.common import RecordCapturer | ||
|
||
from ..routers.cart import cart_router | ||
from ..schemas import CartTransaction | ||
|
@@ -517,3 +520,27 @@ def test_update_new_cart(self) -> None: | |
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
info = response.json() | ||
self.assertTrue(self.env["sale.order"].browse(info["id"]).exists()) | ||
|
||
def test_sync_new_cart(self) -> None: | ||
# A cart is already existing | ||
so = self.env["sale.order"]._create_empty_cart( | ||
self.default_fastapi_authenticated_partner.id | ||
) | ||
data = { | ||
"transactions": [ | ||
{"uuid": self.trans_uuid_1, "product_id": self.product_1.id, "qty": 1} | ||
] | ||
} | ||
with RecordCapturer( | ||
self.env["sale.order"], | ||
[("partner_id", "=", self.default_fastapi_authenticated_partner.id)], | ||
) as capt: | ||
for __ in range(1, 5): | ||
# Get 4 new carts | ||
with self._create_test_client(router=cart_router) as test_client: | ||
response: Response = test_client.post( | ||
"/new", content=json.dumps(data) | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertTrue(capt.records[-1].id > so.id) | ||
self.assertEqual(len(capt.records), 4) |