diff --git a/account_invoice_bank_brand/README.rst b/account_invoice_bank_brand/README.rst new file mode 100644 index 000000000..39e440ec8 --- /dev/null +++ b/account_invoice_bank_brand/README.rst @@ -0,0 +1,87 @@ +========================== +Account Invoice Bank Brand +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-OCA%2Fbrand-lightgray.png?logo=github + :target: https://github.com/OCA/brand/tree/12.0/account_invoice_bank_brand + :alt: OCA/brand +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/brand-12-0/brand-12-0-account_invoice_bank_brand + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/284/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon allows to set partner_bank_id on invoices depending on the brand. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to Settings > Users & Companies > Brands +#. Select a brand +#. Define bank account +#. Create a new invoice + #. Select the brand + #. Save + +The bank account is filled with the brand bank account. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Quentin Groulard + +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/brand `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_invoice_bank_brand/__init__.py b/account_invoice_bank_brand/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_invoice_bank_brand/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_invoice_bank_brand/__manifest__.py b/account_invoice_bank_brand/__manifest__.py new file mode 100644 index 000000000..baf56ada3 --- /dev/null +++ b/account_invoice_bank_brand/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Invoice Bank Brand", + "summary": """ + This addon allows to set partner_bank_id on invoices depending on the brand.""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/brand", + "depends": ["account_brand"], + "data": ["views/res_brand.xml"], +} diff --git a/account_invoice_bank_brand/models/__init__.py b/account_invoice_bank_brand/models/__init__.py new file mode 100644 index 000000000..e9fc97a2a --- /dev/null +++ b/account_invoice_bank_brand/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_invoice +from . import res_brand diff --git a/account_invoice_bank_brand/models/account_invoice.py b/account_invoice_bank_brand/models/account_invoice.py new file mode 100644 index 000000000..b2acc5526 --- /dev/null +++ b/account_invoice_bank_brand/models/account_invoice.py @@ -0,0 +1,27 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from collections import OrderedDict + +from odoo import api, models + + +class AccountInvoice(models.Model): + + _inherit = "account.invoice" + + def _get_onchange_create(self): + res = super()._get_onchange_create() + return OrderedDict( + [("_onchange_brand", ["partner_bank_id"])] + list(res.items()) + ) + + @api.onchange("brand_id") + def _onchange_brand(self): + invoice_type = self.type or self.env.context.get("type", "out_invoice") + if ( + invoice_type in ("out_invoice", "in_refund") + and self.brand_id + and self.brand_id.partner_bank_id + ): + self.partner_bank_id = self.brand_id.partner_bank_id diff --git a/account_invoice_bank_brand/models/res_brand.py b/account_invoice_bank_brand/models/res_brand.py new file mode 100644 index 000000000..70512e6c1 --- /dev/null +++ b/account_invoice_bank_brand/models/res_brand.py @@ -0,0 +1,33 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ResBrand(models.Model): + + _inherit = "res.brand" + + partner_bank_id = fields.Many2one( + comodel_name="res.partner.bank", + domain="[('partner_id.ref_company_ids', 'in', [company_id])]", + string="Bank Account", + description="Company Bank Account Number to which the invoices of this " + "brand will be paid (for Customer Invoice and Vendor Credit Note)", + ) + + @api.constrains("company_id", "partner_bank_id") + def validate_partner_bank_id(self): + for record in self: + if ( + record.partner_bank_id + and not record.company_id + in record.partner_bank_id.partner_id.ref_company_ids + ): + raise ValidationError( + _( + "The account selected for invoices payment does not " + "belong to the same company as this brand." + ) + ) diff --git a/account_invoice_bank_brand/readme/CONTRIBUTORS.rst b/account_invoice_bank_brand/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..5914f5529 --- /dev/null +++ b/account_invoice_bank_brand/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Quentin Groulard diff --git a/account_invoice_bank_brand/readme/DESCRIPTION.rst b/account_invoice_bank_brand/readme/DESCRIPTION.rst new file mode 100644 index 000000000..c320ede2f --- /dev/null +++ b/account_invoice_bank_brand/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This addon allows to set partner_bank_id on invoices depending on the brand. diff --git a/account_invoice_bank_brand/readme/USAGE.rst b/account_invoice_bank_brand/readme/USAGE.rst new file mode 100644 index 000000000..499446612 --- /dev/null +++ b/account_invoice_bank_brand/readme/USAGE.rst @@ -0,0 +1,10 @@ +To use this module, you need to: + +#. Go to Settings > Users & Companies > Brands +#. Select a brand +#. Define bank account +#. Create a new invoice + #. Select the brand + #. Save + +The bank account is filled with the brand bank account. diff --git a/account_invoice_bank_brand/static/description/icon.png b/account_invoice_bank_brand/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_invoice_bank_brand/static/description/icon.png differ diff --git a/account_invoice_bank_brand/static/description/index.html b/account_invoice_bank_brand/static/description/index.html new file mode 100644 index 000000000..d86b2fc16 --- /dev/null +++ b/account_invoice_bank_brand/static/description/index.html @@ -0,0 +1,439 @@ + + + + + + +Account Invoice Bank Brand + + + +
+

