Skip to content

[16.0] [mig] shopinvader_delivery_pickup_public_edition #6

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

Open
wants to merge 6 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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_public_edition/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,
)
78 changes: 78 additions & 0 deletions shopinvader_api_delivery_pickup_public_edition/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
=================================
Shopinvader Pickup Public Edition
=================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c11b4eb95a24a33dea25c3c5f7136d2907d1facd2de388b7e2851b0d18a0053c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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_public_edition
:alt: shopinvader/odoo-shopinvader-carrier

|badge1| |badge2| |badge3|

This is shopinvader the odoo module for the new generation of e-commerce.

This module is a base module for supporting external carrier widget for selecting dropoff site.

You must be aware that this implementation allow public user to create the dropoff site.
So information can be altered, so you should not trust at 100% the meta-information of the dropoffsite.
But the code of the dropoff site is not alterable and can be trusted, as it the only information that are used for sending the goods (we only use the dropoff site code) their is no risk that a package is delivered to the wrong address.


.. _Shopinvader: https://shopinvader.com

**Table of contents**

.. contents::
:local:

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_public_edition%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
* Shopinvader

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

* Sebastien BEAU <[email protected]>
* Chafique DELLI <[email protected]>

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Akretion

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_public_edition>`_ project on GitHub.

You are welcome to contribute.
2 changes: 2 additions & 0 deletions shopinvader_api_delivery_pickup_public_edition/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import routers
from . import models
20 changes: 20 additions & 0 deletions shopinvader_api_delivery_pickup_public_edition/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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 Pickup Public Edition",
"summary": "Shopinvader Pickup Public Edition",
"version": "16.0.1.0.0",
"category": "e-commerce",
"website": "https://github.com/shopinvader/odoo-shopinvader-carrier",
"author": "Akretion, Shopinvader",
"license": "AGPL-3",
"application": False,
"installable": True,
"external_dependencies": {"python": [], "bin": []},
"depends": ["shopinvader_api_delivery_pickup"],
"data": ["views/delivery_carrier_view.xml"],
"demo": [],
"qweb": [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import delivery_carrier
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"

allow_dropoff_site_public_edition = fields.Boolean(
help="This option allow to create a dropoff site from public call "
"on a shopinvader website, this is needed for some carrier",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Sebastien BEAU <[email protected]>
* Chafique DELLI <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

* Akretion
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This is shopinvader the odoo module for the new generation of e-commerce.

This module is a base module for supporting external carrier widget for selecting dropoff site.

You must be aware that this implementation allow public user to create the dropoff site.
So information can be altered, so you should not trust at 100% the meta-information of the dropoffsite.
But the code of the dropoff site is not alterable and can be trusted, as it the only information that are used for sending the goods (we only use the dropoff site code) their is no risk that a package is delivered to the wrong address.


.. _Shopinvader: https://shopinvader.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import cart
98 changes: 98 additions & 0 deletions shopinvader_api_delivery_pickup_public_edition/routers/cart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# 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.shopinvader_api_cart.routers import cart_router
from odoo.addons.shopinvader_schema_sale.schemas import Sale

from ..schemas import PublicDeliveryPickupInput


@cart_router.post("/set_public_delivery_pickup")
@cart_router.post("/{uuid}/set_public_delivery_pickup")
@cart_router.post("/current/set_public_delivery_pickup")
def set_public_delivery_pickup(
env: Annotated[api.Environment, Depends(authenticated_partner_env)],
partner: Annotated["ResPartner", Depends(authenticated_partner)],
data: PublicDeliveryPickupInput,
uuid: str | None = None,
) -> Sale | None:
"""
If cart is found, set the given dropoffsite on it.
"""
cart = env["sale.order"]._find_open_cart(partner.id, uuid)
if not cart:
raise UserError(_("There is no cart"))
dropoff_site = env[
"shopinvader_api_cart.cart_router.helper"
]._add_update_dropoff_site(cart, data)
env["shopinvader_api_cart.cart_router.helper"]._set_delivery_pickup(
cart, dropoff_site.id
)
return Sale.from_sale_order(cart) if cart else None


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

@api.model
def _prepare_dropoff_site_params(self, cart, data):
if not cart.carrier_id:
raise UserError(_("You must select a carrier first"))
elif not cart.carrier_id.allow_dropoff_site_public_edition:
raise UserError(_("You can not add a dropoff site on this carrier"))
dropoff_site = {
"ref": data.code,
"name": data.name,
"street": data.street,
"street2": data.street2,
"zip": data.zip,
"city": data.city,
"phone": data.phone,
}
country_code = data.country_code
state_code = data.state_code

country = self.env["res.country"].search([("code", "=", country_code)])
if not country:
raise UserError(_("Invalid country code %(country_code)s"))
dropoff_site["country_id"] = country.id

if state_code:
state = self.env["res.country.state"].search(
[("code", "=", state_code), ("country_id", "=", country.id)]
)
if not state:
raise UserError(
_("Invalid state code %(state_code)s for country %(country_code)s")
)
dropoff_site["state_id"] = state.id

dropoff_site["carrier_id"] = cart.carrier_id.id
return dropoff_site

@api.model
def _add_update_dropoff_site(self, cart, data):
vals = self._prepare_dropoff_site_params(cart, data)
dropoff_site = self.env["dropoff.site"].search(
[
("carrier_id", "=", cart.carrier_id.id),
("ref", "=", vals["ref"]),
]
)
if dropoff_site:
dropoff_site.write(vals)
else:
dropoff_site = self.env["dropoff.site"].create(vals)
return dropoff_site
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .public_delivery_pickup import (
PublicDeliveryPickup,
PublicDeliveryPickupInput,
PublicDeliveryPickupSearch,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from typing import Annotated

from extendable_pydantic import StrictExtendableBaseModel
from pydantic import Field

from odoo import api


class PublicDeliveryPickupInput(StrictExtendableBaseModel):
code: str
name: str
street: str | None = None
street2: str | None = None
zip: str
city: str
phone: str | None = None
state_code: str | None = None
country_code: str


class PublicDeliveryPickupSearch(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 PublicDeliveryPickup(StrictExtendableBaseModel):
code: str
name: str
street: str | None = None
street2: str | None = None
zip: str
city: str
phone: str | None = None
state_code: str | None = None
country_code: str

@classmethod
def from_public_delivery_pickup(cls, odoo_rec):
return cls.model_construct(
code=odoo_rec.code,
name=odoo_rec.name,
street=odoo_rec.street or None,
street2=odoo_rec.street2 or None,
zip=odoo_rec.zip,
city=odoo_rec.city,
phone=odoo_rec.phone or None,
state_code=odoo_rec.state_id.code or None,
country_code=odoo_rec.country_id.code,
)
Loading
Loading