From 9073abf1591422ab407cd0399651222024df81ba Mon Sep 17 00:00:00 2001 From: "chafique.delli" Date: Tue, 30 Apr 2024 18:13:10 +0200 Subject: [PATCH] [16.0][MIG] shopinvader_delivery_pickup: Migration to 16.0 (FastAPI) --- setup/.setuptools-odoo-make-default-ignore | 2 + setup/README | 2 + .../addons/shopinvader_api_delivery_pickup | 1 + .../shopinvader_api_delivery_pickup/setup.py | 6 + shopinvader_api_delivery_pickup/README.rst | 81 ++++ shopinvader_api_delivery_pickup/__init__.py | 1 + .../__manifest__.py | 15 +- .../readme/CONTRIBUTORS.rst | 1 + .../readme/CREDITS.rst | 0 .../readme/DESCRIPTION.rst | 0 .../readme/ROADMAP.rst | 4 + .../routers/__init__.py | 2 + .../routers/cart.py | 84 ++++ .../routers/delivery_pickup.py | 68 +++ .../schemas/__init__.py | 7 + .../schemas/address.py | 14 + .../schemas/delivery_pickup.py | 78 ++++ .../schemas/resource_calendar_attendance.py | 26 ++ .../security/acl_delivery_pickup.xml | 19 + .../security/groups.xml | 16 + .../static/description/index.html | 436 ++++++++++++++++++ .../tests/__init__.py | 0 .../tests/common.py | 45 ++ .../tests/test_cart.py | 64 +++ .../tests/test_delivery_carrier.py | 42 ++ .../tests/test_delivery_pickup.py | 49 +- shopinvader_delivery_pickup/__init__.py | 1 - .../readme/ROADMAP.rst | 4 - .../services/__init__.py | 4 - .../services/abstract_sale.py | 20 - shopinvader_delivery_pickup/services/cart.py | 59 --- .../services/delivery_carrier.py | 23 - .../services/delivery_pickup.py | 163 ------- shopinvader_delivery_pickup/tests/common.py | 36 -- .../tests/test_cart.py | 43 -- .../tests/test_delivery_carrier.py | 38 -- 36 files changed, 1038 insertions(+), 416 deletions(-) create mode 100644 setup/.setuptools-odoo-make-default-ignore create mode 100644 setup/README create mode 120000 setup/shopinvader_api_delivery_pickup/odoo/addons/shopinvader_api_delivery_pickup create mode 100644 setup/shopinvader_api_delivery_pickup/setup.py create mode 100644 shopinvader_api_delivery_pickup/README.rst create mode 100644 shopinvader_api_delivery_pickup/__init__.py rename {shopinvader_delivery_pickup => shopinvader_api_delivery_pickup}/__manifest__.py (55%) rename {shopinvader_delivery_pickup => shopinvader_api_delivery_pickup}/readme/CONTRIBUTORS.rst (75%) rename {shopinvader_delivery_pickup => shopinvader_api_delivery_pickup}/readme/CREDITS.rst (100%) rename {shopinvader_delivery_pickup => shopinvader_api_delivery_pickup}/readme/DESCRIPTION.rst (100%) create mode 100644 shopinvader_api_delivery_pickup/readme/ROADMAP.rst create mode 100644 shopinvader_api_delivery_pickup/routers/__init__.py create mode 100644 shopinvader_api_delivery_pickup/routers/cart.py create mode 100644 shopinvader_api_delivery_pickup/routers/delivery_pickup.py create mode 100644 shopinvader_api_delivery_pickup/schemas/__init__.py create mode 100644 shopinvader_api_delivery_pickup/schemas/address.py create mode 100644 shopinvader_api_delivery_pickup/schemas/delivery_pickup.py create mode 100644 shopinvader_api_delivery_pickup/schemas/resource_calendar_attendance.py create mode 100644 shopinvader_api_delivery_pickup/security/acl_delivery_pickup.xml create mode 100644 shopinvader_api_delivery_pickup/security/groups.xml create mode 100644 shopinvader_api_delivery_pickup/static/description/index.html rename {shopinvader_delivery_pickup => shopinvader_api_delivery_pickup}/tests/__init__.py (100%) create mode 100644 shopinvader_api_delivery_pickup/tests/common.py create mode 100644 shopinvader_api_delivery_pickup/tests/test_cart.py create mode 100644 shopinvader_api_delivery_pickup/tests/test_delivery_carrier.py rename {shopinvader_delivery_pickup => shopinvader_api_delivery_pickup}/tests/test_delivery_pickup.py (63%) delete mode 100644 shopinvader_delivery_pickup/__init__.py delete mode 100644 shopinvader_delivery_pickup/readme/ROADMAP.rst delete mode 100644 shopinvader_delivery_pickup/services/__init__.py delete mode 100644 shopinvader_delivery_pickup/services/abstract_sale.py delete mode 100644 shopinvader_delivery_pickup/services/cart.py delete mode 100644 shopinvader_delivery_pickup/services/delivery_carrier.py delete mode 100644 shopinvader_delivery_pickup/services/delivery_pickup.py delete mode 100644 shopinvader_delivery_pickup/tests/common.py delete mode 100644 shopinvader_delivery_pickup/tests/test_cart.py delete mode 100644 shopinvader_delivery_pickup/tests/test_delivery_carrier.py diff --git a/setup/.setuptools-odoo-make-default-ignore b/setup/.setuptools-odoo-make-default-ignore new file mode 100644 index 0000000..207e615 --- /dev/null +++ b/setup/.setuptools-odoo-make-default-ignore @@ -0,0 +1,2 @@ +# addons listed in this file are ignored by +# setuptools-odoo-make-default (one addon per line) diff --git a/setup/README b/setup/README new file mode 100644 index 0000000..a63d633 --- /dev/null +++ b/setup/README @@ -0,0 +1,2 @@ +To learn more about this directory, please visit +https://pypi.python.org/pypi/setuptools-odoo diff --git a/setup/shopinvader_api_delivery_pickup/odoo/addons/shopinvader_api_delivery_pickup b/setup/shopinvader_api_delivery_pickup/odoo/addons/shopinvader_api_delivery_pickup new file mode 120000 index 0000000..26dfe6a --- /dev/null +++ b/setup/shopinvader_api_delivery_pickup/odoo/addons/shopinvader_api_delivery_pickup @@ -0,0 +1 @@ +../../../../shopinvader_api_delivery_pickup \ No newline at end of file diff --git a/setup/shopinvader_api_delivery_pickup/setup.py b/setup/shopinvader_api_delivery_pickup/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/shopinvader_api_delivery_pickup/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopinvader_api_delivery_pickup/README.rst b/shopinvader_api_delivery_pickup/README.rst new file mode 100644 index 0000000..f4c7ffd --- /dev/null +++ b/shopinvader_api_delivery_pickup/README.rst @@ -0,0 +1,81 @@ +=========================== +Shopinvader Delivery Pickup +=========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d1c0d9ae60c51081ab91a8e029129c55cea1cc48162865c0fa7ae2bee91e9c05 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader--carrier-lightgray.png?logo=github + :target: https://github.com/shopinvader/odoo-shopinvader-carrier/tree/16.0/shopinvader_api_delivery_pickup + :alt: shopinvader/odoo-shopinvader-carrier + +|badge1| |badge2| |badge3| + +Expose pickup sites to shopinvader API + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +For now the module only implement a fastapi for setting the dropoffsite. + +TODO: +- add the possibility to search a dropoff_site with geo location + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion +* ACSONE SA/NV +* Shopinvader + +Contributors +~~~~~~~~~~~~ + +* Sebastien BEAU +* Laurent Mignon +* Raphaël Reverdy +* Chafique DELLI + +Other credits +~~~~~~~~~~~~~ + +The development of this module has been financially supported by: + +* Akretion +* ACSONE SA/NV + +Maintainers +~~~~~~~~~~~ + +This module is part of the `shopinvader/odoo-shopinvader-carrier `_ project on GitHub. + +You are welcome to contribute. diff --git a/shopinvader_api_delivery_pickup/__init__.py b/shopinvader_api_delivery_pickup/__init__.py new file mode 100644 index 0000000..62a5d54 --- /dev/null +++ b/shopinvader_api_delivery_pickup/__init__.py @@ -0,0 +1 @@ +from . import routers diff --git a/shopinvader_delivery_pickup/__manifest__.py b/shopinvader_api_delivery_pickup/__manifest__.py similarity index 55% rename from shopinvader_delivery_pickup/__manifest__.py rename to shopinvader_api_delivery_pickup/__manifest__.py index 1ca11c7..463d0d3 100644 --- a/shopinvader_delivery_pickup/__manifest__.py +++ b/shopinvader_api_delivery_pickup/__manifest__.py @@ -1,20 +1,23 @@ -# Copyright 2019 Akretion (http://www.akretion.com) +# Copyright 2019-2024 Akretion (http://www.akretion.com) # Sébastien BEAU # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - "name": "Shopinvader Delivery pickup", + "name": "Shopinvader Delivery Pickup", "summary": "Allows to deliver sale order to pickup site", - "version": "12.0.1.0.0", + "version": "16.0.1.0.0", "category": "e-commerce", "website": "https://github.com/shopinvader/odoo-shopinvader-carrier", - "author": "Akretion, ACSONE SA/NV", + "author": "Akretion, ACSONE SA/NV, Shopinvader", "license": "AGPL-3", "application": False, "installable": True, "external_dependencies": {"python": [], "bin": []}, - "depends": ["shopinvader_delivery_carrier", "delivery_dropoff_site"], - "data": [], + "depends": ["shopinvader_api_delivery_carrier", "delivery_dropoff_site"], + "data": [ + "security/groups.xml", + "security/acl_delivery_pickup.xml", + ], "demo": [], "qweb": [], } diff --git a/shopinvader_delivery_pickup/readme/CONTRIBUTORS.rst b/shopinvader_api_delivery_pickup/readme/CONTRIBUTORS.rst similarity index 75% rename from shopinvader_delivery_pickup/readme/CONTRIBUTORS.rst rename to shopinvader_api_delivery_pickup/readme/CONTRIBUTORS.rst index f9f4dfc..ac6ec40 100644 --- a/shopinvader_delivery_pickup/readme/CONTRIBUTORS.rst +++ b/shopinvader_api_delivery_pickup/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Sebastien BEAU * Laurent Mignon * Raphaël Reverdy +* Chafique DELLI diff --git a/shopinvader_delivery_pickup/readme/CREDITS.rst b/shopinvader_api_delivery_pickup/readme/CREDITS.rst similarity index 100% rename from shopinvader_delivery_pickup/readme/CREDITS.rst rename to shopinvader_api_delivery_pickup/readme/CREDITS.rst diff --git a/shopinvader_delivery_pickup/readme/DESCRIPTION.rst b/shopinvader_api_delivery_pickup/readme/DESCRIPTION.rst similarity index 100% rename from shopinvader_delivery_pickup/readme/DESCRIPTION.rst rename to shopinvader_api_delivery_pickup/readme/DESCRIPTION.rst diff --git a/shopinvader_api_delivery_pickup/readme/ROADMAP.rst b/shopinvader_api_delivery_pickup/readme/ROADMAP.rst new file mode 100644 index 0000000..0667b5b --- /dev/null +++ b/shopinvader_api_delivery_pickup/readme/ROADMAP.rst @@ -0,0 +1,4 @@ +For now the module only implement a fastapi for setting the dropoffsite. + +TODO: +- add the possibility to search a dropoff_site with geo location diff --git a/shopinvader_api_delivery_pickup/routers/__init__.py b/shopinvader_api_delivery_pickup/routers/__init__.py new file mode 100644 index 0000000..0896596 --- /dev/null +++ b/shopinvader_api_delivery_pickup/routers/__init__.py @@ -0,0 +1,2 @@ +from . import cart +from .delivery_pickup import delivery_pickup_router diff --git a/shopinvader_api_delivery_pickup/routers/cart.py b/shopinvader_api_delivery_pickup/routers/cart.py new file mode 100644 index 0000000..1ade256 --- /dev/null +++ b/shopinvader_api_delivery_pickup/routers/cart.py @@ -0,0 +1,84 @@ +# Copyright 2019 Akretion (http://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from typing import Annotated + +from fastapi import Depends + +from odoo import _, api, models +from odoo.exceptions import UserError + +from odoo.addons.base.models.res_partner import Partner as ResPartner +from odoo.addons.fastapi.dependencies import ( + authenticated_partner, + authenticated_partner_env, +) +from odoo.addons.sale.models.sale_order import SaleOrder +from odoo.addons.shopinvader_api_cart.routers import cart_router +from odoo.addons.shopinvader_api_cart.schemas import CartTransaction +from odoo.addons.shopinvader_schema_sale.schemas import Sale + +from ..schemas import DeliveryPickupInput + + +@cart_router.post("/set_pickup") +@cart_router.post("/{uuid}/set_pickup") +@cart_router.post("/current/set_pickup") +def set_delivery_pickup( + env: Annotated[api.Environment, Depends(authenticated_partner_env)], + partner: Annotated["ResPartner", Depends(authenticated_partner)], + data: DeliveryPickupInput, + uuid: str | None = None, +) -> Sale | None: + """ + If cart is found, set the pickup site on it. + """ + cart = env["sale.order"]._find_open_cart(partner.id, uuid) + if not cart: + raise UserError(_("There is no cart")) + env["shopinvader_api_cart.cart_router.helper"]._set_delivery_pickup(cart, data) + return Sale.from_sale_order(cart) if cart else None + + +class ShopinvaderApiCartRouterHelper(models.AbstractModel): + _inherit = "shopinvader_api_cart.cart_router.helper" + + # Set delivery pickup + @api.model + def _set_delivery_pickup(self, cart, data): + pickup_site = self.env["dropoff.site"].search( + [("id", "=", data.pickup_site_id)] + ) + if not pickup_site: + raise UserError(_("Invalid code for pickup site")) + if pickup_site.carrier_id not in cart.shopinvader_available_carrier_ids: + raise UserError(_("This delivery method is not available for your order")) + self._set_carrier_and_price(cart, pickup_site.carrier_id.id) + vals = {"partner_shipping_id": pickup_site.partner_id.id} + if not cart.final_shipping_partner_id: + vals["final_shipping_partner_id"] = cart.partner_shipping_id.id + cart.sudo().write(vals) + + @api.model + def _reset_delivery_pickup(self, cart): + if cart.final_shipping_partner_id: + cart.partner_shipping_id = cart.final_shipping_partner_id + cart.final_shipping_partner_id = None + + @api.model + def _set_carrier(self, cart, data): + self._reset_delivery_pickup(cart) + return super()._set_carrier(cart, data) + + @api.model + def _sync_cart( + self, + partner: ResPartner, + cart: SaleOrder, + uuid: str, + transactions: list[CartTransaction], + ): + cart = super()._sync_cart(partner, cart, uuid, transactions) + if transactions: + self._reset_delivery_pickup(cart) + return cart diff --git a/shopinvader_api_delivery_pickup/routers/delivery_pickup.py b/shopinvader_api_delivery_pickup/routers/delivery_pickup.py new file mode 100644 index 0000000..9906206 --- /dev/null +++ b/shopinvader_api_delivery_pickup/routers/delivery_pickup.py @@ -0,0 +1,68 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from typing import Annotated + +from fastapi import APIRouter, Depends + +from odoo import api, models +from odoo.osv import expression + +from odoo.addons.base.models.res_partner import Partner as ResPartner +from odoo.addons.delivery_dropoff_site.models.dropoff_site import DropoffSite +from odoo.addons.fastapi.dependencies import ( + authenticated_partner, + authenticated_partner_env, +) + +from ..schemas import DeliveryPickup as DeliveryPickupSchema, DeliveryPickupSearch + +delivery_pickup_router = APIRouter(tags=["delivery_pickups"]) + + +@delivery_pickup_router.get("/delivery_pickups") +def search( + data: Annotated[DeliveryPickupSearch, Depends()], + env: Annotated[api.Environment, Depends(authenticated_partner_env)], + partner: Annotated[ResPartner, Depends(authenticated_partner)], +) -> list[DeliveryPickupSchema]: + """ + Returns the list of all available pickup sites. + + If cart, the list will be limited to the + pickup sites linked to carriers applying to the current cart. + + If you don't provide a carrier_id, the service will return all the + pickup sites linked to carriers available for this site. + + If you provide a carrier_id, only the pickup sites linked to the given + carrier are returned except if the carrier is not available for this + site. + """ + delivery_pickups = ( + env["shopinvader_api_delivery_pickup.delivery_pickup_router.helper"] + .new({"partner": partner}) + ._search(data, cart=None) + ) + return [ + DeliveryPickupSchema.from_delivery_pickup(delivery_pickup) + for delivery_pickup in delivery_pickups + ] + + +class ShopinvaderApiDeliveryRouterHelper(models.AbstractModel): + _name = "shopinvader_api_delivery_pickup.delivery_pickup_router.helper" + _description = "ShopInvader API Delivery Pickup Router Helper" + + def _search(self, data, cart=None) -> DropoffSite: + """ + Search for delivery pickup sites + :return: a list of dropoff.site + """ + cart.ensure_one() + domain = data.to_odoo_domain() + if cart: + domain = expression.AND( + domain, + [("carrier_id", "in", cart.shopinvader_available_carrier_ids.ids)], + ) + return self.env["dropoff.site"].search(domain) diff --git a/shopinvader_api_delivery_pickup/schemas/__init__.py b/shopinvader_api_delivery_pickup/schemas/__init__.py new file mode 100644 index 0000000..e509a1b --- /dev/null +++ b/shopinvader_api_delivery_pickup/schemas/__init__.py @@ -0,0 +1,7 @@ +from .resource_calendar_attendance import ResourceCalendarAttendance +from .delivery_pickup import ( + DeliveryPickup, + DeliveryPickupInput, + DeliveryPickupSearch, +) +from .address import DeliveryAddress diff --git a/shopinvader_api_delivery_pickup/schemas/address.py b/shopinvader_api_delivery_pickup/schemas/address.py new file mode 100644 index 0000000..22ff43d --- /dev/null +++ b/shopinvader_api_delivery_pickup/schemas/address.py @@ -0,0 +1,14 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.shopinvader_schema_address import schemas + + +class DeliveryAddress(schemas.DeliveryAddress, extends=True): + is_dropoff_site: bool | None = None + + @classmethod + def from_res_partner(cls, odoo_rec): + res = super().from_res_partner(odoo_rec) + res.is_dropoff_site = odoo_rec.is_dropoff_site or None + return res diff --git a/shopinvader_api_delivery_pickup/schemas/delivery_pickup.py b/shopinvader_api_delivery_pickup/schemas/delivery_pickup.py new file mode 100644 index 0000000..82bbb70 --- /dev/null +++ b/shopinvader_api_delivery_pickup/schemas/delivery_pickup.py @@ -0,0 +1,78 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from typing import Annotated, Field, List + +from extendable_pydantic import StrictExtendableBaseModel + +from odoo import api + +from ..schemas import ResourceCalendarAttendance + + +class DeliveryPickupInput(StrictExtendableBaseModel): + pickup_site_id: int + + +class DeliveryPickupSearch(StrictExtendableBaseModel): + name: Annotated[ + str | None, + Field( + description="When used, the search look for any delivery pickup where name " + "contains the given value case insensitively." + ), + ] = None + carrier_id: Annotated[ + int | None, + Field( + description="When used, the search look for any delivery pickup where carrier " + "contains the given value case insensitively." + ), + ] = None + + def to_odoo_domain(self, env: api.Environment): + domain = [] + if self.name: + domain.append(("name", "ilike", self.name)) + if self.carrier_id: + domain.append(("carrier_id", "ilike", self.carrier_id.id)) + return domain + + +class DeliveryPickup(StrictExtendableBaseModel): + id: int + name: str + code: str | None = None + partner_id: int + street: str | None = None + street2: str | None = None + zip: str | None = None + city: str | None = None + phone: str | None = None + state_id: int | None = None + country_id: int + carrier_id: int + calendar_id: int | None = None + attendance_ids: List[ResourceCalendarAttendance] | None = None + + @classmethod + def from_delivery_pickup(cls, odoo_rec): + return cls.model_construct( + id=odoo_rec.id, + name=odoo_rec.name, + code=odoo_rec.code or None, + partner_id=odoo_rec.partner_id.id, + street=odoo_rec.street or None, + street2=odoo_rec.street2 or None, + zip=odoo_rec.zip or None, + city=odoo_rec.city or None, + phone=odoo_rec.phone or None, + state_id=odoo_rec.state_id.id or None, + country_id=odoo_rec.country_id.id, + carrier_id=odoo_rec.carrier_id.id, + calendar_id=odoo_rec.calendar_id.id or None, + attendance_ids=[ + ResourceCalendarAttendance.from_resource_calendar_attendance(attendance) + for attendance in odoo_rec.attendance_ids + ] + or None, + ) diff --git a/shopinvader_api_delivery_pickup/schemas/resource_calendar_attendance.py b/shopinvader_api_delivery_pickup/schemas/resource_calendar_attendance.py new file mode 100644 index 0000000..5c210f5 --- /dev/null +++ b/shopinvader_api_delivery_pickup/schemas/resource_calendar_attendance.py @@ -0,0 +1,26 @@ +# Copyright 2024 AKRETION +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from extendable_pydantic import StrictExtendableBaseModel + + +class ResourceCalendarAttendance(StrictExtendableBaseModel): + id: int + name: str + hour_from: float + hour_to: float + dayofweek: str + calendar_id: int + day_period: str + + @classmethod + def from_resource_calendar_attendance(cls, odoo_rec): + return cls.model_construct( + id=odoo_rec.id, + name=odoo_rec.name, + hour_from=odoo_rec.hour_from, + hour_to=odoo_rec.hour_to, + dayofweek=odoo_rec.dayofweek, + calendar_id=odoo_rec.calendar_id.id, + day_period=odoo_rec.day_period, + ) diff --git a/shopinvader_api_delivery_pickup/security/acl_delivery_pickup.xml b/shopinvader_api_delivery_pickup/security/acl_delivery_pickup.xml new file mode 100644 index 0000000..f3742c4 --- /dev/null +++ b/shopinvader_api_delivery_pickup/security/acl_delivery_pickup.xml @@ -0,0 +1,19 @@ + + + + + + delivery.pickup shopinvader user read access + + + + + + + + + diff --git a/shopinvader_api_delivery_pickup/security/groups.xml b/shopinvader_api_delivery_pickup/security/groups.xml new file mode 100644 index 0000000..3a89c74 --- /dev/null +++ b/shopinvader_api_delivery_pickup/security/groups.xml @@ -0,0 +1,16 @@ + + + + + + Delivery Pickup User + + + + diff --git a/shopinvader_api_delivery_pickup/static/description/index.html b/shopinvader_api_delivery_pickup/static/description/index.html new file mode 100644 index 0000000..3045ce1 --- /dev/null +++ b/shopinvader_api_delivery_pickup/static/description/index.html @@ -0,0 +1,436 @@ + + + + + +Shopinvader Delivery Pickup + + + +
+

