Skip to content

Commit

Permalink
[MIG] account_import_helper to v17
Browse files Browse the repository at this point in the history
Several improvements:
- better handling of company.
- single step wizard
- move description from manifest to README
  • Loading branch information
alexis-via committed Jan 29, 2024
1 parent 462551b commit a632ee2
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 88 deletions.
50 changes: 50 additions & 0 deletions account_import_helper/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
=====================
Account Import Helper
=====================

This module provides methods to help on the import of accounting-related data, in particular the chart of accounts.

First, in a standard test Odoo database with the chart of account of the official addons, use the wizard available via the menu *Configuration > Technical > Chart Generate > Chart Generate* to generate the file *account.account.csv*.

Then, in the future production database, after the installation of the official addons that has the chart of accounts for the country:

* Unconfigure the links to the accounts from several objects and ir.properties:

.. code::
UPDATE account_journal set default_account_id=null, suspense_account_id=null;
DELETE from pos_payment_method;
UPDATE ir_property SET value_reference=null WHERE value_reference like 'account.account,%';
* Delete all accounts:

.. code::
DELETE FROM account_account;
* In the menu *Invoicing > Configuration > Accounting > Chart of accounts*, import the file *account.account.csv* with *Encoding* set to **utf-8** and *Use first row as header* enabled.

* In the menu *Invoicing > Configuration > Accounting > Taxes*, reconfigure the account on taxes.

* In the menu *Invoicing > Configuration > Accounting > Fiscal Positions*, on each fiscal position, configure the account mapping.

* In the menu *Invoicing > Configuration > Accounting > Journals*, on each journal, configure all the fields that point to accounts.

* On the page *Invoicing > Configuration > Settings*, update the section *Default Accounts*

* In the menu *Settings > Technical > Parameters > Company Properties*, edit the 4 properties

- property_account_receivable_id
- property_account_payable_id
- property_account_expense_categ_id
- property_account_income_categ_id

and set the field *value* with **account.account,67** where 67 is the ID of the account you want to have as default for that property.


Contributors
============

This module has been written by Alexis de Lattre <[email protected]> from `Akretion France <https://akretion.com/fr>`_.
2 changes: 1 addition & 1 deletion account_import_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import account
from . import models
from . import wizard
45 changes: 1 addition & 44 deletions account_import_helper/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,6 @@
"category": "Partner",
"license": "AGPL-3",
"summary": "Helper methods to import accounting-related data",
"description": """
Account Import Helper
=====================
This module provides methods to help on the import of accounting-related data, in particular the chart of accounts.
First, in a standard test Odoo database with the chart of account of the official addons, use the wizard available via the menu *Configuration > Technical > Chart Generate > Chart Generate* to generate the file *account.account.csv*.
Then, in the future production database, after the installation of the official addons that has the chart of accounts for the country:
* Unconfigure the links to the accounts from several objects and ir.properties:
UPDATE account_journal set default_account_id=null, suspense_account_id=null;
DELETE from pos_payment_method;
UPDATE ir_property SET value_reference=null WHERE value_reference like 'account.account,%';
* Delete all accounts:
DELETE FROM account_account;
* Go to the menu *Invoicing > Configuration > Accounting > Chart of accounts* and import the file *account.account.csv* with Encoding = UTF-8
* In the menu *Accounting > Configuration > Accounting > Taxes* and reconfigure the account on taxes.
* In the menu *Accounting > Configuration > Accounting > Fiscal Positions*, on each fiscal position, configure the account mapping.
* In the menu *Accounting > Configuration > Accounting > Journals*, on each journal, configure all the fields that point to accounts.
* On the page *Accounting > Configuration > Settings*, configure the *Inter-Banks Transfer Account* (field displayed by my module account_usability)
* In the menu *Settings > Technical > Parameters > Company Properties*, edit the 4 properties
- property_account_receivable_id
- property_account_payable_id
- property_account_expense_categ_id
- property_account_income_categ_id
and set the field *value* with *account.account,67* where 67 is the ID of the account you want to have as default for that property.
This module has been written by Alexis de Lattre <[email protected]> from Akretion.
""",
"author": "Akretion",
"website": "https://github.com/akretion/odoo-import-helper",
"depends": ["account"],
Expand All @@ -59,5 +16,5 @@
"security/ir.model.access.csv",
"wizard/account_chart_generate_view.xml",
],
"installable": False,
"installable": True,
}
10 changes: 0 additions & 10 deletions account_import_helper/demo/chart_to_import.csv

This file was deleted.

Binary file added account_import_helper/demo/chart_to_import.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions account_import_helper/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_company
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# - can use 580001


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

@api.model
def generate_id2xmlid(self, object_name):
Expand All @@ -31,7 +31,6 @@ def generate_id2xmlid(self, object_name):
obj_id2xmlid[entry.res_id] = "{}.{}".format(entry.module, entry.name)
return obj_id2xmlid

