-
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.
- Loading branch information
Showing
4 changed files
with
92 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2024 Akretion | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = 'sale.order.line' | ||
|
||
note = fields.Char() | ||
|
||
|
||
class ShopinvaderApiCartRouterHelper(models.AbstractModel): | ||
_inherit = "shopinvader_api_cart.cart_router.helper" | ||
|
||
@api.model | ||
def _prepare_line_from_transactions(self, cart, transactions): | ||
vals = super()._prepare_line_from_transactions(cart, transactions) | ||
# if the qty delta (add and remove of a product) is 0 then the vals is None | ||
if vals: | ||
options = transactions[0].options | ||
if options and options.note: | ||
vals["note"] = options.note | ||
return vals |
66 changes: 66 additions & 0 deletions
66
shopinvader_api_cart/tests/test_shopinvader_api_cart_option.py
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import json | ||
import random | ||
|
||
from odoo_test_helper import FakeModelLoader | ||
|
||
|
||
from ..routers.cart import cart_router | ||
|
||
from .common import CommonSaleCart | ||
from odoo.addons.shopinvader_schema_sale.schemas import sale_line_option | ||
|
||
from odoo import api, models | ||
|
||
NUMBER = range(1, 3) | ||
|
||
|
||
class SaleLineOption(sale_line_option.SaleLineOption, extends=True): | ||
note: str | None = None | ||
|
||
@classmethod | ||
def _prepare_from_sale_order_line(cls, line): | ||
vals = super()._prepare_from_sale_order_line(line) | ||
if hasattr(line, "note") and line.note: | ||
vals["note"] = line.note | ||
return vals | ||
|
||
|
||
class TestSaleCartOption(CommonSaleCart): | ||
@classmethod | ||
def setUpClass(cls): | ||
super(TestSaleCartOption, cls).setUpClass() | ||
cls.loader = FakeModelLoader(cls.env, cls.__module__) | ||
cls.loader.backup_registry() | ||
from .fake_model import ShopinvaderApiCartRouterHelper | ||
from .fake_model import SaleOrderLine | ||
cls.loader.update_registry((SaleOrderLine,)) | ||
# cls.loader.update_registry((SaleOrderLine, ShopinvaderApiCartRouterHelper)) | ||
cls.loader.update_registry((ShopinvaderApiCartRouterHelper,)) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.loader.restore_registry() | ||
super(TestSaleCartOption, cls).tearDownClass() | ||
|
||
def test_transactions(self) -> None: | ||
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, | ||
"options": {"note": str(random.Random(NUMBER))}, | ||
} | ||
] | ||
} | ||
with self._create_test_client(router=cart_router) as test_client: | ||
test_client.post(f"/{so.uuid}/sync", content=json.dumps(data)) | ||
line = so.order_line | ||
self.assertEqual(1, line.product_uom_qty) | ||
self.assertIn(line.note, ("1", "2"), "Note field should be 1 or 2") |
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