Account Invoice Bank Brand

+ + +

Beta License: AGPL-3 OCA/brand Translate me on Weblate Try me on Runbot

+

This addon allows to set partner_bank_id on invoices depending on the brand.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Settings > Users & Companies > Brands
  2. +
  3. Select a brand
  4. +
  5. Define bank account
  6. +
  7. +
    Create a new invoice
    +
      +
    1. Select the brand
    2. +
    3. Save
    4. +
    +
    +
    +
  8. +
+

The bank account is filled with the brand bank account.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/brand project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_invoice_bank_brand/tests/__init__.py b/account_invoice_bank_brand/tests/__init__.py new file mode 100644 index 000000000..d7555d021 --- /dev/null +++ b/account_invoice_bank_brand/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_invoice diff --git a/account_invoice_bank_brand/tests/test_account_invoice.py b/account_invoice_bank_brand/tests/test_account_invoice.py new file mode 100644 index 000000000..c1080ee5e --- /dev/null +++ b/account_invoice_bank_brand/tests/test_account_invoice.py @@ -0,0 +1,41 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import SavepointCase + + +class TestAccountInvoice(SavepointCase): + def setUp(self): + super(TestAccountInvoice, self).setUp() + self.partner_id = self.env.ref("base.res_partner_12") + self.invoice = self.env["account.invoice"].create( + {"partner_id": self.partner_id.id, "type": "out_invoice"} + ) + company_id = self.env["res.company"].browse(1) + self.partner_bank_id = self.env["res.partner.bank"].create( + {"acc_number": "123456", "partner_id": company_id.partner_id.id} + ) + self.brand_id = self.env["res.brand"].create( + { + "name": "Brand", + "partner_bank_id": self.partner_bank_id.id, + "company_id": 1, + } + ) + + def test_on_change_brand_id(self): + self.invoice._onchange_brand() + self.assertNotEqual(self.invoice.partner_bank_id, self.partner_bank_id) + self.invoice.brand_id = self.brand_id + self.invoice._onchange_brand() + self.assertEqual(self.invoice.partner_bank_id, self.partner_bank_id) + + def test_create_invoice(self): + invoice = self.env["account.invoice"].create( + { + "partner_id": self.partner_id.id, + "type": "out_invoice", + "brand_id": self.brand_id.id, + } + ) + self.assertEqual(invoice.partner_bank_id, self.partner_bank_id) diff --git a/account_invoice_bank_brand/views/res_brand.xml b/account_invoice_bank_brand/views/res_brand.xml new file mode 100644 index 000000000..ab235b43b --- /dev/null +++ b/account_invoice_bank_brand/views/res_brand.xml @@ -0,0 +1,20 @@ + + + + + + + res.brand.form (in account_invoice_bank_brand) + res.brand + + + + + + + + + + + diff --git a/setup/account_invoice_bank_brand/odoo/addons/account_invoice_bank_brand b/setup/account_invoice_bank_brand/odoo/addons/account_invoice_bank_brand new file mode 120000 index 000000000..bacc3d876 --- /dev/null +++ b/setup/account_invoice_bank_brand/odoo/addons/account_invoice_bank_brand @@ -0,0 +1 @@ +../../../../account_invoice_bank_brand \ No newline at end of file diff --git a/setup/account_invoice_bank_brand/setup.py b/setup/account_invoice_bank_brand/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_invoice_bank_brand/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)