Skip to content

Commit

Permalink
Add shopinvader_api_cart_step
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Mar 25, 2024
1 parent 55d43c6 commit a7aba11
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/shopinvader_api_cart_step/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions shopinvader_api_cart_step/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bot pls :)
2 changes: 2 additions & 0 deletions shopinvader_api_cart_step/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import schemas
from . import helpers
14 changes: 14 additions & 0 deletions shopinvader_api_cart_step/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Cart steps cart API integration",
"summary": """
Track checkout steps on sale cart.
""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Camptocamp",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"depends": ["sale_cart_step", "shopinvader_api_cart"],
}
1 change: 1 addition & 0 deletions shopinvader_api_cart_step/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import cart_helper
20 changes: 20 additions & 0 deletions shopinvader_api_cart_step/helpers/cart_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class ShopinvaderApiCartRouterHelper(models.AbstractModel):
_inherit = "shopinvader_api_cart.cart_router.helper"

def _update_prepare_data(self, data):
vals = super()._update_prepare_data(data)
if data.current_step or data.next_step:
vals.update(self._update_prepare_data_step(data))
return vals

def _update_prepare_data_step(self, data):
return self.env["sale.order"]._cart_step_update_vals(
current_step=data.current_step, next_step=data.next_step
)
1 change: 1 addition & 0 deletions shopinvader_api_cart_step/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Simone Orsi <[email protected]>
1 change: 1 addition & 0 deletions shopinvader_api_cart_step/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Plugs ``sale_cart_step`` within cart api.
1 change: 1 addition & 0 deletions shopinvader_api_cart_step/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import cart
18 changes: 18 additions & 0 deletions shopinvader_api_cart_step/schemas/cart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2024 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.addons.shopinvader_api_cart.schemas import (
CartUpdateInput as BaseCartUpdateInput,
)


class CartUpdateInput(BaseCartUpdateInput, extends=True):

current_step: str | None = None
next_step: str | None = None

def convert_to_sale_write(self):
vals = super().convert_to_sale_write()
# NOTE: is not possible to use `env` to retrive data here
return vals
1 change: 1 addition & 0 deletions shopinvader_api_cart_step/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_api_cart_step
48 changes: 48 additions & 0 deletions shopinvader_api_cart_step/tests/test_api_cart_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2024 Camptocamp SA
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import json

from fastapi import status
from requests import Response

from odoo.addons.shopinvader_api_cart.routers.cart import cart_router
from odoo.addons.shopinvader_api_cart.tests.common import CommonSaleCart


class TestSaleCart(CommonSaleCart):
@classmethod
def setUpClass(cls):
super(TestSaleCart, cls).setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.address_step = cls.env.ref("sale_cart_step.cart_step_address")
cls.checkout_step = cls.env.ref("sale_cart_step.cart_step_checkout")
cls.last_step = cls.env.ref("sale_cart_step.cart_step_last")

def test_update(self):
so = self.env["sale.order"]._create_empty_cart(
self.default_fastapi_authenticated_partner.id
)
data = {
"current_step": self.address_step.code,
"next_step": self.checkout_step.code,
}
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.post(
f"/{so.uuid}/update", content=json.dumps(data)
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn(self.address_step, so.cart_step_done_ids)
self.assertEqual(so.cart_step_id, self.checkout_step)
data = {
"current_step": self.checkout_step.code,
"next_step": self.last_step.code,
}
with self._create_test_client(router=cart_router) as test_client:
response: Response = test_client.post(
f"/{so.uuid}/update", content=json.dumps(data)
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn(self.checkout_step, so.cart_step_done_ids)
self.assertEqual(so.cart_step_id, self.last_step)

0 comments on commit a7aba11

Please sign in to comment.