Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AnizR committed Jun 7, 2023
1 parent 752e7d5 commit c48067e
Show file tree
Hide file tree
Showing 26 changed files with 176 additions and 23 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# generated from manifests external_dependencies
extendable_pydantic
fastapi
pydantic
File renamed without changes.
6 changes: 6 additions & 0 deletions setup/shopinvader_schema_address/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,
)
1 change: 0 additions & 1 deletion setup/si_schema_address/odoo/addons/si_schema_address

This file was deleted.

2 changes: 2 additions & 0 deletions shopinvader_api_address/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import services
from . import models
21 changes: 21 additions & 0 deletions shopinvader_api_address/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Shopinvader Api Address",
"summary": """
Adds profile and address Fastapi""",
"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": [
"fastapi",
"shopinvader_schema_address",
"extendable_fastapi",
],
"data": [],
"demo": [],
"external_dependencies": {"python": ["fastapi", "extendable_pydantic", "pydantic"]},
"installable": True,
}
1 change: 1 addition & 0 deletions shopinvader_api_address/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import fast_api_endpoint
25 changes: 25 additions & 0 deletions shopinvader_api_address/models/fast_api_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from fastapi import APIRouter

from odoo import api, fields, models


class FastapiEndpoint(models.Model):

_inherit = "fastapi.endpoint"

app: str = fields.Selection(
selection_add=[("address", "Address Endpoint")], ondelete={"address": "cascade"}
)

@api.model
def _get_fastapi_routers(self):
if self.app == "address":
return [address_api_router]
return super().get_fastapi_routers()


# create a router
address_api_router = APIRouter()
10 changes: 10 additions & 0 deletions shopinvader_api_address/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ This file is optional, it should explain how to configure
the module before using it; it is aimed at advanced users. ]

To configure this module, you need to:

#. Go to ...

.. figure:: ../static/description/image.png
:alt: alternative description
:width: 600 px
2 changes: 2 additions & 0 deletions shopinvader_api_address/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Firstname Lastname <[email protected]> (optional company website url)
* Second Person <[email protected]> (optional company website url)
7 changes: 7 additions & 0 deletions shopinvader_api_address/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[ This file is optional and contains additional credits, other than
authors, contributors, and maintainers. ]

The development of this module has been financially supported by:

* Company 1 name
* Company 2 name
4 changes: 4 additions & 0 deletions shopinvader_api_address/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ This file must be max 2-3 paragraphs, and is required. ]

This module extends the functionality of ... to support ...
and to allow you to ...
24 changes: 24 additions & 0 deletions shopinvader_api_address/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[ The change log. The goal of this file is to help readers
understand changes between version. The primary audience is
end users and integrators. Purely technical changes such as
code refactoring must not be mentioned here.

This file may contain ONE level of section titles, underlined
with the ~ (tilde) character. Other section markers are
forbidden and will likely break the structure of the README.rst
or other documents where this fragment is included. ]

11.0.x.y.z (YYYY-MM-DD)
~~~~~~~~~~~~~~~~~~~~~~~

* [BREAKING] Breaking changes come first.
(`#70 <https://github.com/OCA/repo/issues/70>`_)
* [ADD] New feature.
(`#74 <https://github.com/OCA/repo/issues/74>`_)
* [FIX] Correct this.
(`#71 <https://github.com/OCA/repo/issues/71>`_)

11.0.x.y.z (YYYY-MM-DD)
~~~~~~~~~~~~~~~~~~~~~~~

* ...
7 changes: 7 additions & 0 deletions shopinvader_api_address/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[ This file must only be present if there are very specific
installation instructions, such as installing non-python
dependencies. The audience is systems administrators. ]

To install this module, you need to:

#. Do this ...
5 changes: 5 additions & 0 deletions shopinvader_api_address/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ Enumerate known caveats and future potential improvements.
It is mostly intended for end-users, and can also help
potential new contributors discovering new features to implement. ]

* ...
11 changes: 11 additions & 0 deletions shopinvader_api_address/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ This file must be present and contains the usage instructions
for end-users. As all other rst files included in the README,
it MUST NOT contain reStructuredText sections
only body text (paragraphs, lists, tables, etc). Should you need
a more elaborate structure to explain the addon, please create a
Sphinx documentation (which may include this file as a "quick start"
section). ]

To use this module, you need to:

#. Go to ...
1 change: 1 addition & 0 deletions shopinvader_api_address/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import address_service
25 changes: 25 additions & 0 deletions shopinvader_api_address/services/address_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from fastapi import Depends

from odoo.api import Environment

from odoo.addons.fastapi.depends import odoo_env, paging
from odoo.addons.fastapi.schemas import PagedCollection, Paging
from odoo.addons.shopinvader_schema_address.schema.address import Address

from ..models.fast_api_endpoint import address_api_router


@address_api_router.get("/", response_model=PagedCollection[Address])
def get_address(
paging: Paging = Depends(paging),
env: Environment = Depends(odoo_env), # use authenticated_partner_env
) -> PagedCollection[Address]:
"""Get the list of Address"""
count = env["res.partner"].search_count([])
partners = (
env["res.partner"].sudo().search([], limit=paging.limit, offset=paging.offset)
)
return PagedCollection[Address](
total=count,
items=[Address.from_orm(rec) for rec in partners],
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion shopinvader_schema_address/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import schema
from . import schema
20 changes: 10 additions & 10 deletions shopinvader_schema_address/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Shopinvader Schema Address',
'summary': """
"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,Odoo Community Association (OCA)',
'website': 'https://github.com/shopinvader/odoo-shopinvader',
"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": [
"pydantic",
"extendable",
"extendable_fastapi",
"fastapi", # to remove?
],
"external_dependencies": {"python": ["extendable_pydantic", "pydantic"]},
'data': [
],
'demo': [
],
"data": [],
"demo": [],
"installable": True,
}
1 change: 0 additions & 1 deletion shopinvader_schema_address/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

This module extends the functionality of ... to support ...
and to allow you to ...

6 changes: 3 additions & 3 deletions shopinvader_schema_address/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[ The change log. The goal of this file is to help readers
understand changes between version. The primary audience is
end users and integrators. Purely technical changes such as
code refactoring must not be mentioned here.
code refactoring must not be mentioned here.

This file may contain ONE level of section titles, underlined
with the ~ (tilde) character. Other section markers are
with the ~ (tilde) character. Other section markers are
forbidden and will likely break the structure of the README.rst
or other documents where this fragment is included. ]

Expand Down
15 changes: 8 additions & 7 deletions shopinvader_schema_address/schema/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import pydantic

from typing import Optional

from extendable_pydantic import ExtendableModelMeta
from pydantic import BaseModel

from odoo.addons.pydantic import utils


class State(BaseModel, metaclass=ExtendableModelMeta):
id: int
name: str
code: str

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter


class Country(BaseModel, metaclass=ExtendableModelMeta):
id: int
name: str
code: str

class Config:
orm_mode = True
getter_dict = utils.GenericOdooGetter
Expand All @@ -30,12 +31,12 @@ class Config:
class Address(BaseModel, metaclass=ExtendableModelMeta):
name: str
street: str
street2: Optional[str] = None
street2: str | None = None
zip: str
city: str
phone: Optional[str] = None
email: Optional[str] = None
state: Optional[State] = pydantic.Field(alias="state_id") or None
phone: str | None = None
email: str | None = None
state: State | None = pydantic.Field(alias="state_id")
country: Country = pydantic.Field(alias="country_id")

class Config:
Expand Down

0 comments on commit c48067e

Please sign in to comment.