Shopinvader Delivery Pickup

+ + +

Beta License: AGPL-3 shopinvader/odoo-shopinvader-carrier

+

Expose pickup sites to shopinvader API

+

Table of contents

+ +
+

Known issues / Roadmap

+

For now the module only implement a fastapi for setting the dropoffsite.

+

TODO: +- add the possibility to search a dropoff_site with geo location

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
  • ACSONE SA/NV
  • +
  • Shopinvader
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The development of this module has been financially supported by:

+
    +
  • Akretion
  • +
  • ACSONE SA/NV
  • +
+
+
+

Maintainers

+

This module is part of the shopinvader/odoo-shopinvader-carrier project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/shopinvader_delivery_pickup/tests/__init__.py b/shopinvader_api_delivery_pickup/tests/__init__.py similarity index 100% rename from shopinvader_delivery_pickup/tests/__init__.py rename to shopinvader_api_delivery_pickup/tests/__init__.py diff --git a/shopinvader_api_delivery_pickup/tests/common.py b/shopinvader_api_delivery_pickup/tests/common.py new file mode 100644 index 0000000..8fa3b1f --- /dev/null +++ b/shopinvader_api_delivery_pickup/tests/common.py @@ -0,0 +1,45 @@ +# Copyright 2019 Akretion (http://www.akretion.com). +# Copyright 2019 ACSONE SA/NV +# @author Sébastien BEAU +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import json + +from requests import Response + +from odoo.addons.shopinvader_api_cart.routers import cart_router +from odoo.addons.shopinvader_api_delivery_carrier.tests.common import ( + TestShopinvaderDeliveryCarrierCommon, +) + + +class TestShopinvaderDeliveryPickupCommon(TestShopinvaderDeliveryCarrierCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.user_with_rights.groups_id = [ + (4, cls.env.ref("sales_team.group_sale_salesman").id) + ] + cls.pickup_carrier = cls.env.ref("delivery_dropoff_site.delivery_carrier") + cls.poste_carrier.with_dropoff_site = True + cls.cart.carrier_id = cls.poste_carrier.id + cls.pickup_site_foo = cls.env["dropoff.site"].create( + {"ref": "foo", "name": "Foo", "carrier_id": cls.poste_carrier.id} + ) + cls.pickup_site_bar = cls.env["dropoff.site"].create( + {"ref": "bar", "name": "Bar", "carrier_id": cls.free_carrier.id} + ) + cls.cart.partner_shipping_id = cls.pickup_site_foo.partner_id.id + cls.cart.onchange_partner_shipping_id() + cls.final_partner = cls.cart.partner_shipping_id + + def _set_carrier(self, carrier_id): + with self._create_test_client(router=cart_router) as test_client: + data = { + "carrier_id": carrier_id, + } + response: Response = test_client.post( + "/set_carrier", content=json.dumps(data) + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(self.cart.carrier_id.id, carrier_id) + return response.json() diff --git a/shopinvader_api_delivery_pickup/tests/test_cart.py b/shopinvader_api_delivery_pickup/tests/test_cart.py new file mode 100644 index 0000000..94ed5dd --- /dev/null +++ b/shopinvader_api_delivery_pickup/tests/test_cart.py @@ -0,0 +1,64 @@ +# Copyright 2019 Akretion (http://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import json + +from requests import Response + +from odoo.tests.common import tagged + +from odoo.addons.shopinvader_api_cart.routers import cart_router + +from .common import TestShopinvaderDeliveryPickupCommon + + +@tagged("post_install", "-at_install") +class TestCart(TestShopinvaderDeliveryPickupCommon): + def _set_pickup(self, pickup_site): + with self._create_test_client(router=cart_router) as test_client: + data = { + "pickup_site_id": pickup_site.id, + } + response: Response = test_client.post( + "/set_pickup", content=json.dumps(data) + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(self.cart.partner_shipping_id, pickup_site.partner_id) + return response.json() + + def test_setting_pickup_site(self): + shipping = self.cart.partner_shipping_id + self.assertEqual(shipping.ref, "foo") + self.assertEqual(shipping.name, "Foo") + self.assertEqual(shipping, self.final_partner) + self.assertEqual(self.final_partner.is_dropoff_site, True) + self.assertEqual( + self.cart.final_shipping_partner_id.name, "FastAPI Delivery Carrier Demo" + ) + self.assertEqual(self.cart.carrier_id, self.poste_carrier) + + def test_changing_pickup_site(self): + previous_shipping = self.cart.partner_shipping_id + self._set_pickup(self.pickup_site_bar) + self.assertNotEqual(self.cart.partner_shipping_id, previous_shipping) + shipping = self.cart.partner_shipping_id + self.assertEqual(shipping.ref, "bar") + self.assertEqual(shipping.name, "Bar") + self.assertEqual(shipping, self.final_partner) + self.assertEqual(self.final_partner.is_dropoff_site, True) + self.assertEqual( + self.cart.final_shipping_partner_id.name, "FastAPI Delivery Carrier Demo" + ) + self.assertEqual(self.cart.carrier_id, self.free_carrier) + + def test_change_carrier(self): + self._set_carrier(carrier_id=self.free_carrier.id) + self.assertEqual(self.cart.partner_shipping_id, self.final_partner) + self.assertEqual(self.final_partner.is_dropoff_site, False) + self.assertEqual( + self.cart.final_shipping_partner_id.name, "FastAPI Delivery Carrier Demo" + ) + + def test_unset_carrier(self): + self._set_carrier(carrier_id=False) + self.assertEqual(self.cart.partner_shipping_id, self.final_partner) diff --git a/shopinvader_api_delivery_pickup/tests/test_delivery_carrier.py b/shopinvader_api_delivery_pickup/tests/test_delivery_carrier.py new file mode 100644 index 0000000..e8b1c94 --- /dev/null +++ b/shopinvader_api_delivery_pickup/tests/test_delivery_carrier.py @@ -0,0 +1,42 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from requests import Response + +from odoo.tests.common import tagged + +from odoo.addons.shopinvader_api_delivery_carrier.routers import delivery_carrier_router + +from .common import TestShopinvaderDeliveryPickupCommon + + +@tagged("post_install", "-at_install") +class TestDeliveryCarrier(TestShopinvaderDeliveryPickupCommon): + def test_search_all(self): + with self._create_test_client(router=delivery_carrier_router) as test_client: + response: Response = test_client.get("/delivery_carriers") + self.assertEqual(response.status_code, 200) + res = response.json() + expected = [ + { + "id": self.free_carrier.id, + "name": self.free_carrier.name, + "code": self.free_carrier.code or None, + }, + { + "id": self.poste_carrier.id, + "name": self.poste_carrier.name, + "code": self.poste_carrier.code or None, + }, + { + "id": self.pickup_carrier.id, + "name": self.pickup_carrier.name, + "code": self.pickup_carrier.code or None, + }, + { + "id": self.local_carrier.id, + "name": self.local_carrier.name, + "code": self.local_carrier.code or None, + }, + ] + self.assertEqual(res, expected) diff --git a/shopinvader_delivery_pickup/tests/test_delivery_pickup.py b/shopinvader_api_delivery_pickup/tests/test_delivery_pickup.py similarity index 63% rename from shopinvader_delivery_pickup/tests/test_delivery_pickup.py rename to shopinvader_api_delivery_pickup/tests/test_delivery_pickup.py index 5cd1ce5..98ec3d0 100644 --- a/shopinvader_delivery_pickup/tests/test_delivery_pickup.py +++ b/shopinvader_api_delivery_pickup/tests/test_delivery_pickup.py @@ -1,28 +1,35 @@ # Copyright 2019 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from .common import CommondDeliveryPickupCase +from odoo.tests.common import tagged -class TestDeliveryCarrier(CommondDeliveryPickupCase): +from .common import TestShopinvaderDeliveryPickupCommon + + +@tagged("post_install", "-at_install") +class TestDeliveryPickup(TestShopinvaderDeliveryPickupCommon): def _assertExpectedPickupSites(self, search_result, dropoff_sites): - self.assertIn("count", search_result) - self.assertEqual(search_result["count"], len(dropoff_sites)) - pickup_ids = [r["id"] for r in search_result["rows"]] + self.assertEqual(len(search_result), len(dropoff_sites)) + pickup_ids = [r["id"] for r in search_result] self.assertSetEqual(set(dropoff_sites.ids), set(pickup_ids)) + def _delivery_pickup_search(self, domain): + return self.env["dropoff.site"].search(domain) + def test_01(self): """ Data: - * a backend with 2 delivery methods (poste, free) + * 2 delivery methods (poste, free) * 2 dropoff_site defined for delivery la poste Test Case: * search delivery_pickup without parameters Expected result: - * 2 pickup site found + * 2 pickup sites found :return: """ - res = self._delivery_pickup_search() + domain = [("carrier_id", "in", self.cart.shopinvader_available_carrier_ids.ids)] + res = self._delivery_pickup_search(domain) self._assertExpectedPickupSites( res, self.pickup_site_foo | self.pickup_site_bar ) @@ -30,7 +37,7 @@ def test_01(self): def test_02(self): """ Data: - * a backend without delivery method + * cart without delivery method * 2 dropoff_site defined for delivery la poste Test Case: * search delivery_pickup without parameters @@ -38,14 +45,15 @@ def test_02(self): * No site found :return: """ - self.backend.write({"carrier_ids": [(5, None, None)]}) - res = self._delivery_pickup_search() + self._set_carrier(carrier_id=False) + domain = [("carrier_id", "=", False)] + res = self._delivery_pickup_search(domain) self._assertExpectedPickupSites(res, self.env["dropoff.site"].browse()) def test_03(self): """ Data: - * a backend without delivery method + * cart without delivery method * 2 dropoff_site defined for delivery la poste Test Case: * search delivery_pickup for carrier la poste @@ -53,14 +61,15 @@ def test_03(self): * No site found :return: """ - self.backend.write({"carrier_ids": [(5, None, None)]}) - res = self._delivery_pickup_search(carrier_id=self.poste_carrier.id) + self._set_carrier(carrier_id=False) + domain = [("carrier_id", "=", self.poste_carrier.id)] + res = self._delivery_pickup_search(domain) self._assertExpectedPickupSites(res, self.env["dropoff.site"].browse()) def test_04(self): """ Data: - * a backend without 2 delivery methods (poste, free) + * 2 delivery methods (poste, free) with dropoff_site * 1 dropoff_site defined for delivery la poste * 1 dropoff_site defined for delivery free Test Case: @@ -71,13 +80,14 @@ def test_04(self): """ self.pickup_site_bar.carrier_id = self.free_carrier self.pickup_site_foo.carrier_id = self.poste_carrier - res = self._delivery_pickup_search(carrier_id=self.poste_carrier.id) + domain = [("carrier_id", "=", self.poste_carrier.id)] + res = self._delivery_pickup_search(domain) self._assertExpectedPickupSites(res, self.pickup_site_foo) def test_05(self): """ Data: - * a backend without 2 delivery methods (poste, free) + * 2 delivery methods (poste, free) with dropoff_site * 1 dropoff_site defined for delivery la poste * 1 dropoff_site defined for delivery la free Test Case: @@ -89,8 +99,9 @@ def test_05(self): """ self.pickup_site_bar.carrier_id = self.free_carrier self.pickup_site_foo.carrier_id = self.poste_carrier - self._set_carrier(self.poste_carrier) - res = self._delivery_pickup_search(target="current_cart") + self._set_carrier(carrier_id=self.poste_carrier.id) + domain = [("carrier_id", "in", self.cart.shopinvader_available_carrier_ids.ids)] + res = self._delivery_pickup_search(domain) self._assertExpectedPickupSites( res, self.pickup_site_foo | self.pickup_site_bar ) diff --git a/shopinvader_delivery_pickup/__init__.py b/shopinvader_delivery_pickup/__init__.py deleted file mode 100644 index 99464a7..0000000 --- a/shopinvader_delivery_pickup/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import services diff --git a/shopinvader_delivery_pickup/readme/ROADMAP.rst b/shopinvader_delivery_pickup/readme/ROADMAP.rst deleted file mode 100644 index 518c7b7..0000000 --- a/shopinvader_delivery_pickup/readme/ROADMAP.rst +++ /dev/null @@ -1,4 +0,0 @@ -For now the module only implement an api rest for setting the dropoffsite. - -TODO: -- add the possibility to search a dropoff_site with geo location diff --git a/shopinvader_delivery_pickup/services/__init__.py b/shopinvader_delivery_pickup/services/__init__.py deleted file mode 100644 index 41d27e5..0000000 --- a/shopinvader_delivery_pickup/services/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from . import abstract_sale -from . import cart -from . import delivery_pickup -from . import delivery_carrier diff --git a/shopinvader_delivery_pickup/services/abstract_sale.py b/shopinvader_delivery_pickup/services/abstract_sale.py deleted file mode 100644 index 0376b58..0000000 --- a/shopinvader_delivery_pickup/services/abstract_sale.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2016 Akretion (http://www.akretion.com) -# Sébastien BEAU -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo.addons.component.core import AbstractComponent - - -class AbstractSaleService(AbstractComponent): - _inherit = "shopinvader.abstract.sale.service" - - def _convert_shipping(self, sale): - res = super(AbstractSaleService, self)._convert_shipping(sale) - if sale.partner_shipping_id.is_dropoff_site: - res["address"].update( - { - "recipient_name": sale.final_shipping_partner_id.name, - "is_pickup_site": True, - } - ) - return res diff --git a/shopinvader_delivery_pickup/services/cart.py b/shopinvader_delivery_pickup/services/cart.py deleted file mode 100644 index 6d615ff..0000000 --- a/shopinvader_delivery_pickup/services/cart.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright 2019 Akretion (http://www.akretion.com). -# @author Sébastien BEAU -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo.addons.base_rest.components.service import to_int -from odoo.addons.component.core import Component -from odoo.exceptions import UserError -from odoo.tools.translate import _ - - -class CartService(Component): - _inherit = "shopinvader.cart.service" - - # Public services - - def set_delivery_pickup(self, **params): - """ - This service will apply the given pickup site AND the linked - carrier to the current cart - :param params: Dict containing pickup site information - :return: - """ - cart = self._get() - if not cart: - raise UserError(_("There is not cart")) - else: - self._set_delivery_pickup(cart, params["pickup_site_id"]) - return self._to_json(cart) - - # Validator - - def _validator_set_delivery_pickup(self): - return {"pickup_site_id": {"coerce": to_int}} - - # Services implementation - - def _set_delivery_pickup(self, cart, pickup_site_id): - pickup_site_obj = self.env["dropoff.site"] - pickup_site = pickup_site_obj.search([("id", "=", pickup_site_id)]) - if not pickup_site: - raise UserError(_("Invalid code for pickup site")) - self._set_carrier(cart, pickup_site.carrier_id.id) - vals = {"partner_shipping_id": pickup_site.partner_id.id} - if not cart.final_shipping_partner_id: - vals["final_shipping_partner_id"] = cart.partner_shipping_id.id - cart.write(vals) - - def _reset_delivery_pickup(self, cart): - if cart.final_shipping_partner_id: - cart.partner_shipping_id = cart.final_shipping_partner_id - cart.final_shipping_partner_id = None - - def _set_carrier(self, cart, carrier_id): - self._reset_delivery_pickup(cart) - return super(CartService, self)._set_carrier(cart, carrier_id) - - def _unset_carrier(self, cart): - self._reset_delivery_pickup(cart) - return super(CartService, self)._unset_carrier(cart) diff --git a/shopinvader_delivery_pickup/services/delivery_carrier.py b/shopinvader_delivery_pickup/services/delivery_carrier.py deleted file mode 100644 index 71240a2..0000000 --- a/shopinvader_delivery_pickup/services/delivery_carrier.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2019 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -# pylint: disable=consider-merging-classes-inherited,method-required-super - -from odoo.addons.component.core import Component - - -class DeliveryCarrierService(Component): - _inherit = "shopinvader.delivery.carrier.service" - - @property - def allowed_carrier_types(self): - res = super(DeliveryCarrierService, self).allowed_carrier_types - res.append("pickup") - return res - - def _prepare_carrier(self, carrier, cart=None): - res = super(DeliveryCarrierService, self)._prepare_carrier( - carrier, cart - ) - if carrier.with_dropoff_site: - res["type"] = "pickup" - return res diff --git a/shopinvader_delivery_pickup/services/delivery_pickup.py b/shopinvader_delivery_pickup/services/delivery_pickup.py deleted file mode 100644 index 007a369..0000000 --- a/shopinvader_delivery_pickup/services/delivery_pickup.py +++ /dev/null @@ -1,163 +0,0 @@ -# Copyright 2019 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo.addons.base_rest.components.service import to_int -from odoo.addons.component.core import Component -from odoo.osv.expression import FALSE_DOMAIN - - -class DeliveryPickupService(Component): - _inherit = "base.shopinvader.service" - _name = "shopinvader.delivery.pickup.service" - _usage = "delivery_pickup" - _description = """ - This service allows you to retrieve the information of available - pickup sites. - """ - - # Public services: - - def search(self, **params): - """ - Returns the list of available pickup sites - - If the target params == current_cart, the list will be limited to the - pickup sites linked to carriers applying to the current cart. - - If you don't provide a carrier_id, the service will return all the - pickup sites linked to carriers available for this site. - - If you provide a carrier_id, only the pickup sites linked to the given - carrier are returned except if the carrier is not available for this - site. - - """ - dropoff_sites = self._search(**params) - return { - "count": len(dropoff_sites), - "rows": [self._dropoff_site_to_json(ds) for ds in dropoff_sites], - } - - # Validators - - def _validator_search(self): - return { - "target": { - "type": "string", - "required": False, - "allowed": ["current_cart"], - }, - "carrier_id": { - "type": "integer", - "coerce": to_int, - "required": False, - "nullable": False, - }, - } - - def _validator_return_search(self): - return { - "count": {"type": "integer", "required": True}, - "rows": { - "type": "list", - "required": True, - "schema": { - "type": "dict", - "schema": self._pickup_site_schema(), - }, - }, - } - - def _pickup_site_schema(self): - return { - "id": {"type": "integer", "required": True}, - "name": {"type": "string", "required": True}, - "ref": {"type": "string", "nullable": True}, - "street": {"type": "string", "nullable": True}, - "street2": {"type": "string", "nullable": True}, - "zip": {"type": "string", "nullable": True}, - "city": {"type": "string", "nullable": True}, - "phone": {"type": "string", "nullable": True}, - "state": { - "type": "dict", - "nullable": True, - "schema": { - "id": {"type": "integer", "required": True}, - "name": {"type": "string", "required": True}, - }, - }, - "country": { - "type": "dict", - "nullable": True, - "schema": { - "id": {"type": "integer", "required": True}, - "name": {"type": "string", "required": True}, - }, - }, - "carrier": { - "type": "dict", - "nullable": True, - "schema": { - "id": {"type": "integer", "required": True}, - "name": {"type": "string", "required": True}, - }, - }, - "attendances": { - "type": "list", - "nullable": True, - "schema": { - "type": "dict", - "schema": { - "id": {"type": "integer", "nullable": True}, - "dayofweek": {"type": "string", "nullable": True}, - "hour_from": {"type": "number", "nullable": True}, - "hour_to": {"type": "number", "nullable": True}, - }, - }, - }, - } - - # Services implementation - - def _search(self, **params): - """ - Search for delively carriers - :param params: see _validator_search - :return: a list of delivery.carriers - """ - domain = self._search_param_to_domain(**params) - return self.env["dropoff.site"].search(domain) - - def _search_param_to_domain(self, **params): - # first of all, always restrict dropoff site for available carrier - available_carriers = self.component(usage="delivery_carrier")._search( - cart=params.get("target") - ) - carrier_id = params.get("carrier_id") - if carrier_id: - if carrier_id not in available_carriers.ids: - return FALSE_DOMAIN - return [("carrier_id", "=", carrier_id)] - return [("carrier_id", "in", available_carriers.ids)] - - def _dropoff_site_to_json(self, dropoff_site): - return dropoff_site.jsonify(self._json_parser())[0] - - def _json_parser(self): - return [ - "id", - "name", - "ref", - "street", - "street2", - "zip", - "city", - "phone", - ("state_id:state", ["id", "name"]), - ("country_id:country", ["id", "name"]), - ("carrier_id:carrier", ["id", "name"]), - ("attendance_ids:attendances", self._json_parser_attendances()), - ] - - def _json_parser_attendances(self): - return ["id", "hour_from", "hour_to", "dayofweek"] diff --git a/shopinvader_delivery_pickup/tests/common.py b/shopinvader_delivery_pickup/tests/common.py deleted file mode 100644 index c258fde..0000000 --- a/shopinvader_delivery_pickup/tests/common.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2019 Akretion (http://www.akretion.com). -# Copyright 2019 ACSONE SA/NV -# @author Sébastien BEAU -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo.addons.shopinvader_delivery_carrier.tests.common import ( - CommonCarrierCase, -) - - -class CommondDeliveryPickupCase(CommonCarrierCase): - def setUp(self): - super(CommondDeliveryPickupCase, self).setUp() - self.final_partner = self.cart.partner_shipping_id - self.poste_carrier.with_dropoff_site = True - self._set_carrier(self.poste_carrier) - self.pickup_site_foo = self.env["dropoff.site"].create( - {"ref": "foo", "name": "Foo", "carrier_id": self.poste_carrier.id} - ) - self.pickup_site_bar = self.env["dropoff.site"].create( - {"ref": "bar", "name": "Bar", "carrier_id": self.free_carrier.id} - ) - self.cart_service = self.service - self.delivery_pickup_service = self.cart_service.component( - usage="delivery_pickups" - ) - self._cart_set_delivery_pickup(self.pickup_site_foo.id) - - def _cart_set_delivery_pickup(self, pickup_site_id): - self.res_cart = self.cart_service.dispatch( - "set_delivery_pickup", params={"pickup_site_id": pickup_site_id} - )["data"] - self.res_address = self.res_cart["shipping"]["address"] - - def _delivery_pickup_search(self, **params): - return self.delivery_pickup_service.dispatch("search", params=params) diff --git a/shopinvader_delivery_pickup/tests/test_cart.py b/shopinvader_delivery_pickup/tests/test_cart.py deleted file mode 100644 index 9928474..0000000 --- a/shopinvader_delivery_pickup/tests/test_cart.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2019 Akretion (http://www.akretion.com). -# @author Sébastien BEAU -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from .common import CommondDeliveryPickupCase - - -class TestCart(CommondDeliveryPickupCase): - def test_setting_pickup_site(self): - shipping = self.cart.partner_shipping_id - self.assertEqual(shipping.ref, "foo") - self.assertEqual(shipping.name, "Foo") - self.assertEqual( - self.cart.final_shipping_partner_id, self.final_partner - ) - self.assertEqual(self.res_address["is_pickup_site"], True) - self.assertEqual(self.res_address["recipient_name"], "Osiris") - self.assertEqual(self.cart.carrier_id, self.poste_carrier) - - def test_changing_pickup_site(self): - previous_shipping = self.cart.partner_shipping_id - self._cart_set_delivery_pickup(self.pickup_site_bar.id) - self.assertNotEqual(self.cart.partner_shipping_id, previous_shipping) - shipping = self.cart.partner_shipping_id - self.assertEqual(shipping.ref, "bar") - self.assertEqual(shipping.name, "Bar") - self.assertEqual( - self.cart.final_shipping_partner_id, self.final_partner - ) - self.assertEqual(self.res_address["is_pickup_site"], True) - self.assertEqual(self.res_address["recipient_name"], "Osiris") - self.assertEqual(self.cart.carrier_id, self.free_carrier) - - def test_change_carrier(self): - cart = self._set_carrier(self.free_carrier) - address = cart["shipping"]["address"] - self.assertEqual(self.cart.partner_shipping_id, self.final_partner) - self.assertNotIn("is_pickup_site", address) - self.assertNotIn("recipient_name", address) - - def test_unset_carrier(self): - self.service._unset_carrier(self.cart) - self.assertEqual(self.cart.partner_shipping_id, self.final_partner) diff --git a/shopinvader_delivery_pickup/tests/test_delivery_carrier.py b/shopinvader_delivery_pickup/tests/test_delivery_carrier.py deleted file mode 100644 index f7ab250..0000000 --- a/shopinvader_delivery_pickup/tests/test_delivery_carrier.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2019 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.addons.shopinvader_delivery_carrier.tests.common import ( - CommonCarrierCase, -) - - -class TestDeliveryCarrier(CommonCarrierCase): - def setUp(self): - super(CommonCarrierCase, self).setUp() - self.carrier_service = self.service.component("delivery_carriers") - self.poste_carrier.with_dropoff_site = True - self.pickup_site_foo = self.env["dropoff.site"].create( - {"ref": "foo", "name": "Foo", "carrier_id": self.poste_carrier.id} - ) - - def test_search_all(self): - res = self.carrier_service.search() - expected = { - "count": 2, - "rows": [ - { - "price": 0.0, - "description": None, - "id": self.free_carrier.id, - "name": self.free_carrier.name, - "type": None, - }, - { - "price": 0.0, - "description": None, - "id": self.poste_carrier.id, - "name": self.poste_carrier.name, - "type": "pickup", - }, - ], - } - self.assertDictEqual(res, expected)