From 0bef32777135cc142ce8cbb4a9bbb84b58a3f694 Mon Sep 17 00:00:00 2001 From: Zina Rasoamanana Date: Tue, 6 Jun 2023 12:24:54 +0200 Subject: [PATCH 1/2] parent 9e24cfedfcba9a5051f0ad161fcd8d679e4f2466 author Zina Rasoamanana 1686047094 +0200 committer Zina Rasoamanana 1688136067 +0200 [ADD] addon shopinvader_schema_address: init wip: add addres_billing/shipping get/create update shipping address work on tests + use country/state_id + work on address schemas rename address service extract service logic from model extract shopinvader_address some improvements + sudo on service write add vat on billing address split create/update shipping address check before update/delete shipping address readme shopinvader_schema_address shopinvader_api_address readme shopinvader_address: readme [FIX] shopinvader_api_address_*: Uses new helper class to run tests with fastapi and extendable --- requirements.txt | 3 + .../odoo/addons/shopinvader_address | 1 + setup/shopinvader_address/setup.py | 6 + .../odoo/addons/shopinvader_api_address | 1 + setup/shopinvader_api_address/setup.py | 6 + .../odoo/addons/shopinvader_schema_address | 1 + setup/shopinvader_schema_address/setup.py | 6 + shopinvader_address/README.rst | 96 ++++ shopinvader_address/__init__.py | 1 + shopinvader_address/__manifest__.py | 17 + shopinvader_address/models/__init__.py | 1 + shopinvader_address/models/res_partner.py | 163 +++++++ shopinvader_address/readme/CONTRIBUTORS.rst | 4 + shopinvader_address/readme/DESCRIPTION.rst | 2 + shopinvader_address/readme/USAGE.rst | 31 ++ .../static/description/index.html | 447 ++++++++++++++++++ shopinvader_api_address/README.rst | 61 +++ shopinvader_api_address/__init__.py | 2 + shopinvader_api_address/__manifest__.py | 25 + .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 2 + shopinvader_api_address/routers/__init__.py | 2 + .../routers/address_service.py | 164 +++++++ shopinvader_api_address/schemas.py | 119 +++++ .../security/res_groups.xml | 16 + .../security/res_partner.xml | 27 ++ .../static/description/icon.png | Bin 0 -> 9455 bytes .../static/description/index.html | 418 ++++++++++++++++ shopinvader_api_address/tests/__init__.py | 1 + .../tests/test_shopinvader_address_api.py | 336 +++++++++++++ shopinvader_schema_address/README.rst | 62 +++ shopinvader_schema_address/__init__.py | 1 + shopinvader_schema_address/__manifest__.py | 21 + .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 3 + shopinvader_schema_address/schemas.py | 60 +++ .../static/description/icon.png | Bin 0 -> 9455 bytes .../static/description/index.html | 419 ++++++++++++++++ 38 files changed, 2533 insertions(+) create mode 120000 setup/shopinvader_address/odoo/addons/shopinvader_address create mode 100644 setup/shopinvader_address/setup.py create mode 120000 setup/shopinvader_api_address/odoo/addons/shopinvader_api_address create mode 100644 setup/shopinvader_api_address/setup.py create mode 120000 setup/shopinvader_schema_address/odoo/addons/shopinvader_schema_address create mode 100644 setup/shopinvader_schema_address/setup.py create mode 100644 shopinvader_address/README.rst create mode 100644 shopinvader_address/__init__.py create mode 100644 shopinvader_address/__manifest__.py create mode 100644 shopinvader_address/models/__init__.py create mode 100644 shopinvader_address/models/res_partner.py create mode 100644 shopinvader_address/readme/CONTRIBUTORS.rst create mode 100644 shopinvader_address/readme/DESCRIPTION.rst create mode 100644 shopinvader_address/readme/USAGE.rst create mode 100644 shopinvader_address/static/description/index.html create mode 100644 shopinvader_api_address/README.rst create mode 100644 shopinvader_api_address/__init__.py create mode 100644 shopinvader_api_address/__manifest__.py create mode 100644 shopinvader_api_address/readme/CONTRIBUTORS.rst create mode 100644 shopinvader_api_address/readme/DESCRIPTION.rst create mode 100644 shopinvader_api_address/routers/__init__.py create mode 100644 shopinvader_api_address/routers/address_service.py create mode 100644 shopinvader_api_address/schemas.py create mode 100644 shopinvader_api_address/security/res_groups.xml create mode 100644 shopinvader_api_address/security/res_partner.xml create mode 100644 shopinvader_api_address/static/description/icon.png create mode 100644 shopinvader_api_address/static/description/index.html create mode 100644 shopinvader_api_address/tests/__init__.py create mode 100644 shopinvader_api_address/tests/test_shopinvader_address_api.py create mode 100644 shopinvader_schema_address/README.rst create mode 100644 shopinvader_schema_address/__init__.py create mode 100644 shopinvader_schema_address/__manifest__.py create mode 100644 shopinvader_schema_address/readme/CONTRIBUTORS.rst create mode 100644 shopinvader_schema_address/readme/DESCRIPTION.rst create mode 100644 shopinvader_schema_address/schemas.py create mode 100644 shopinvader_schema_address/static/description/icon.png create mode 100644 shopinvader_schema_address/static/description/index.html diff --git a/requirements.txt b/requirements.txt index 180fc49789..893abd9d60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,5 @@ # generated from manifests external_dependencies +extendable_pydantic +fastapi openupgradelib +pydantic diff --git a/setup/shopinvader_address/odoo/addons/shopinvader_address b/setup/shopinvader_address/odoo/addons/shopinvader_address new file mode 120000 index 0000000000..8340ba8d32 --- /dev/null +++ b/setup/shopinvader_address/odoo/addons/shopinvader_address @@ -0,0 +1 @@ +../../../../shopinvader_address \ No newline at end of file diff --git a/setup/shopinvader_address/setup.py b/setup/shopinvader_address/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_address/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/shopinvader_api_address/odoo/addons/shopinvader_api_address b/setup/shopinvader_api_address/odoo/addons/shopinvader_api_address new file mode 120000 index 0000000000..7ab1a9af29 --- /dev/null +++ b/setup/shopinvader_api_address/odoo/addons/shopinvader_api_address @@ -0,0 +1 @@ +../../../../shopinvader_api_address \ No newline at end of file diff --git a/setup/shopinvader_api_address/setup.py b/setup/shopinvader_api_address/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_api_address/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/shopinvader_schema_address/odoo/addons/shopinvader_schema_address b/setup/shopinvader_schema_address/odoo/addons/shopinvader_schema_address new file mode 120000 index 0000000000..626dee81d1 --- /dev/null +++ b/setup/shopinvader_schema_address/odoo/addons/shopinvader_schema_address @@ -0,0 +1 @@ +../../../../shopinvader_schema_address \ No newline at end of file diff --git a/setup/shopinvader_schema_address/setup.py b/setup/shopinvader_schema_address/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_schema_address/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopinvader_address/README.rst b/shopinvader_address/README.rst new file mode 100644 index 0000000000..050b02fa92 --- /dev/null +++ b/shopinvader_address/README.rst @@ -0,0 +1,96 @@ +=================== +Shopinvader Address +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-lightgray.png?logo=github + :target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_address + :alt: shopinvader/odoo-shopinvader + +|badge1| |badge2| |badge3| + +This addons adds helper methos on the res.partner model that ease the management +and the creation of addresses within odoo code. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +BillingAddress + In the context of shopinvader, the ``BillingAddress`` corresponds to the authenticated partner itself. + Therefore, the ``Billing Address`` is unique for each partner. + + Creation of ``Billing Address`` is not supported since it corresponds to the authenticated partner. + + It can be updated using: + + .. code-block:: python + + def _update_shopinvader_billing_address(self, vals: dict, address_id: int) -> "ResPartner" + + *Remark: it cannot be modified if it has already been used on a confirmed sale order.* + +ShippingAddress + In the context of shopinvader, a ``ShippingAddress`` corresponds to any delivery address linked to the authenticated partner. + A partner can have between 0 and n ``ShippingAddress``. + + It can be created using: + + .. code-block:: python + + def _create_shopinvader_shipping_address(self, vals: dict) -> "ResPartner": + + It can be updated using: + + .. code-block:: python + + def _update_shopinvader_shipping_address(self, vals: dict, address_id: int) -> "ResPartner": + + *Remark: it cannot be modified if it has already been used on a confirmed sale order.* + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Laurent Mignon +* Marie Lejeune +* Stéphane Bidoul +* Zina Rasoamanana + +Maintainers +~~~~~~~~~~~ + +This module is part of the `shopinvader/odoo-shopinvader `_ project on GitHub. + +You are welcome to contribute. diff --git a/shopinvader_address/__init__.py b/shopinvader_address/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/shopinvader_address/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/shopinvader_address/__manifest__.py b/shopinvader_address/__manifest__.py new file mode 100644 index 0000000000..5e650b7bb1 --- /dev/null +++ b/shopinvader_address/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Address", + "summary": """ + Shopinvader Address: Shipping,Billing""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "sale", + ], + "data": [], + "demo": [], +} diff --git a/shopinvader_address/models/__init__.py b/shopinvader_address/models/__init__.py new file mode 100644 index 0000000000..91fed54d40 --- /dev/null +++ b/shopinvader_address/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/shopinvader_address/models/res_partner.py b/shopinvader_address/models/res_partner.py new file mode 100644 index 0000000000..232896feda --- /dev/null +++ b/shopinvader_address/models/res_partner.py @@ -0,0 +1,163 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, models +from odoo.exceptions import MissingError, UserError + + +class ResPartner(models.Model): + + _inherit = "res.partner" + + def _ensure_shopinvader_billing_address_not_used(self) -> None: + """ + Check if Billing Address is used on confirmed sale order + """ + self.ensure_one() + sale_order = ( + self.env["sale.order"] + .sudo() + .search( + [ + ("partner_invoice_id", "=", self.id), + ("state", "in", ("done", "sale")), + ], + limit=1, + ) + ) + if len(sale_order) > 0: + raise UserError( + _( + "Can not update billing addresses(%(address_id)d)" + "because it is already used on confirmed sale order", + address_id=self.id, + ) + ) + + def _ensure_shopinvader_shipping_address_not_used(self) -> None: + """ + Check if Shipping Address is used on confirmed sale order + """ + self.ensure_one() + sale_order = ( + self.env["sale.order"] + .sudo() + .search( + [ + ("partner_shipping_id", "=", self.id), + ("state", "in", ("done", "sale")), + ], + limit=1, + ) + ) + if len(sale_order) > 0: + raise UserError( + _( + "Can not delete Shipping address(%(address_id)d)" + "because it is already used on confirmed sale order", + address_id=self.id, + ) + ) + + # --- Billing --- + # Billing address is unique and corresponds to authenticated_partner + + def _get_shopinvader_billing_addresses(self) -> "ResPartner": + self.ensure_one() + return self + + def _get_shopinvader_billing_address(self, address_id: int) -> "ResPartner": + self.ensure_one() + addresses = self._get_shopinvader_billing_addresses() + address = addresses.filtered(lambda rec: rec.id == address_id) + if not address: + raise MissingError( + _( + "Billing address not found, id: %(address_id)d", + address_id=address_id, + ) + ) + return address + + def _create_shopinvader_billing_address(self, vals: dict) -> "ResPartner": + raise UserError(_("Creation of billing addresses is not supported")) + + def _update_shopinvader_billing_address( + self, vals: dict, address_id: int + ) -> "ResPartner": + self.ensure_one() + address = self._get_shopinvader_billing_address(address_id) + + # if billing address is already used, it is not possible to modify it + # an error will be raised + address._ensure_shopinvader_billing_address_not_used() + + address.write(vals) + + return address + + # ---Shipping --- + + def _get_shopinvader_shipping_addresses(self) -> "ResPartner": + self.ensure_one() + domain = [("type", "=", "delivery"), ("parent_id", "=", self.id)] + + return self.env["res.partner"].search(domain) + + def _get_shopinvader_shipping_address(self, address_id: int) -> "ResPartner": + self.ensure_one() + + addresses = self._get_shopinvader_shipping_addresses() + address = addresses.filtered(lambda rec: rec.id == address_id) + if not address: + raise MissingError( + _( + "Shipping address not found, id: %(address_id)d", + address_id=address_id, + ) + ) + + return address + + def _create_shopinvader_shipping_address(self, vals: dict) -> "ResPartner": + self.ensure_one() + vals = dict(vals, parent_id=self.id, type="delivery") + return self.env["res.partner"].create(vals) + + def _update_shopinvader_shipping_address( + self, vals: dict, address_id: int + ) -> "ResPartner": + + if any(key in vals for key in ("parent_id", "type")): + raise UserError( + _( + "parent_id and type cannot be modified on" + " shopinvader shipping address, id: %(address_id)d", + address_id=address_id, + ) + ) + + self.ensure_one() + address = self._get_shopinvader_shipping_address(address_id) + + # if shipping address is already used, it is not possible to modify it + address._ensure_shopinvader_shipping_address_not_used() + + # update_address + address.write(vals) + return address + + def _delete_shopinvader_shipping_address(self, address_id: int) -> None: + """ + Delete of shopinvader shipping addresses will result to an archive + """ + address = self._get_shopinvader_shipping_address(address_id) + if address: + address._ensure_shopinvader_shipping_address_not_used() + + # archive address + address.active = False + else: + raise MissingError( + _("No address found, id: %(address_id)d", address_id=address_id) + ) diff --git a/shopinvader_address/readme/CONTRIBUTORS.rst b/shopinvader_address/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..49726552ac --- /dev/null +++ b/shopinvader_address/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Laurent Mignon +* Marie Lejeune +* Stéphane Bidoul +* Zina Rasoamanana diff --git a/shopinvader_address/readme/DESCRIPTION.rst b/shopinvader_address/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..3f08b3e673 --- /dev/null +++ b/shopinvader_address/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This addons adds helper methos on the res.partner model that ease the management +and the creation of addresses within odoo code. diff --git a/shopinvader_address/readme/USAGE.rst b/shopinvader_address/readme/USAGE.rst new file mode 100644 index 0000000000..8c073146f4 --- /dev/null +++ b/shopinvader_address/readme/USAGE.rst @@ -0,0 +1,31 @@ +BillingAddress + In the context of shopinvader, the ``BillingAddress`` corresponds to the authenticated partner itself. + Therefore, the ``Billing Address`` is unique for each partner. + + Creation of ``Billing Address`` is not supported since it corresponds to the authenticated partner. + + It can be updated using: + + .. code-block:: python + + def _update_shopinvader_billing_address(self, vals: dict, address_id: int) -> "ResPartner" + + *Remark: it cannot be modified if it has already been used on a confirmed sale order.* + +ShippingAddress + In the context of shopinvader, a ``ShippingAddress`` corresponds to any delivery address linked to the authenticated partner. + A partner can have between 0 and n ``ShippingAddress``. + + It can be created using: + + .. code-block:: python + + def _create_shopinvader_shipping_address(self, vals: dict) -> "ResPartner": + + It can be updated using: + + .. code-block:: python + + def _update_shopinvader_shipping_address(self, vals: dict, address_id: int) -> "ResPartner": + + *Remark: it cannot be modified if it has already been used on a confirmed sale order.* diff --git a/shopinvader_address/static/description/index.html b/shopinvader_address/static/description/index.html new file mode 100644 index 0000000000..06d1cc74d7 --- /dev/null +++ b/shopinvader_address/static/description/index.html @@ -0,0 +1,447 @@ + + + + + + +Shopinvader Address + + + +
+

