first commit

This commit is contained in:
Suherdy Yacob 2026-04-27 15:38:40 +07:00
commit 992603e080
4 changed files with 48 additions and 0 deletions

1
__init__.py Normal file
View File

@ -0,0 +1 @@
from . import models

16
__manifest__.py Normal file
View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
{
'name': 'Account Shared Bank Cash',
'version': '1.0',
'category': 'Accounting',
'summary': 'Allows Bank & Cash accounts to be shared between companies',
'description': """
This module removes the standard restriction that prevents Chart of Accounts (COA) of type 'Bank and Cash' from being shared across multiple companies.
""",
'author': 'Antigravity',
'depends': ['account'],
'data': [],
'installable': True,
'application': False,
'license': 'LGPL-3',
}

1
models/__init__.py Normal file
View File

@ -0,0 +1 @@
from . import account_account

30
models/account_account.py Normal file
View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from odoo import api, models, _
from odoo.exceptions import ValidationError, UserError
class AccountAccount(models.Model):
_inherit = 'account.account'
@api.constrains('company_ids', 'account_type')
def _check_company_consistency(self):
if accounts_without_company := self.filtered(lambda a: not a.sudo().company_ids):
raise ValidationError(
self.env._(
"The following accounts must be assigned to at least one company:\n%(accounts)s",
accounts="\n".join(f"- {account.display_name}" for account in accounts_without_company),
),
)
# We explicitly REMOVE the check preventing 'asset_cash' accounts from having len(company_ids) > 1
# The standard Odoo validation below was removed:
# if self.filtered(lambda a: a.account_type == 'asset_cash' and len(a.company_ids) > 1):
# raise ValidationError(_("Bank & Cash accounts cannot be shared between companies."))
# Need to invalidate the sudo cache as we might have just written on `company_ids`
self.invalidate_recordset(fnames=['company_ids'])
for companies, accounts in self.grouped(lambda a: a.company_ids).items():
if self.env['account.move.line'].sudo().search_count([
('account_id', 'in', accounts.ids),
'!', ('company_id', 'child_of', companies.ids)
], limit=1):
raise UserError(_("You can't unlink this company from this account since there are some journal items linked to it."))