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

[WIP][14][BACKPORT] shopinvader api address #1380

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7d6b05b
[ADD] addon shopinvader_schema_address: init
AnizR Jun 6, 2023
a8d231d
WIP
AnizR Jun 7, 2023
f250fa5
wip
AnizR Jun 7, 2023
ce344b6
work in progress..
AnizR Jun 7, 2023
ca18587
wip
AnizR Jun 18, 2023
119a312
wip
AnizR Jun 20, 2023
512f58e
wip
AnizR Jun 20, 2023
d933077
change requests
AnizR Jun 20, 2023
b23dc55
wip
AnizR Jun 20, 2023
7f4d8a0
wip
AnizR Jun 21, 2023
391d063
wip: add addres_billing/shipping get/create
AnizR Jun 21, 2023
a4aba02
update shipping address
AnizR Jun 21, 2023
6625910
wip
AnizR Jun 21, 2023
8d78304
wip
AnizR Jun 21, 2023
5cb957c
work on tests + use country/state_id + work on address schemas
AnizR Jun 21, 2023
c609928
rename address service
AnizR Jun 21, 2023
ef57b86
add minimal security
AnizR Jun 21, 2023
a73ef0d
add minimal security 2
AnizR Jun 21, 2023
5251f3c
test a mapper
AnizR Jun 22, 2023
cda0906
extract service logic from model
AnizR Jun 22, 2023
03935b2
extract shopinvader_address
AnizR Jun 22, 2023
9dfa272
wip
AnizR Jun 22, 2023
9bafac0
wip
AnizR Jun 22, 2023
8e82e5f
wip tag
AnizR Jun 22, 2023
a8f2ed0
add tag
AnizR Jun 22, 2023
5852caa
some clean up
AnizR Jun 22, 2023
7e3c56a
some refactoring
AnizR Jun 22, 2023
b2e5c27
wip
AnizR Jun 23, 2023
7ee28be
wip
AnizR Jun 23, 2023
a79fff6
some improvements + sudo on service write
AnizR Jun 23, 2023
d3b78f6
add vat on billing address
AnizR Jun 23, 2023
cdb095f
split create/update shipping address
AnizR Jun 23, 2023
5b48e95
update schema
AnizR Jun 23, 2023
08ca806
check before update/delete shipping address
AnizR Jun 23, 2023
b2e73e1
add httpx in test requirements
AnizR Jun 23, 2023
3ab9702
readme shopinvader_schema_address
AnizR Jun 23, 2023
0f713d4
shopinvader_api_address readme
AnizR Jun 23, 2023
79e925d
shopinvader_address: readme
AnizR Jun 23, 2023
f7591c1
pre-commit
AnizR Jun 23, 2023
99c1bb6
add creation method of billing address
AnizR Jun 23, 2023
2417004
[FIX] shopinvader_api_address_*: Uses new helper class to run tests w…
lmignon Jun 26, 2023
809b6e5
rename service functions
AnizR Jun 26, 2023
f811d68
refactor raised error in shopinvader_address
AnizR Jun 26, 2023
c63013e
add dependencies test-requirements
AnizR Jun 26, 2023
322ecbe
get on billing address
AnizR Jun 26, 2023
8752151
split get service of billing and shipping in 2
AnizR Jun 26, 2023
08b2c16
clean up raises
AnizR Jun 26, 2023
8118177
fixup: remove demo in manifest + change in comments
AnizR Jun 27, 2023
0a0b8f0
[IMP] backport address services from 16.0 : black, isort, prettier
xavier-bouquiaux Jun 29, 2023
ff4c672
[14.0][BACKPORT] shopinvader fastapi address services
xavier-bouquiaux Jun 29, 2023
d5ed450
[WIP] add dependcy to pr on fastapi -> needed for v14 -> will be remo…
xavier-bouquiaux Jun 30, 2023
8e3546c
remove dependencie to shopinvader_schema_address -> useless
xavier-bouquiaux Jun 30, 2023
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
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# generated from manifests external_dependencies
cerberus
extendable_pydantic
fastapi
locomotivecms
pydantic
python-magic
python-slugify
python-stdnum
Expand Down
1 change: 1 addition & 0 deletions setup/shopinvader_address/odoo/addons/shopinvader_address
6 changes: 6 additions & 0 deletions setup/shopinvader_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,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_api_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,
)
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,
)
96 changes: 96 additions & 0 deletions shopinvader_address/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/shopinvader/odoo-shopinvader/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 <https://github.com/shopinvader/odoo-shopinvader/issues/new?body=module:%20shopinvader_address%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
~~~~~~~

* ACSONE SA/NV

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

* Laurent Mignon <[email protected]>
* Marie Lejeune <[email protected]>
* Stéphane Bidoul <[email protected]>
* Zina Rasoamanana <[email protected]>

Maintainers
~~~~~~~~~~~

This module is part of the `shopinvader/odoo-shopinvader <https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_address>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions shopinvader_address/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions shopinvader_address/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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": "14.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"depends": [
"sale",
],
"data": [],
"demo": [],
}
1 change: 1 addition & 0 deletions shopinvader_address/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
163 changes: 163 additions & 0 deletions shopinvader_address/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -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)
)
4 changes: 4 additions & 0 deletions shopinvader_address/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Laurent Mignon <[email protected]>
* Marie Lejeune <[email protected]>
* Stéphane Bidoul <[email protected]>
* Zina Rasoamanana <[email protected]>
2 changes: 2 additions & 0 deletions shopinvader_address/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This addons adds helper methods on the res.partner model that ease the management
and the creation of addresses within odoo code.
31 changes: 31 additions & 0 deletions shopinvader_address/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.*
Loading