From b9ddf4692261147c1865d8c9a61b7aff94b8804f Mon Sep 17 00:00:00 2001 From: Laetitia Da Costa Date: Mon, 24 Jun 2024 13:56:24 +0200 Subject: [PATCH] [ADD]import_chart_of_accounts --- import_chart_of_accounts/README.rst | 81 +++++++++ import_chart_of_accounts/__init__.py | 1 + import_chart_of_accounts/__manifest__.py | 23 +++ import_chart_of_accounts/i18n/fr.po | 168 ++++++++++++++++++ .../security/ir.model.access.csv | 2 + import_chart_of_accounts/wizard/__init__.py | 1 + .../wizard/import_coa_wizard.py | 50 ++++++ .../wizard/import_coa_wizard_views.xml | 66 +++++++ 8 files changed, 392 insertions(+) create mode 100644 import_chart_of_accounts/README.rst create mode 100644 import_chart_of_accounts/__init__.py create mode 100644 import_chart_of_accounts/__manifest__.py create mode 100644 import_chart_of_accounts/i18n/fr.po create mode 100644 import_chart_of_accounts/security/ir.model.access.csv create mode 100644 import_chart_of_accounts/wizard/__init__.py create mode 100644 import_chart_of_accounts/wizard/import_coa_wizard.py create mode 100644 import_chart_of_accounts/wizard/import_coa_wizard_views.xml diff --git a/import_chart_of_accounts/README.rst b/import_chart_of_accounts/README.rst new file mode 100644 index 0000000..60a5ef5 --- /dev/null +++ b/import_chart_of_accounts/README.rst @@ -0,0 +1,81 @@ +================ +import_chart_of_accounts +================ + +Provide several profiles for one person. + +Installation +============ + +Use Odoo normal module installation procedure to install +``import_chart_of_accounts``. + +Description +============= + +Pendant l'import, chaque ligne est comparée aux comptes comptables présents dans Odoo +- Si le compte comptable existe déjà dans bdd, seul le nom du compte comptable est mis à jour +- Un compte comptable est déjà existant si les 6 premiers chiffres du code comptable sont identique (par ex: le compte 120000 et 12000000 sont les mêmes comptes) +- Si le compte comptable n'existe pas dans bdd, il est créé. +- Un compte similaire est recherché dans la bdd à partir des 3 premier chiffres du code comptable. +- On recherche tous les comptes qui ont les 3 premiers chiffres de son code en commun avec celui du compte nouvellement créé +- Parmi ces comptes, le compte du lequel les paramètres seront copiés sur le nouveau compte est celui au numéro de code le plus bas. +- On enregistre la valeur des variables 'type' et 'reconcilition' du compte "similaire" dans le nouveau compte comptable +- S'il n'existe "compte similaire" pour ce nouveau compte, aucun paramétrage n'est ajouté lors de l'import + +Exemple : + +J'importe le compte comptable 607730 Epicerie divers +Ce compte comptable n'existe pas déjà dans Odoo, il est créé. +Pour le configurer automatiquement, on se fonde sur un compte similaire dans Odoo et avec le code le plus bas parmis les comptes similaires +Ici il s'agit de 607000 Achats de marchandise: +Il a pour Type Charges car c'est une compte de charges et Autoriser le lettrage est à False. +Le compte 607730 Epicerie divers sera donc enregistré dans Odoo avec le même paramétrage. + +Usage +===== + +Pour importer le plan comptable : + +Aller dans l'App Facturation +Menu Configuration > Comptabilité > Importer le plan comptable + +Un assistant permettant le téléversement d'un plan comptable apparaît. + +Le fichier téléversé doit être au format CSV uniquement. +Il ne doit comporter que deux colonnes : +- La première colonne doit s'appeler 'code' pour le numéro de compte comptable +- La deuxième colonne doit s'appeler 'name' pour le nom du compte comptable + +Known issues / Roadmap +====================== + +None yet. + +Bug Tracker +=========== + +Bugs are tracked on `our issues website `_. 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. + +Credits +======= + +Contributors +------------ + +* Laetitia Da Costa + +Funders +------- + +The development of this module has been financially supported by: +* Elabore (https://elabore.coop) + + +Maintainer +---------- + +This module is maintained by Elabore. \ No newline at end of file diff --git a/import_chart_of_accounts/__init__.py b/import_chart_of_accounts/__init__.py new file mode 100644 index 0000000..20a7f5c --- /dev/null +++ b/import_chart_of_accounts/__init__.py @@ -0,0 +1 @@ +from . import wizard \ No newline at end of file diff --git a/import_chart_of_accounts/__manifest__.py b/import_chart_of_accounts/__manifest__.py new file mode 100644 index 0000000..bb91eef --- /dev/null +++ b/import_chart_of_accounts/__manifest__.py @@ -0,0 +1,23 @@ +{ + 'name': 'Import chart of accounts', + 'version': '16.0.1.1.0', + 'summary': 'while importing the accounts chart, only update account name of existing accounts and automatise settings for new accounts', + 'description': '', + 'author': '', + 'website': '', + 'license': 'AGPL-3', + 'category': '', + 'depends': [ + 'account' + ], + 'data': [ + 'wizard/import_coa_wizard_views.xml', + 'security/ir.model.access.csv' + ], + 'installable': True, + 'application': False, + 'assets': { + } +} + + diff --git a/import_chart_of_accounts/i18n/fr.po b/import_chart_of_accounts/i18n/fr.po new file mode 100644 index 0000000..f91d467 --- /dev/null +++ b/import_chart_of_accounts/i18n/fr.po @@ -0,0 +1,168 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * import_chart_of_accounts +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-05-29 10:27+0000\n" +"PO-Revision-Date: 2024-05-29 10:27+0000\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: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Exemple :" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Accounts chart CSV Import Wizard" +msgstr "Importer un plan comptable" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__coa_file +msgid "CSV File" +msgstr "Fichier CSV" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Cancel" +msgstr "Annuler" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Ce compte comptable n'existe pas déjà dans Odoo, il est créé." +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__create_uid +msgid "Created by" +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__create_date +msgid "Created on" +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__display_name +msgid "Display Name" +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__filename +msgid "Filename" +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__id +msgid "ID" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "" +"Ici il s'agit de 607000 Achats de marchandise:
\n" +" Il a pour Type Charges car c'est une compte de charges et Autoriser le lettrage est à False.
\n" +" Le compte 607730 Epicerie divers sera donc enregistré dans Odoo avec le même paramétrage,
\n" +" c'est-à-dire avec un type Charge et une non autorisation du lettrage" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Il ne doit comporter que deux colonnes" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Import" +msgstr "Importer" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "J'importe le compte comptable 607730 Epicerie divers" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "" +"La deuxième colonne doit s'appeler name pour le nom du " +"compte comptable" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "" +"La première colonne doit s'appeler code pour le numéro de " +"compte comptable" +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard____last_update +msgid "Last Modified on" +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.model.fields,field_description:import_chart_of_accounts.field_import_coa_wizard__write_date +msgid "Last Updated on" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Le fichier téléversé doit être au format CSV" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "" +"Pendant l'import, chaque ligne est comparée aux comptes comptables présents " +"dans Odoo" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "Pour importer le plan comptable :" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "" +"Pour le configurer automatiquement, on se fonde sur le compte le plus proche" +" dans Odoo" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "" +"Si le compte comptable existe déjà dans bdd, seul le nom du compte comptable" +" est mis à jour" +msgstr "" + +#. module: import_chart_of_accounts +#: model_terms:ir.ui.view,arch_db:import_chart_of_accounts.import_coa_wizard_view +msgid "" +"Si le compte comptable n'existe pas dans bdd, il est créé. Puis un compte similaire est recherché dans la bdd,\n" +"
le compte comptable nouvellement créé aura le même type et la même autorisation de lettrage." +msgstr "" + +#. module: import_chart_of_accounts +#: model:ir.actions.act_window,name:import_chart_of_accounts.action_import_coa_wizard +#: model:ir.ui.menu,name:import_chart_of_accounts.import_coa_menu +msgid "Upload Chart Of Accounts" +msgstr "Importer un plan comptable" + +#. module: import_chart_of_accounts +#: model:ir.model,name:import_chart_of_accounts.model_import_coa_wizard +msgid "import.coa.wizard" +msgstr "" diff --git a/import_chart_of_accounts/security/ir.model.access.csv b/import_chart_of_accounts/security/ir.model.access.csv new file mode 100644 index 0000000..f2301d6 --- /dev/null +++ b/import_chart_of_accounts/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_import_coa_wizard,access.import.coa.wizard,model_import_coa_wizard,account.group_account_manager,1,1,1,0 \ No newline at end of file diff --git a/import_chart_of_accounts/wizard/__init__.py b/import_chart_of_accounts/wizard/__init__.py new file mode 100644 index 0000000..5f549bc --- /dev/null +++ b/import_chart_of_accounts/wizard/__init__.py @@ -0,0 +1 @@ +from . import import_coa_wizard \ No newline at end of file diff --git a/import_chart_of_accounts/wizard/import_coa_wizard.py b/import_chart_of_accounts/wizard/import_coa_wizard.py new file mode 100644 index 0000000..db7ad51 --- /dev/null +++ b/import_chart_of_accounts/wizard/import_coa_wizard.py @@ -0,0 +1,50 @@ +from odoo import models, fields, api, exceptions, _ +import csv +import base64 +from io import StringIO +from odoo.exceptions import UserError + +class ImportCoaWizard(models.TransientModel): + _name = 'import.coa.wizard' + + coa_file = fields.Binary(string='CSV File', required=True) + filename = fields.Char(string='Filename') + + def import_plan_comptable(self): + self.ensure_one() + if not self.coa_file: + raise UserError("Please upload a file.") + + if self.filename and not self.filename.lower().endswith('.csv'): + raise UserError("Import COA Wizard only supports CSV") + + file_content = base64.b64decode(self.coa_file).decode('utf-8') + csv_file = StringIO(file_content) + csv_reader = csv.DictReader(csv_file) + + required_columns = ['code', 'name'] + if not all(column in csv_reader.fieldnames for column in required_columns): + raise UserError(f"The CSV file must contain the following columns: {', '.join(required_columns)}") + + data_to_import = [row for row in csv_reader] + for record_data in data_to_import: + # the account is already existing in Odoo if the 6 first digits are identicales + existing_line = self.find_account_with_same_firsts_digits(record_data['code'][:6]) + if existing_line: + existing_line.write(record_data) + else: + # the closest account already existing in Odoo has the first tree digits identicales + closest_account = self.find_account_with_same_firsts_digits(record_data['code'][:3]) + if closest_account : + record_data['account_type'] = closest_account.account_type + record_data['reconcile'] = closest_account.reconcile + new_account = self.env['account.account'].create(record_data) + + return { + "type": "ir.actions.act_window", + "res_model": "account.account", + "view_mode": "list" + } + + def find_account_with_same_firsts_digits(self, code_prefix): + return self.env['account.account'].search([('code', '=like', f'{code_prefix}%')],limit=1) diff --git a/import_chart_of_accounts/wizard/import_coa_wizard_views.xml b/import_chart_of_accounts/wizard/import_coa_wizard_views.xml new file mode 100644 index 0000000..2622b45 --- /dev/null +++ b/import_chart_of_accounts/wizard/import_coa_wizard_views.xml @@ -0,0 +1,66 @@ + + + + import.coa.wizard.view + import.coa.wizard + +
+ +
+

Pour importer le plan comptable : +

    +
  • Le fichier téléversé doit être au format CSV
  • +
  • Il ne doit comporter que deux colonnes
  • +
  • La première colonne doit s'appeler code pour le numéro de compte comptable
  • +
  • La deuxième colonne doit s'appeler name pour le nom du compte comptable
  • +
+

+
+

Pendant l'import, chaque ligne est comparée aux comptes comptables présents dans Odoo +

    +
  • Si le compte comptable existe déjà dans bdd, seul le nom du compte comptable est mis à jour
  • +
  • Un compte comptable est déjà existant si les 6 premiers chiffres du code comptable sont identique (par ex: le compte 120000 et 12000000 sont les mêmes comptes)
  • +
  • Si le compte comptable n'existe pas dans bdd, il est créé. Puis un compte similaire est recherché dans la bdd, +
    le compte comptable nouvellement créé aura le même type et la même autorisation de lettrage.
  • +
+

+
+

Exemple : +

    +
  • J'importe le compte comptable 607730 Epicerie divers
  • +
  • Ce compte comptable n'existe pas déjà dans Odoo, il est créé.
  • +
  • Pour le configurer automatiquement, on se fonde sur le compte le plus proche dans Odoo
  • +
  • Ici il s'agit de 607000 Achats de marchandise:
    + Il a pour Type Charges car c'est une compte de charges et Autoriser le lettrage est à False.
    + Le compte 607730 Epicerie divers sera donc enregistré dans Odoo avec le même paramétrage,
    + c'est-à-dire avec un type Charge et une non autorisation du lettrage
  • +
+

+
+
+ + + + +
+
+
+
+
+ + Upload Chart Of Accounts + import.coa.wizard + form + new + + + +