commit 992603e080d42210998f68026ab2ffb14bee6ad9 Author: Suherdy Yacob Date: Mon Apr 27 15:38:40 2026 +0700 first commit diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..7d31c36 --- /dev/null +++ b/__manifest__.py @@ -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', +} diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..5a5ba4f --- /dev/null +++ b/models/__init__.py @@ -0,0 +1 @@ +from . import account_account diff --git a/models/account_account.py b/models/account_account.py new file mode 100644 index 0000000..a97e0dc --- /dev/null +++ b/models/account_account.py @@ -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."))