@api.model
def generate_custom_chart(
self,
custom_chart,
Expand All @@ -45,12 +44,12 @@ def generate_custom_chart(
# tuple: ('622600', {'name': 'Honoraires comptables'})
# in the second value of the tuple, we often only put name,
# but we can put other odoo properties
self.ensure_one()
taxtemplate2xmlid = self.generate_id2xmlid("account.tax.template")
logger.info("taxtemplate2xmlid = %s", taxtemplate2xmlid)
company = self.env.user.company_id
# pre-load odoo's chart of account
odoo_chart = {}
accounts = self.search([("company_id", "=", company.id)])
accounts = self.env['account.account'].search([("company_id", "=", self.id)])
odoo_code_size = False
for account in accounts:
taxes_xmlids = [taxtemplate2xmlid[tax.id] for tax in account.tax_ids]
Expand Down Expand Up @@ -100,11 +99,11 @@ def generate_custom_chart(
size = odoo_code_size
else:
size = len(custom_code)
match = False
exit_while = False
matching_code = custom_code
if custom2odoo_code_map and custom_code in custom2odoo_code_map:
matching_code = custom2odoo_code_map[custom_code]
while size > 1 and not match:
while size > 1 and not exit_while:
short_matching_code = matching_code[:size]
for odoo_code, odoo_dict in odoo_chart.items():
if odoo_code.startswith(short_matching_code):
Expand All @@ -119,10 +118,10 @@ def generate_custom_chart(
if not with_taxes:
custom_dict["tax_xmlids"] = ""
res.append(custom_dict)
match = True
exit_while = True
break
size -= 1
if not match:
if not exit_while:
raise UserError(
_("Customer account %s '%s' didn't match any Odoo account")
% (custom_code, src_custom_dict.get("name"))
Expand Down
18 changes: 10 additions & 8 deletions account_import_helper/wizard/account_chart_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class AccountChartGenerate(models.TransientModel):
input_has_header_line = fields.Boolean(string="Has a header line", help="Enable this option if the first line of the XLSX file is a header line which must be skipped.")
out_csv_file = fields.Binary(string="Result CSV file", readonly=True)
out_csv_filename = fields.Char(readonly=True)
state = fields.Selection(
[("step1", "step1"), ("step2", "step2")], default="step1", required=True
)
company_id = fields.Many2one(
'res.company', string="Source Company", required=True, readonly=True,
default=lambda self: self.env.company)

def _prepare_custom2odoo_code_map(self):
custom2odoo_code_map = {}
Expand Down Expand Up @@ -74,7 +74,7 @@ def run(self):
fileobj.close()
pprint(custom_chart)
logger.info("Starting to generate CSV file")
res = self.env["account.account"].generate_custom_chart(
res = self.company_id.generate_custom_chart(
custom_chart,
module=self.module,
xmlid_prefix=self.xmlid_prefix,
Expand Down Expand Up @@ -102,14 +102,16 @@ def run(self):
res_file = fout.read()
self.write(
{
"state": "step2",
"out_csv_file": base64.b64encode(res_file.encode('utf-8')),
"out_csv_filename": "account.account-%s.csv" % self.module,
}
)
fout.close()
logger.info("End of the generation of CSV file")
action = self.env["ir.actions.actions"]._for_xml_id(
"account_import_helper.account_chart_generate_action")
action["res_id"] = self.ids[0]
action = {
'name': 'Result',
'type': 'ir.actions.act_url',
'url': f"web/content/?model=account.chart.generate&id={self.id}&filename_field=out_csv_filename&field=out_csv_file&download=true&filename={self.out_csv_filename}",
'target': 'new',
}
return action
19 changes: 3 additions & 16 deletions account_import_helper/wizard/account_chart_generate_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<field name="model">account.chart.generate</field>
<field name="arch" type="xml">
<form string="Generate chart of account">
<div name="help" states="step1">
<div name="help">
<p
>Input XLSX file must have 3 columns:</p>
<ul><li>A. Account Code (field <em>code</em>, required)</li>
Expand All @@ -21,19 +21,15 @@
</ul>
</div>
<group name="main">
<field name="state" invisible="1" />
</group>
<group name="step1" states="step1">
<field name="company_id" />
<field name="module" />
<field name="xmlid_prefix" />
<field name="fixed_size_code" />
<field name="with_taxes" />
<field name="input_file" filename="input_filename" />
<field name="input_filename" invisible="1" />
<field name="input_has_header_line"/>
</group>
<group name="step2" states="step2">
<field name="out_csv_file" filename="out_csv_filename" />
<field name="out_csv_file" filename="out_csv_filename" invisible="1"/>
<field name="out_csv_filename" invisible="1" />
</group>
<footer>
Expand All @@ -42,19 +38,10 @@
type="object"
string="Generate"
class="btn-primary"
states="step1"
/>
<button
special="cancel"
string="Cancel"
class="oe_link"
states="step1"
/>
<button
special="cancel"
string="Close"
class="btn-primary"
states="step2"
/>
</footer>
</form>
Expand Down

0 comments on commit a632ee2

Please sign in to comment.