Skip to content
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

[16.0] mig delivery pickup (TODO) #5

Open
wants to merge 18 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7d5c797
[IMP] start adding module for dropoff site
sebastienbeau Jun 24, 2019
0c63cdb
[REF] refactor code split edition part in a separated module and add …
sebastienbeau Jun 28, 2019
d902bb3
[IMP] add a flag to know if the shipping address is a dropoff site an…
sebastienbeau Jul 1, 2019
5020150
[IMP] rename shopinvader_dropoff_site into shopinvader_delivery_pickup
lmignon Aug 3, 2019
ed63fdd
[IMP] shopinvader_delivery_pickup: rename set_dropoff_site into set_d…
lmignon Aug 3, 2019
2223066
[IMP] shopinvader_delivery_pickup: Add delivery_pickup service
lmignon Aug 3, 2019
3b90b2b
Fix copyright due to cherry-pick
sebastienbeau Oct 22, 2019
d16d0aa
[FIx] fix test and fix consistency of service name
sebastienbeau Oct 22, 2019
15e0dc0
[FIX] fix changed in API
sebastienbeau Apr 22, 2020
742faa8
[FIX] fix comment done by Laurent Mignon
sebastienbeau Aug 25, 2020
c3845fb
shopinvader_delivery_pickup: black, isort, prettier
hparfr Jun 8, 2021
cef0a0c
shopinvader_delivery_pickup: Migration to 12.0
hparfr Jun 8, 2021
2f9264a
shopinvader_delivery_pickup: expose opening hours
hparfr Jun 8, 2021
0ca4616
[16.0][MIG] shopinvader_delivery_pickup: Migration to 16.0 (FastAPI)
chafique-delli Apr 30, 2024
9bab98e
shopinvader_api_delivery_pickup: set module in alpha
sebastienbeau Sep 4, 2024
d87684c
shopinvader_api_delivery_pickup: fix import
sebastienbeau Sep 4, 2024
fc80b3c
shopinvader_api_delivery_pickup: Fix setting delivery pickup
sebastienbeau Sep 5, 2024
6b93a80
shopinvader_api_delivery_pickup: add with_dropoff_site in schema
chafique-delli Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions setup/.setuptools-odoo-make-default-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# addons listed in this file are ignored by
# setuptools-odoo-make-default (one addon per line)
2 changes: 2 additions & 0 deletions setup/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To learn more about this directory, please visit
https://pypi.python.org/pypi/setuptools-odoo
6 changes: 6 additions & 0 deletions setup/shopinvader_api_delivery_pickup/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,
)
86 changes: 86 additions & 0 deletions shopinvader_api_delivery_pickup/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
===========================
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-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**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 <https://github.com/shopinvader/odoo-shopinvader-carrier/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 <https://github.com/shopinvader/odoo-shopinvader-carrier/issues/new?body=module:%20shopinvader_api_delivery_pickup%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Akretion
* ACSONE SA/NV
* Shopinvader

Contributors
~~~~~~~~~~~~

* Sebastien BEAU <[email protected]>
* Laurent Mignon <[email protected]>
* Raphaël Reverdy <[email protected]>
* Chafique DELLI <[email protected]>

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 <https://github.com/shopinvader/odoo-shopinvader-carrier/tree/16.0/shopinvader_api_delivery_pickup>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions shopinvader_api_delivery_pickup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import routers
24 changes: 24 additions & 0 deletions shopinvader_api_delivery_pickup/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2019-2024 Akretion (http://www.akretion.com)
# Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Shopinvader Delivery Pickup",
"summary": "Allows to deliver sale order to pickup site",
"version": "16.0.1.0.0",
"category": "e-commerce",
"website": "https://github.com/shopinvader/odoo-shopinvader-carrier",
"author": "Akretion, ACSONE SA/NV, Shopinvader",
"development_status": "Alpha",
"license": "AGPL-3",
"application": False,
"installable": True,
"external_dependencies": {"python": [], "bin": []},
"depends": ["shopinvader_api_delivery_carrier", "delivery_dropoff_site"],
"data": [
"security/groups.xml",
"security/acl_delivery_pickup.xml",
],
"demo": [],
"qweb": [],
}
4 changes: 4 additions & 0 deletions shopinvader_api_delivery_pickup/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Sebastien BEAU <[email protected]>
* Laurent Mignon <[email protected]>
* Raphaël Reverdy <[email protected]>
* Chafique DELLI <[email protected]>
4 changes: 4 additions & 0 deletions shopinvader_api_delivery_pickup/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The development of this module has been financially supported by:

* Akretion
* ACSONE SA/NV
1 change: 1 addition & 0 deletions shopinvader_api_delivery_pickup/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose pickup sites to shopinvader API
4 changes: 4 additions & 0 deletions shopinvader_api_delivery_pickup/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions shopinvader_api_delivery_pickup/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import cart
from .delivery_pickup import delivery_pickup_router
84 changes: 84 additions & 0 deletions shopinvader_api_delivery_pickup/routers/cart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2019 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# 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.pickup_site_id
)
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, pickup_site_id):
pickup_site = self.env["dropoff.site"].search([("id", "=", 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
68 changes: 68 additions & 0 deletions shopinvader_api_delivery_pickup/routers/delivery_pickup.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions shopinvader_api_delivery_pickup/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .resource_calendar_attendance import ResourceCalendarAttendance
from .delivery_pickup import (
DeliveryPickup,
DeliveryPickupInput,
DeliveryPickupSearch,
)
from .address import DeliveryAddress
from .delivery_carrier import (
DeliveryCarrierWithPrice,
DeliveryCarrier,
)
14 changes: 14 additions & 0 deletions shopinvader_api_delivery_pickup/schemas/address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 AKRETION
# 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
24 changes: 24 additions & 0 deletions shopinvader_api_delivery_pickup/schemas/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 AKRETION
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.addons.shopinvader_api_delivery_carrier.schemas import delivery_carrier


class DeliveryCarrierWithPrice(delivery_carrier.DeliveryCarrierWithPrice, extends=True):
with_dropoff_site: bool | None = None

@classmethod
def from_delivery_carrier(cls, odoo_rec, cart=None):
res = super().from_delivery_carrier(odoo_rec, cart=cart)
res.with_dropoff_site = odoo_rec.with_dropoff_site or None
return res


class DeliveryCarrier(delivery_carrier.DeliveryCarrier, extends=True):
with_dropoff_site: bool | None = None

@classmethod
def from_delivery_carrier(cls, odoo_rec):
res = super().from_delivery_carrier(odoo_rec)
res.with_dropoff_site = odoo_rec.with_dropoff_site or None
return res
Loading
Loading