Skip to content

Commit

Permalink
[17.0][ADD]: partner_contact_block_invoice_address
Browse files Browse the repository at this point in the history
  • Loading branch information
ilo committed Sep 24, 2024
1 parent 546003e commit 9b9ed14
Show file tree
Hide file tree
Showing 15 changed files with 728 additions and 0 deletions.
88 changes: 88 additions & 0 deletions partner_contact_block_invoice_address/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
==================================
Partner block invoice address type
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a5227b4dd58736e4aa51cccff5d71349aecb02920b9fa021ad7193f5fccfd304
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-OCA%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/17.0/partner_contact_block_invoice_address
:alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/partner-contact-17-0/partner-contact-17-0-partner_contact_block_invoice_address
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module was written to allow the user to block the creation of
invoice address type.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module :

1. Go to Settings > Configuration > General Settings
2. Check the box "Partner Block Invoice Address" in the "Block Invoice
Address Type" section
3. Set the default type of address to set when creating a new partner

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_contact_block_invoice_address%0Aversion:%2017.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
-------

* Camptocamp
* Italo LOPES

Contributors
------------

- Italo LOPES <italo.lopes@camptocamp.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/17.0/partner_contact_block_invoice_address>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions partner_contact_block_invoice_address/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions partner_contact_block_invoice_address/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

{
"name": "Partner block invoice address type",
"summary": "Partner block invoice address type",
"version": "17.0.1.0.0",
"author": "Camptocamp, " "Italo LOPES, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"maintainer": "Camptocamp",
"category": "Extra Tools",
"website": "https://github.com/OCA/partner-contact",
"depends": ["base_setup"],
"data": [
"views/base_config_view.xml",
],
"auto_install": False,
"installable": True,
}
2 changes: 2 additions & 0 deletions partner_contact_block_invoice_address/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import base_config_settings
from . import res_partner
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

partner_block_invoice_address = fields.Boolean(
config_parameter="partner_block_invoice_address"
)
partner_block_invoice_address_default_type = fields.Selection(
[
("contact", "Contact"),
("delivery", "Delivery Address"),
("other", "Other Address"),
],
default="other",
config_parameter="partner_block_invoice_address_default_type",
)
71 changes: 71 additions & 0 deletions partner_contact_block_invoice_address/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)


from odoo import _, api, models
from odoo.exceptions import UserError


class ResPartner(models.Model):
_inherit = "res.partner"

def _check_setting_block_invoice_address(self):
partner_block_invoice_address = (
self.env["ir.config_parameter"]
.sudo()
.get_param("partner_block_invoice_address")
)
if partner_block_invoice_address == "True":
partner_block_invoice_address_default_type = (
self.env["ir.config_parameter"]
.sudo()
.get_param("partner_block_invoice_address_default_type")
)
return partner_block_invoice_address_default_type
return False

@api.onchange("type")
def _onchange_contact_type(self):
default_type = self._check_setting_block_invoice_address()
if default_type and self.type == "invoice":
self.type = default_type
return {
"warning": {
"title": _("Warning"),
"message": _(
"You cannot set a contact as an invoice address. "
"Check the settings."
),
},
}
return {}

def write(self, vals):
if (
"type" in vals
and vals["type"] == "invoice"
and self._check_setting_block_invoice_address()
):
raise UserError(
_(
"You cannot set a contact as an invoice address. "
"Check the settings."
)
)
return super().write(vals)

@api.model_create_multi
def create(self, vals):
for val in vals:
if (
"type" in val
and val["type"] == "invoice"
and self._check_setting_block_invoice_address()
):
raise UserError(
_(
"You cannot set a contact as an invoice address. "
"Check the settings."
)
)
return super().create(vals)
3 changes: 3 additions & 0 deletions partner_contact_block_invoice_address/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions partner_contact_block_invoice_address/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To configure this module :
1. Go to Settings > Configuration > General Settings
2. Check the box "Partner Block Invoice Address" in the "Block Invoice Address Type" section
3. Set the default type of address to set when creating a new partner
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Italo LOPES \<<italo.lopes@camptocamp.com>\>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module was written to allow the user to block the creation of invoice address type.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9b9ed14

Please sign in to comment.