Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] addon shopinvader_api_address #1361

Merged
merged 2 commits into from
Jul 30, 2023
Merged
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
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# generated from manifests external_dependencies
extendable_pydantic>=1.0.0
fastapi
openupgradelib
pydantic>=2.0.0
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": "16.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,
)
AnizR marked this conversation as resolved.
Show resolved Hide resolved
)

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
sbidoul marked this conversation as resolved.
Show resolved Hide resolved

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,
)
)
AnizR marked this conversation as resolved.
Show resolved Hide resolved
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)
AnizR marked this conversation as resolved.
Show resolved Hide resolved
)
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 methos 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
Loading