Skip to content
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
76 changes: 76 additions & 0 deletions sync_multi_company_bank_account/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===============================
Sync Multi Company Bank Account
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2cb1117e7eeae500370f540a90494e7d195242b9492ae0ffc2f344857e97e33a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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-Escodoo%2Faccount--addons-lightgray.png?logo=github
:target: https://github.com/Escodoo/account-addons/tree/16.0/sync_multi_company_bank_account
:alt: Escodoo/account-addons

|badge1| |badge2| |badge3|

The Multi-Company Bank Account Synchronization module aims to ensure that all companies within a business group have the same bank accounts registered and updated, so that all of them can carry out financial transactions without data compatibility issues.

The synchronization is performed automatically, so that the addition, update or deletion of a bank account in one of the companies is reflected in all other companies of the group. To ensure data integrity, the module also checks whether the bank account can be deleted without compromising the integrity of the records in other companies.

**Table of contents**

.. contents::
:local:

Usage
=====

To use the Multi-Company Bank Account Synchronization module, follow these steps:

Install the module in your Odoo system.

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

Bugs are tracked on `GitHub Issues <https://github.com/Escodoo/account-addons/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/Escodoo/account-addons/issues/new?body=module:%20sync_multi_company_bank_account%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
~~~~~~~

* Escodoo

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

* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>
* Cristiano Mafra Junior <cristiano.mafra@escodoo.com.br>

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

This module is part of the `Escodoo/account-addons <https://github.com/Escodoo/account-addons/tree/16.0/sync_multi_company_bank_account>`_ project on GitHub.

You are welcome to contribute.
2 changes: 2 additions & 0 deletions sync_multi_company_bank_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
16 changes: 16 additions & 0 deletions sync_multi_company_bank_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Sync Multi Company Bank Account",
"summary": """
Sync Multi Company Bank Accounts""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo",
"website": "https://github.com/Escodoo/account-addons",
"depends": ["base"],
"data": [],
"demo": [],
"post_init_hook": "post_init_hook",
}
25 changes: 25 additions & 0 deletions sync_multi_company_bank_account/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2023 - TODAY, Marcel Savegnago <marcel.savegnago@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import SUPERUSER_ID, api


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
cr.execute("SELECT * FROM res_partner_bank")
res_partner_bank = []
res_partner_bank = cr.dictfetchall()
if res_partner_bank:
bank_accounts = env["res.partner.bank"]
companies = env["res.company"].search([])
for company in companies:
bank_accounts |= company.bank_ids
for bank_account in bank_accounts:
for company in companies:
if company.id != bank_account.company_id.id:
if bank_account.acc_number not in company.bank_ids.mapped(
"acc_number"
):
bank_account.sudo().with_context(
no_sync_partner_bank=True
).copy({"company_id": company.id})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sync_multi_company_bank_account
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sync_multi_company_bank_account
#: model:ir.model,name:sync_multi_company_bank_account.model_res_partner_bank
msgid "Bank Accounts"
msgstr ""

#. module: sync_multi_company_bank_account
#: model:ir.model,name:sync_multi_company_bank_account.model_res_company
msgid "Companies"
msgstr ""
2 changes: 2 additions & 0 deletions sync_multi_company_bank_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import res_partner_bank
from . import res_company
45 changes: 45 additions & 0 deletions sync_multi_company_bank_account/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2023 - TODAY, Marcel Savegnago <marcel.savegnago@escodoo.com.br>
# Copyright 2025 - TODAY, Cristiano Mafra Junior <cristiano.mafra@escodoo.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class ResCompany(models.Model):
_inherit = "res.company"

def copy_bank_accounts(self):
oldest_company = self.search([], order="create_date").filtered(
lambda c: c.id != self.id
)[:1]
if not oldest_company:
return

bank_accounts = self.env["res.partner.bank"].search(
[
("company_id", "=", oldest_company.id),
]
)

for bank_account in bank_accounts:
dst_partner = self.partner_id
existing = self.env["res.partner.bank"].search(
[
("partner_id", "=", dst_partner.id),
("sanitized_acc_number", "=", bank_account.sanitized_acc_number),
],
limit=1,
)
if not existing:
bank_account.sudo().with_context(no_sync_partner_bank=True).copy(
default={
"company_id": self.id,
"partner_id": dst_partner.id,
}
)

@api.model
def create(self, vals):
company = super().create(vals)
company.copy_bank_accounts()
return company
73 changes: 73 additions & 0 deletions sync_multi_company_bank_account/models/res_partner_bank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2023 - TODAY, Marcel Savegnago <marcel.savegnago@escodoo.com.br>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import api, models


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

@api.model
def create(self, vals):
res = super().create(vals)
if not self.env.context.get("no_sync_partner_bank"):
res.sudo()._sync_partner_bank(vals)
return res

def write(self, vals):
old_acc_number = self.acc_number
old_partner_id = self.partner_id.id
res = super().write(vals)
if not self.env.context.get("no_sync_partner_bank"):
self.sudo()._sync_partner_bank(vals, old_acc_number, old_partner_id)
return res

def unlink(self):
if not self.env.context.get("no_sync_partner_bank_check_unlink"):
for bank in self:
for company in self.env["res.company"].search([]):
if company.id != bank.company_id.id:
dst_partner = company.partner_id
partner_bank = self.env["res.partner.bank"].search(
[
("partner_id", "=", dst_partner.id),
(
"sanitized_acc_number",
"=",
bank.sanitized_acc_number,
),
],
limit=1,
)
if partner_bank:
partner_bank.sudo().with_context(
no_sync_partner_bank_check_unlink=True
).unlink()
return super().unlink()

def _sync_partner_bank(self, vals, old_acc_number=None, old_partner_id=None):
for rec in self:
for company in self.env["res.company"].search([]):
if company.id != rec.company_id.id:
dst_partner = company.partner_id

partner_bank = self.env["res.partner.bank"].search(
[
("partner_id", "=", dst_partner.id),
(
"sanitized_acc_number",
"=",
rec.sanitized_acc_number,
),
],
limit=1,
)
if partner_bank:
partner_bank.with_context(no_sync_partner_bank=True).write(vals)
else:
rec.sudo().with_context(no_sync_partner_bank=True).copy(
{
"company_id": company.id,
"partner_id": dst_partner.id,
}
)
3 changes: 3 additions & 0 deletions sync_multi_company_bank_account/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 sync_multi_company_bank_account/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Escodoo <https://www.escodoo.com.br>`_:

* Marcel Savegnago <marcel.savegnago@escodoo.com.br>
* Cristiano Mafra Junior <cristiano.mafra@escodoo.com.br>
3 changes: 3 additions & 0 deletions sync_multi_company_bank_account/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The Multi-Company Bank Account Synchronization module aims to ensure that all companies within a business group have the same bank accounts registered and updated, so that all of them can carry out financial transactions without data compatibility issues.

The synchronization is performed automatically, so that the addition, update or deletion of a bank account in one of the companies is reflected in all other companies of the group. To ensure data integrity, the module also checks whether the bank account can be deleted without compromising the integrity of the records in other companies.
3 changes: 3 additions & 0 deletions sync_multi_company_bank_account/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
To use the Multi-Company Bank Account Synchronization module, follow these steps:

Install the module in your Odoo system.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading