summaryrefslogtreecommitdiff
path: root/addons/account/__init__.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account/__init__.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account/__init__.py')
-rw-r--r--addons/account/__init__.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/addons/account/__init__.py b/addons/account/__init__.py
new file mode 100644
index 00000000..7312ecc2
--- /dev/null
+++ b/addons/account/__init__.py
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import controllers
+from . import models
+from . import wizard
+from . import report
+
+from odoo import api, SUPERUSER_ID
+
+SYSCOHADA_LIST = ['BJ', 'BF', 'CM', 'CF', 'KM', 'CG', 'CI', 'GA', 'GN', 'GW', 'GQ', 'ML', 'NE', 'CD', 'SN', 'TD', 'TG']
+
+def _set_fiscal_country(env):
+ """ Sets the fiscal country on existing companies when installing the module.
+ That field is an editable computed field. It doesn't automatically get computed
+ on existing records by the ORM when installing the module, so doing that by hand
+ ensures existing records will get a value for it if needed.
+ """
+ env['res.company'].search([]).compute_account_tax_fiscal_country()
+
+
+def _auto_install_l10n(env):
+ #check the country of the main company (only) and eventually load some module needed in that country
+ country_code = env.company.country_id.code
+ if country_code:
+ #auto install localization module(s) if available
+ to_install_l10n = env['ir.module.module'].search_count([
+ ('category_id', '=', env.ref('base.module_category_accounting_localizations_account_charts').id),
+ ('state', '=', 'to install'),
+ ])
+ module_list = []
+ if to_install_l10n:
+ # We don't install a CoA if one was passed in the command line
+ # or has been selected to install
+ pass
+ elif country_code in SYSCOHADA_LIST:
+ #countries using OHADA Chart of Accounts
+ module_list.append('l10n_syscohada')
+ elif country_code == 'GB':
+ module_list.append('l10n_uk')
+ elif country_code == 'DE':
+ module_list.append('l10n_de_skr03')
+ module_list.append('l10n_de_skr04')
+ else:
+ if env['ir.module.module'].search([('name', '=', 'l10n_' + country_code.lower())]):
+ module_list.append('l10n_' + country_code.lower())
+ else:
+ module_list.append('l10n_generic_coa')
+ if country_code == 'US':
+ module_list.append('account_plaid')
+ if country_code in ['US', 'CA']:
+ module_list.append('account_check_printing')
+ if country_code in ['US', 'AU', 'NZ', 'CA', 'CO', 'EC', 'ES', 'FR', 'IN', 'MX', 'GB']:
+ module_list.append('account_yodlee')
+ if country_code in SYSCOHADA_LIST + [
+ 'AT', 'BE', 'CA', 'CO', 'DE', 'EC', 'ES', 'ET', 'FR', 'GR', 'IT', 'LU', 'MX', 'NL', 'NO',
+ 'PL', 'PT', 'RO', 'SI', 'TR', 'GB', 'VE', 'VN'
+ ]:
+ module_list.append('base_vat')
+ if country_code == 'MX':
+ module_list.append('l10n_mx_edi')
+ if country_code == 'IT':
+ module_list.append('l10n_it_edi_sdicoop')
+
+ module_ids = env['ir.module.module'].search([('name', 'in', module_list), ('state', '=', 'uninstalled')])
+ module_ids.sudo().button_install()
+
+def _account_post_init(cr, registry):
+ env = api.Environment(cr, SUPERUSER_ID, {})
+ _auto_install_l10n(env)
+ _set_fiscal_country(env)