Shopinvader Address

+ + +

Beta License: AGPL-3 shopinvader/odoo-shopinvader

+

This addons adds helper methos on the res.partner model that ease the management +and the creation of addresses within odoo code.

+

Table of contents

+ +
+

Usage

+
+
BillingAddress
+

In the context of shopinvader, the BillingAddress corresponds to the authenticated partner itself. +Therefore, the Billing Address is unique for each partner.

+

Creation of Billing Address is not supported since it corresponds to the authenticated partner.

+

It can be updated using:

+
+def _update_shopinvader_billing_address(self, vals: dict, address_id: int) -> "ResPartner"
+
+

Remark: it cannot be modified if it has already been used on a confirmed sale order.

+
+
ShippingAddress
+

In the context of shopinvader, a ShippingAddress corresponds to any delivery address linked to the authenticated partner. +A partner can have between 0 and n ShippingAddress.

+

It can be created using:

+
+def _create_shopinvader_shipping_address(self, vals: dict) -> "ResPartner":
+
+

It can be updated using:

+
+def _update_shopinvader_shipping_address(self, vals: dict, address_id: int) -> "ResPartner":
+
+

Remark: it cannot be modified if it has already been used on a confirmed sale order.

+
+
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

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

Contributors

+ +
+
+

Maintainers

