-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by lmignon
- Loading branch information
Showing
38 changed files
with
2,532 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../shopinvader_address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 1 addition & 0 deletions
1
setup/shopinvader_api_address/odoo/addons/shopinvader_api_address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../shopinvader_api_address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 1 addition & 0 deletions
1
setup/shopinvader_schema_address/odoo/addons/shopinvader_schema_address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../shopinvader_schema_address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.* |
Oops, something went wrong.