+

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

+

You are welcome to contribute.

+
+
+
+ + diff --git a/shopinvader_api_address/README.rst b/shopinvader_api_address/README.rst new file mode 100644 index 0000000000..4a5beecf49 --- /dev/null +++ b/shopinvader_api_address/README.rst @@ -0,0 +1,61 @@ +======================= +Shopinvader Address Api +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-lightgray.png?logo=github + :target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_api_address + :alt: shopinvader/odoo-shopinvader + +|badge1| |badge2| |badge3| + +This addon adds a web API on top of the res.partner model to ease the management +of addresses from Web frontend. + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Laurent Mignon +* Marie Lejeune +* Stéphane Bidoul +* Zina Rasoamanana + +Maintainers +~~~~~~~~~~~ + +This module is part of the `shopinvader/odoo-shopinvader `_ project on GitHub. + +You are welcome to contribute. diff --git a/shopinvader_api_address/__init__.py b/shopinvader_api_address/__init__.py new file mode 100644 index 0000000000..78ebce7be9 --- /dev/null +++ b/shopinvader_api_address/__init__.py @@ -0,0 +1,2 @@ +from . import routers +from . import schemas diff --git a/shopinvader_api_address/__manifest__.py b/shopinvader_api_address/__manifest__.py new file mode 100644 index 0000000000..6d0ebf2da8 --- /dev/null +++ b/shopinvader_api_address/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Address Api", + "summary": """ + Adds a service to manage shopinvader billing and shipping address""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "extendable", + "extendable_fastapi", + "fastapi", + "shopinvader_address", + "shopinvader_schema_address", + ], + "data": [ + "security/res_groups.xml", + "security/res_partner.xml", + ], + "external_dependencies": {"python": ["fastapi", "extendable_pydantic", "pydantic"]}, + "installable": True, +} diff --git a/shopinvader_api_address/readme/CONTRIBUTORS.rst b/shopinvader_api_address/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..49726552ac --- /dev/null +++ b/shopinvader_api_address/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Laurent Mignon +* Marie Lejeune +* Stéphane Bidoul +* Zina Rasoamanana diff --git a/shopinvader_api_address/readme/DESCRIPTION.rst b/shopinvader_api_address/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..9c0e587fc4 --- /dev/null +++ b/shopinvader_api_address/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This addon adds a web API on top of the res.partner model to ease the management +of addresses from Web frontend. diff --git a/shopinvader_api_address/routers/__init__.py b/shopinvader_api_address/routers/__init__.py new file mode 100644 index 0000000000..16dedd61bd --- /dev/null +++ b/shopinvader_api_address/routers/__init__.py @@ -0,0 +1,2 @@ +from .address_service import address_router +from . import address_service diff --git a/shopinvader_api_address/routers/address_service.py b/shopinvader_api_address/routers/address_service.py new file mode 100644 index 0000000000..693efaf422 --- /dev/null +++ b/shopinvader_api_address/routers/address_service.py @@ -0,0 +1,164 @@ +from typing import Annotated, List + +from fastapi import APIRouter, Depends + +from odoo.addons.base.models.res_partner import Partner as ResPartner +from odoo.addons.fastapi.dependencies import authenticated_partner +from odoo.addons.shopinvader_schema_address.schemas import ( + BillingAddress, + ShippingAddress, +) + +from ..schemas import ( + BillingAddressCreate, + BillingAddressUpdate, + ShippingAddressCreate, + ShippingAddressUpdate, +) + +# create a router +address_router = APIRouter(tags=["addresses"]) + +# --- Billing addresses --- + + +@address_router.get("/addresses/billing", response_model=List[BillingAddress]) +def get_billing_addresses( + partner: Annotated[ResPartner, Depends(authenticated_partner)], +) -> List[BillingAddress]: + """ + Get billing address of authenticated user + billing address corresponds to authenticated partner + """ + address = partner._get_shopinvader_billing_addresses() + return [BillingAddress.from_res_partner(rec) for rec in address] + + +@address_router.get("/addresses/billing/{address_id}", response_model=BillingAddress) +def get_billing_address( + partner: Annotated[ResPartner, Depends(authenticated_partner)], + address_id: int, +) -> BillingAddress: + """ + Get billing address of authenticated user with specific address_id + billing address corresponds to authenticated partner + """ + address = partner._get_shopinvader_billing_address(address_id) + return BillingAddress.from_res_partner(address) + + +@address_router.post( + "/addresses/billing", response_model=BillingAddress, status_code=201 +) +def create_billing_address( + data: BillingAddressCreate, + partner: Annotated[ResPartner, Depends(authenticated_partner)], +) -> BillingAddress: + """ + Create billing address + Raise error since billing address is the authenticated partner + """ + vals = data.to_res_partner_vals() + address = partner._create_shopinvader_billing_address(vals) + return BillingAddress.from_res_partner(address) + + +@address_router.post("/addresses/billing/{address_id}", response_model=BillingAddress) +def update_billing_address( + data: BillingAddressUpdate, + partner: Annotated[ResPartner, Depends(authenticated_partner)], + address_id: int, +) -> BillingAddress: + """ + Update billing address of authenticated user + billing address corresponds to authenticated partner + """ + vals = data.to_res_partner_vals() + # sudo() is needed because some addons override the write + # function of res.partner to do some checks before writing. + # These checks need more rights than what we are giving to + # the enspoint's user + # (e.g. snailmail/models/res_partner.py) + address = partner.sudo()._update_shopinvader_billing_address(vals, address_id) + return BillingAddress.from_res_partner(address) + + +# --- Shipping address --- + + +@address_router.get("/addresses/shipping", response_model=List[ShippingAddress]) +def get_shipping_addresses( + partner: Annotated[ResPartner, Depends(authenticated_partner)], +) -> List[ShippingAddress]: + """ + Get shipping addresses of authenticated user + Can be used to get every shipping address: /addresses/shipping + """ + addresses = partner._get_shopinvader_shipping_addresses() + return [ShippingAddress.from_res_partner(rec) for rec in addresses] + + +@address_router.get("/addresses/shipping/{address_id}", response_model=ShippingAddress) +def get_shipping_address( + partner: Annotated[ResPartner, Depends(authenticated_partner)], + address_id: int, +) -> ShippingAddress: + """ + Get shipping addresses of authenticated user + Can be used to get one specific address: /addresses/shipping/address_id + """ + addresses = partner._get_shopinvader_shipping_address(address_id) + return ShippingAddress.from_res_partner(addresses) + + +@address_router.post( + "/addresses/shipping", response_model=ShippingAddress, status_code=201 +) +def create_shipping_address( + data: ShippingAddressCreate, + partner: Annotated[ResPartner, Depends(authenticated_partner)], +) -> ShippingAddress: + """ + Create shipping address of authenticated user + """ + vals = data.to_res_partner_vals() + address = partner._create_shopinvader_shipping_address(vals) + + return ShippingAddress.from_res_partner(address) + + +@address_router.post("/addresses/shipping/{address_id}", response_model=ShippingAddress) +def update_shipping_address( + data: ShippingAddressUpdate, + partner: Annotated[ResPartner, Depends(authenticated_partner)], + address_id: int, +) -> ShippingAddress: + """ + Update shipping address of authenticated user + """ + vals = data.to_res_partner_vals() + # sudo() is needed because some addons override the write + # function of res.partner to do some checks before writing. + # These checks need more rights than what we are giving to + # the enspoint's user + # (e.g. snailmail/models/res_partner.py) + address = partner.sudo()._update_shopinvader_shipping_address(vals, address_id) + return ShippingAddress.from_res_partner(address) + + +@address_router.delete("/addresses/shipping/{address_id}") +def delete_shipping_address( + address_id: int, + partner: Annotated[ResPartner, Depends(authenticated_partner)], +) -> None: + """ + Delete shipping address of authenticated user + Address will be archived. + """ + + # sudo() is needed because some addons override the write + # function of res.partner to do some checks before writing. + # These checks need more rights than what we are giving to + # the enspoint's user + # (e.g. snailmail/models/res_partner.py) + partner.sudo()._delete_shopinvader_shipping_address(address_id) diff --git a/shopinvader_api_address/schemas.py b/shopinvader_api_address/schemas.py new file mode 100644 index 0000000000..c70ed751ec --- /dev/null +++ b/shopinvader_api_address/schemas.py @@ -0,0 +1,119 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from extendable_pydantic import ExtendableModelMeta +from pydantic import BaseModel + + +class AddressCreate(BaseModel, metaclass=ExtendableModelMeta): + """ + used to create new address (res.partner) + state and country can be name or code + """ + + name: str | None + street: str | None + street2: str | None + zip: str | None + city: str | None + phone: str | None + email: str | None + state_id: int | None + country_id: int | None + + def to_res_partner_vals(self) -> dict: + vals = { + "name": self.name, + "street": self.street, + "street2": self.street2, + "zip": self.zip, + "city": self.city, + "phone": self.phone, + "email": self.email, + "state_id": self.state_id, + "country_id": self.country_id, + } + + return vals + + +class AddressUpdate(BaseModel, metaclass=ExtendableModelMeta): + """ + used to update address (res.partner) + state and country can be name or code + """ + + name: str | None + street: str | None + street2: str | None + zip: str | None + city: str | None + phone: str | None + email: str | None + state_id: int | None + country_id: int | None + + def to_res_partner_vals(self) -> dict: + vals = { + "name": self.name, + "street": self.street, + "street2": self.street2, + "zip": self.zip, + "city": self.city, + "phone": self.phone, + "email": self.email, + "state_id": self.state_id, + "country_id": self.country_id, + } + + return vals + + +# --- Billing Address --- +class BillingAddressCreate(AddressUpdate): + """ + Creation of Billing Address + + Remark: it is actually not used since + the billing address is the authenticated + partner's address + """ + + vat: str | None + + def to_res_partner_vals(self) -> dict: + vals = super().to_res_partner_vals() + + vals["vat"] = self.vat + + return vals + + +class BillingAddressUpdate(AddressUpdate): + """ + Update of Billing Address + """ + + vat: str | None + + def to_res_partner_vals(self) -> dict: + vals = super().to_res_partner_vals() + + vals["vat"] = self.vat + + return vals + + +# --- Shipping Address --- + + +class ShippingAddressCreate(AddressUpdate): + """ + Creation of Shipping Address + """ + + +class ShippingAddressUpdate(AddressUpdate): + """ + Update of Shipping Address + """ diff --git a/shopinvader_api_address/security/res_groups.xml b/shopinvader_api_address/security/res_groups.xml new file mode 100644 index 0000000000..2f1a13724f --- /dev/null +++ b/shopinvader_api_address/security/res_groups.xml @@ -0,0 +1,16 @@ + + + + + Shopinvader Address user + + + + + diff --git a/shopinvader_api_address/security/res_partner.xml b/shopinvader_api_address/security/res_partner.xml new file mode 100644 index 0000000000..6a2251767a --- /dev/null +++ b/shopinvader_api_address/security/res_partner.xml @@ -0,0 +1,27 @@ + + + + + + Shopinvader Address Endpoint rule: res partner + + + [('parent_id','=',authenticated_partner_id)] + + + + + Shopinvader Address: user read/write/create partners + + + + + + + + + diff --git a/shopinvader_api_address/static/description/icon.png b/shopinvader_api_address/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dC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??gSzdp?6Uug9{ zd@V08Z$BdI?fpoCS$)t4mg4rT8Q_I}h`0d-vYZ^|dOB*Q^S|xqTV*vIg?@fVFSmMpaw0qtTRbx} z({Pg?#{2`sc9)M5N$*N|4;^t$+QP?#mov zGVC@I*lBVrOU-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/shopinvader_api_address/static/description/index.html b/shopinvader_api_address/static/description/index.html new file mode 100644 index 0000000000..67e3ce2025 --- /dev/null +++ b/shopinvader_api_address/static/description/index.html @@ -0,0 +1,418 @@ + + + + + + +Shopinvader Address Api + + + +
+

Shopinvader Address Api

+ + +

Beta License: AGPL-3 shopinvader/odoo-shopinvader

+

This addon adds a web API on top of the res.partner model to ease the management +of addresses from Web frontend.

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

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

Contributors

+ +
+
+

Maintainers

+

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

+

You are welcome to contribute.

+
+
+
+ + diff --git a/shopinvader_api_address/tests/__init__.py b/shopinvader_api_address/tests/__init__.py new file mode 100644 index 0000000000..3230279a9a --- /dev/null +++ b/shopinvader_api_address/tests/__init__.py @@ -0,0 +1 @@ +from . import test_shopinvader_address_api diff --git a/shopinvader_api_address/tests/test_shopinvader_address_api.py b/shopinvader_api_address/tests/test_shopinvader_address_api.py new file mode 100644 index 0000000000..b898366e38 --- /dev/null +++ b/shopinvader_api_address/tests/test_shopinvader_address_api.py @@ -0,0 +1,336 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import json + +from fastapi import status +from requests import Response + +from odoo.tests.common import tagged + +from odoo.addons.extendable_fastapi.tests.common import FastAPITransactionCase + +from ..routers import address_router + + +@tagged("post_install", "-at_install") +class TestShopinvaderAddressApi(FastAPITransactionCase): + @classmethod + def setUpClass(cls) -> None: + super().setUpClass() + + cls.env["res.users"].create( + { + "name": "Test User", + "login": "test_user", + "groups_id": [ + ( + 6, + 0, + [ + cls.env.ref( + "shopinvader_api_address.shopinvader_address_user_group" + ).id + ], + ) + ], + } + ) + + cls.test_partner = cls.env["res.partner"].create( + { + "name": "FastAPI Shopinvader Address Demo", + "street": "rue test", + "zip": "1410", + "city": "Waterloo", + "country_id": cls.env.ref("base.be").id, + } + ) + + cls.default_fastapi_authenticated_partner = cls.test_partner + cls.default_fastapi_router = address_router + + def test_get_billing_address(self): + """ + Test to get address of authenticated_partner + """ + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.get( + "/addresses/billing", + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + + response_json = response.json() + self.assertTrue(response_json) + + address = response_json[0] + + self.assertEqual(address.get("name"), self.test_partner.name) + self.assertEqual(address.get("street"), self.test_partner.street) + self.assertEqual(address.get("zip"), self.test_partner.zip) + self.assertEqual(address.get("city"), self.test_partner.city) + self.assertEqual(address.get("country_id"), self.test_partner.country_id.id) + self.assertEqual(address.get("id"), self.test_partner.id) + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.get( + f"/addresses/billing/{self.test_partner.id}", + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + + response_json = response.json() + self.assertTrue(response_json) + + address = response_json + + self.assertEqual(address.get("name"), self.test_partner.name) + self.assertEqual(address.get("street"), self.test_partner.street) + self.assertEqual(address.get("zip"), self.test_partner.zip) + self.assertEqual(address.get("city"), self.test_partner.city) + self.assertEqual(address.get("country_id"), self.test_partner.country_id.id) + self.assertEqual(address.get("id"), self.test_partner.id) + + def test_get_shipping_address(self): + """ + Test to get shipping address of authenticated_partner + """ + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.get( + "/addresses/shipping", + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + + response_json = response.json() + self.assertEqual(0, len(response_json)) + + # add shipping address + new_address = self.env["res.partner"].create( + { + "name": "test New Addr", + "street": "test Street", + "zip": "5000", + "city": "Namur", + "country_id": self.env.ref("base.be").id, + "parent_id": self.test_partner.id, + "type": "delivery", + } + ) + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.get( + "/addresses/shipping", + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + + response_json = response.json() + self.assertTrue(response_json) + + address = response_json[0] + + self.assertEqual(address.get("name"), new_address.name) + self.assertEqual(address.get("street"), new_address.street) + self.assertEqual(address.get("zip"), new_address.zip) + self.assertEqual(address.get("city"), new_address.city) + self.assertEqual(address.get("country_id"), new_address.country_id.id) + self.assertEqual(address.get("id"), new_address.id) + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.get( + f"/addresses/shipping/{new_address.id}", + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + + response_json = response.json() + + address = response_json + + self.assertEqual(address.get("name"), new_address.name) + self.assertEqual(address.get("street"), new_address.street) + self.assertEqual(address.get("zip"), new_address.zip) + self.assertEqual(address.get("city"), new_address.city) + self.assertEqual(address.get("country_id"), new_address.country_id.id) + self.assertEqual(address.get("id"), new_address.id) + + def test_update_billing_address(self): + """ + Test to update billing address + """ + data = { + "name": "FastAPI Shopinvader Address Demo", + "zip": "1410", + "city": "Waterloo", + "country_id": self.env.ref("base.be").id, + "street": "test Street", + } + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.post( + f"/addresses/billing/{self.test_partner.id}", content=json.dumps(data) + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + response_json = response.json() + self.assertTrue(response_json) + + address = response_json + + self.assertEqual(address.get("street"), "test Street") + self.assertEqual(address.get("street"), self.test_partner.street) + + def test_update_billing_address_vat(self): + """ + Test to update billing address vat + """ + data = { + "name": "FastAPI Shopinvader Address Demo", + "zip": "1410", + "city": "Waterloo", + "country_id": self.env.ref("base.be").id, + "street": "rue test", + "vat": "test_vat", + } + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.post( + f"/addresses/billing/{self.test_partner.id}", content=json.dumps(data) + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + response_json = response.json() + self.assertTrue(response_json) + + address = response_json + + self.assertEqual(address.get("vat"), "test_vat") + self.assertEqual(address.get("vat"), self.test_partner.vat) + + def test_create_shipping_address(self): + """ + Test to create shipping address + """ + data = { + "name": "test Addr", + "street": "test Street", + "zip": "5000", + "city": "Namur", + "country_id": self.env.ref("base.be").id, + } + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.post( + "/addresses/shipping", content=json.dumps(data) + ) + + self.assertEqual( + response.status_code, + status.HTTP_201_CREATED, + msg=f"error message: {response.text}", + ) + response_json = response.json() + self.assertTrue(response_json) + + address = response_json + + self.assertEqual(address.get("street"), "test Street") + self.assertNotEqual(address.get("street"), self.test_partner.street) + + def test_delete_shipping_address(self): + """ + Test to delete shipping address + """ + + new_address = self.env["res.partner"].create( + { + "name": "test New Addr", + "street": "test Street", + "zip": "5000", + "city": "Namur", + "country_id": self.env.ref("base.be").id, + "parent_id": self.test_partner.id, + "type": "delivery", + } + ) + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.delete( + f"/addresses/shipping/{new_address.id}", + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + self.assertFalse(new_address.active) + + def test_update_shipping_address(self): + """ + Test to update shipping address + """ + new_address = self.env["res.partner"].create( + { + "name": "test New Addr", + "street": "test Street", + "zip": "5000", + "city": "Namur", + "country_id": self.env.ref("base.be").id, + "parent_id": self.test_partner.id, + "type": "delivery", + } + ) + + data = { + "name": "test Addr2", + "street": "test Street2", + "zip": "5000", + "city": "Namur", + "country_id": self.env.ref("base.be").id, + "parent_id": self.test_partner.id, + "type": "delivery", + } + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.post( + f"/addresses/shipping/{new_address.id}", content=json.dumps(data) + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + self.assertEqual(new_address.name, data.get("name")) + self.assertEqual(new_address.street, data.get("street")) diff --git a/shopinvader_schema_address/README.rst b/shopinvader_schema_address/README.rst new file mode 100644 index 0000000000..9114cc8ff7 --- /dev/null +++ b/shopinvader_schema_address/README.rst @@ -0,0 +1,62 @@ +========================== +Shopinvader Schema Address +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-lightgray.png?logo=github + :target: https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_schema_address + :alt: shopinvader/odoo-shopinvader + +|badge1| |badge2| |badge3| + +This addon adds pydantic schemas that represents Addresses. +It introduces BillingAddress and ShippingAddress as sub classes of Address. +It has been designed and thought to be used in shopinvader services. + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Laurent Mignon +* Marie Lejeune +* Stéphane Bidoul +* Zina Rasoamanana + +Maintainers +~~~~~~~~~~~ + +This module is part of the `shopinvader/odoo-shopinvader `_ project on GitHub. + +You are welcome to contribute. diff --git a/shopinvader_schema_address/__init__.py b/shopinvader_schema_address/__init__.py new file mode 100644 index 0000000000..a51a83a6f8 --- /dev/null +++ b/shopinvader_schema_address/__init__.py @@ -0,0 +1 @@ +from . import schemas diff --git a/shopinvader_schema_address/__manifest__.py b/shopinvader_schema_address/__manifest__.py new file mode 100644 index 0000000000..36203a772b --- /dev/null +++ b/shopinvader_schema_address/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Shopinvader Schema Address", + "summary": """ + Adds shchema address: address billing_address delivery_address""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": [ + "pydantic", + "extendable", + "extendable_fastapi", + ], + "external_dependencies": {"python": ["extendable_pydantic", "pydantic"]}, + "data": [], + "demo": [], + "installable": True, +} diff --git a/shopinvader_schema_address/readme/CONTRIBUTORS.rst b/shopinvader_schema_address/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..49726552ac --- /dev/null +++ b/shopinvader_schema_address/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* Laurent Mignon +* Marie Lejeune +* Stéphane Bidoul +* Zina Rasoamanana diff --git a/shopinvader_schema_address/readme/DESCRIPTION.rst b/shopinvader_schema_address/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..90ee135c67 --- /dev/null +++ b/shopinvader_schema_address/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This addon adds pydantic schemas that represents Addresses. +It introduces BillingAddress and ShippingAddress as sub classes of Address. +It has been designed and thought to be used in shopinvader services. diff --git a/shopinvader_schema_address/schemas.py b/shopinvader_schema_address/schemas.py new file mode 100644 index 0000000000..e3c5def77b --- /dev/null +++ b/shopinvader_schema_address/schemas.py @@ -0,0 +1,60 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from extendable_pydantic import ExtendableModelMeta +from pydantic import BaseModel + +from odoo.addons.pydantic import utils + + +class Address(BaseModel, metaclass=ExtendableModelMeta): + id: int + name: str | None + street: str | None + street2: str | None + zip: str | None + city: str | None + phone: str | None + email: str | None + state_id: int | None + country_id: int | None + + class Config: + orm_mode = True + getter_dict = utils.GenericOdooGetter + + @classmethod + def from_res_partner(cls, odoo_rec): + return cls( + id=odoo_rec.id, + name=odoo_rec.name or None, + 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, + email=odoo_rec.email or None, + state_id=odoo_rec.state_id.id or None, + country_id=odoo_rec.country_id.id or None, + ) + + +class BillingAddress(Address): + """ + Billing Address + """ + + vat: str | None + + @classmethod + def from_res_partner(cls, odoo_rec): + res = super().from_res_partner(odoo_rec) + res.vat = odoo_rec.vat or None + + return res + + +class ShippingAddress(Address): + """ + Shipping Address + """ diff --git a/shopinvader_schema_address/static/description/icon.png b/shopinvader_schema_address/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG0I@qAOHsk$2}yTmVkBp_eHuY$A9)>P6o~I z%aQ?!(GqeQ-Y+b0I(m9pwgi(IIZZzsbMv+9w{PFtd_<_(LA~0H(xz{=FhLB@(1&qHA5EJw1>>=%q2f&^X>IQ{!GJ4e9U z&KlB)z(84HmNgm2hg2C0>WM{E(DdPr+EeU_N@57;PC2&DmGFW_9kP&%?X4}+xWi)( z;)z%wI5>D4a*5XwD)P--sPkoY(a~WBw;E~AW`Yue4kFa^LM3X`8x|}ZUeMnqr}>kH zG%WWW>3ml$Yez?i%)2pbKPI7?5o?hydokgQyZsNEr{a|mLdt;X2TX(#B1j35xPnPW z*bMSSOauW>o;*=kO8ojw91VX!qoOQb)zHJ!odWB}d+*K?#sY_jqPdg{Sm2HdYzdEx zOGVPhVRTGPtv0o}RfVP;Nd(|CB)I;*t&QO8h zFfekr30S!-LHmV_Su-W+rEwYXJ^;6&3|L$mMC8*bQptyOo9;>Qb9Q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wmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/shopinvader_schema_address/static/description/index.html b/shopinvader_schema_address/static/description/index.html new file mode 100644 index 0000000000..a44c04d92e --- /dev/null +++ b/shopinvader_schema_address/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Shopinvader Schema Address + + + +
+

Shopinvader Schema Address

+ + +

Beta License: AGPL-3 shopinvader/odoo-shopinvader

+

This addon adds pydantic schemas that represents Addresses. +It introduces BillingAddress and ShippingAddress as sub classes of Address. +It has been designed and thought to be used in shopinvader services.

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

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

Contributors

+ +
+
+

Maintainers

+

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

+

You are welcome to contribute.

+
+
+
+ + From 3b55bd476b54dbaeb65f441857f91b740a04624e Mon Sep 17 00:00:00 2001 From: mle Date: Wed, 26 Jul 2023 08:18:51 +0200 Subject: [PATCH 2/2] Migration to Pydantic v2 --- requirements.txt | 4 +-- shopinvader_api_address/__manifest__.py | 4 ++- shopinvader_api_address/schemas.py | 40 +++++++++++----------- shopinvader_schema_address/__manifest__.py | 4 ++- shopinvader_schema_address/schemas.py | 29 +++++++--------- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/requirements.txt b/requirements.txt index 893abd9d60..a0f722a6d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # generated from manifests external_dependencies -extendable_pydantic +extendable_pydantic>=1.0.0 fastapi openupgradelib -pydantic +pydantic>=2.0.0 diff --git a/shopinvader_api_address/__manifest__.py b/shopinvader_api_address/__manifest__.py index 6d0ebf2da8..47c5fee51a 100644 --- a/shopinvader_api_address/__manifest__.py +++ b/shopinvader_api_address/__manifest__.py @@ -20,6 +20,8 @@ "security/res_groups.xml", "security/res_partner.xml", ], - "external_dependencies": {"python": ["fastapi", "extendable_pydantic", "pydantic"]}, + "external_dependencies": { + "python": ["fastapi", "extendable_pydantic>=1.0.0", "pydantic>=2.0.0"] + }, "installable": True, } diff --git a/shopinvader_api_address/schemas.py b/shopinvader_api_address/schemas.py index c70ed751ec..7d08c22a69 100644 --- a/shopinvader_api_address/schemas.py +++ b/shopinvader_api_address/schemas.py @@ -11,15 +11,15 @@ class AddressCreate(BaseModel, metaclass=ExtendableModelMeta): state and country can be name or code """ - name: str | None - street: str | None - street2: str | None - zip: str | None - city: str | None - phone: str | None - email: str | None - state_id: int | None - country_id: int | None + name: str | None = None + street: str | None = None + street2: str | None = None + zip: str | None = None + city: str | None = None + phone: str | None = None + email: str | None = None + state_id: int | None = None + country_id: int | None = None def to_res_partner_vals(self) -> dict: vals = { @@ -43,15 +43,15 @@ class AddressUpdate(BaseModel, metaclass=ExtendableModelMeta): state and country can be name or code """ - name: str | None - street: str | None - street2: str | None - zip: str | None - city: str | None - phone: str | None - email: str | None - state_id: int | None - country_id: int | None + name: str | None = None + street: str | None = None + street2: str | None = None + zip: str | None = None + city: str | None = None + phone: str | None = None + email: str | None = None + state_id: int | None = None + country_id: int | None = None def to_res_partner_vals(self) -> dict: vals = { @@ -79,7 +79,7 @@ class BillingAddressCreate(AddressUpdate): partner's address """ - vat: str | None + vat: str | None = None def to_res_partner_vals(self) -> dict: vals = super().to_res_partner_vals() @@ -94,7 +94,7 @@ class BillingAddressUpdate(AddressUpdate): Update of Billing Address """ - vat: str | None + vat: str | None = None def to_res_partner_vals(self) -> dict: vals = super().to_res_partner_vals() diff --git a/shopinvader_schema_address/__manifest__.py b/shopinvader_schema_address/__manifest__.py index 36203a772b..a46dfe2639 100644 --- a/shopinvader_schema_address/__manifest__.py +++ b/shopinvader_schema_address/__manifest__.py @@ -14,7 +14,9 @@ "extendable", "extendable_fastapi", ], - "external_dependencies": {"python": ["extendable_pydantic", "pydantic"]}, + "external_dependencies": { + "python": ["extendable_pydantic>=1.0.0", "pydantic>=2.0.0"] + }, "data": [], "demo": [], "installable": True, diff --git a/shopinvader_schema_address/schemas.py b/shopinvader_schema_address/schemas.py index e3c5def77b..f5fe51d90c 100644 --- a/shopinvader_schema_address/schemas.py +++ b/shopinvader_schema_address/schemas.py @@ -2,26 +2,21 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from extendable_pydantic import ExtendableModelMeta -from pydantic import BaseModel - -from odoo.addons.pydantic import utils +from pydantic import BaseModel, ConfigDict class Address(BaseModel, metaclass=ExtendableModelMeta): id: int - name: str | None - street: str | None - street2: str | None - zip: str | None - city: str | None - phone: str | None - email: str | None - state_id: int | None - country_id: int | None - - class Config: - orm_mode = True - getter_dict = utils.GenericOdooGetter + name: str | None = None + street: str | None = None + street2: str | None = None + zip: str | None = None + city: str | None = None + phone: str | None = None + email: str | None = None + state_id: int | None = None + country_id: int | None = None + model_config: ConfigDict = ConfigDict(from_attributes=True) @classmethod def from_res_partner(cls, odoo_rec): @@ -44,7 +39,7 @@ class BillingAddress(Address): Billing Address """ - vat: str | None + vat: str | None = None @classmethod def from_res_partner(cls, odoo_rec):