Skip to content

Commit

Permalink
Merge PR #743 into 18.0
Browse files Browse the repository at this point in the history
Signed-off-by ecino
  • Loading branch information
OCA-git-bot committed Jan 28, 2025
2 parents 2c077a2 + 7579c22 commit 5046695
Show file tree
Hide file tree
Showing 16 changed files with 1,241 additions and 0 deletions.
3 changes: 3 additions & 0 deletions checklog-odoo.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[checklog-odoo]
ignore=
WARNING.*0 failed, 0 error\(s\).*
98 changes: 98 additions & 0 deletions l10n_ch_account_tags/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
========================
Switzerland Account Tags
========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--switzerland-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-switzerland/tree/14.0/l10n_ch_account_tags
:alt: OCA/l10n-switzerland
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-switzerland-14-0/l10n-switzerland-14-0-l10n_ch_account_tags
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/125/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds tags and the account templates for the Switzerland chart of accounts

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

1. Install this module

Changelog
=========
14.0.1.0.0 (10.09.2021)
~~~~~~~~~~~~~~~~~~~~~~~~~

* Migration to version 14.0

13.0.1.0.0 (30.09.2019)
~~~~~~~~~~~~~~~~~~~~~~~~~

* Migration to version 13.0

11.0.1.0.0 (05.07.2018)
~~~~~~~~~~~~~~~~~~~~~~~~~

* Adding the module

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-switzerland/issues>`_.
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 <https://github.com/OCA/l10n-switzerland/issues/new?body=module:%20l10n_ch_account_tags%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp SA

Contributors
~~~~~~~~~~~~

* Panarin Mykhailo <m.panarin@mobilunity.com>
* Yannick Vaucher <yannick.vaucher@camptocamp.com>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/l10n-switzerland <https://github.com/OCA/l10n-switzerland/tree/14.0/l10n_ch_account_tags>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions l10n_ch_account_tags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .hooks import post_init
15 changes: 15 additions & 0 deletions l10n_ch_account_tags/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

{
"name": "Switzerland Account Tags",
"category": "Localisation",
"summary": "",
"version": "18.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-switzerland",
"license": "AGPL-3",
"depends": ["l10n_ch"],
"data": ["data/account.account.tag-ch.csv"],
"post_init_hook": "post_init",
}
34 changes: 34 additions & 0 deletions l10n_ch_account_tags/data/account.account.tag-ch.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"id","name","applicability","color"
"account_tag_ch_60","Autres charges d‘exploitation (CH_60)","accounts","4"
"account_tag_ch_280","Capital social ou capital de fondation (CH_280)","accounts","4"
"account_tag_ch_68","Amortissements sur immobilisations corporelles (CH_68)","accounts","4"
"account_tag_ch_69","Résultat financier (CH_69)","accounts","4"
"account_tag_ch_180","Capital non versé : capital social - capital de fondation (CH_180)","accounts","4"
"account_tag_ch_148","Participations (CH_148)","accounts","4"
"account_tag_ch_220","Autres dettes à court terme (CH_220)","accounts","4"
"account_tag_ch_160","Immobilisations corporelles immeubles CH_160)","accounts","4"
"account_tag_ch_140","Immobilisations financières (CH_140)","accounts","4"
"account_tag_ch_89","Impôts directs (CH_89)","accounts","4"
"account_tag_ch_150","Immobilisations corporelles meubles (CH_150)","accounts","4"
"account_tag_ch_130","Actifs de régularisation (transitoires) (CH_130)","accounts","4"
"account_tag_ch_80","Résultat hors-exploitation (CH_80)","accounts","4"
"account_tag_ch_210","Dettes à court terme rémunérés (CH_210)","accounts","4"
"account_tag_ch_114","Autres créances à court terme (CH_114)","accounts","4"
"account_tag_ch_85","Résultat extraordinaires (CH_85)","accounts","4"
"account_tag_ch_110","Créances résultant de livraisons et prestations (CH_110)","accounts","4"
"account_tag_ch_297","Résultat de l'exercice (CH_297)","accounts","4"
"account_tag_ch_290","Réserves / bénéfices et pertes reportés (CH_290)","accounts","4"
"account_tag_ch_170","Immobilisations incorporelles (CH_170)","accounts","4"
"account_tag_ch_230","Passifs de régularisation (transitoires) et provisions à court terme (CH_230)","accounts","4"
"account_tag_ch_7","Résultat des activités annexes d'exploitation (CH_7)","accounts","4"
"account_tag_ch_5","Charges de personnel (CH_5)","accounts","4"
"account_tag_ch_4","Charges de marchandises et de matériel (CH_4)","accounts","4"
"account_tag_ch_200","Dettes à court terme résultant d’achats et de prestations de services (CH_200)","accounts","4"
"account_tag_ch_260","Provisions à long termes et provisions légales (CH_260)","accounts","4"
"account_tag_ch_120","Stocks et prestations non facturées (CH_120)","accounts","4"
"account_tag_ch_100","Trésorerie (CH_100)","accounts","4"
"account_tag_ch_106","Actifs à court terme cotés en bourse (CH_106)","accounts","4"
"account_tag_ch_240","Dettes à long terme rémunérées (CH_240)","accounts","4"
"account_tag_ch_39","Variation des stocks (CH_39)","accounts","4"
"account_tag_ch_250","Autres dettes à long terme (CH_250)","accounts","4"
"account_tag_ch_30","Chiffre d'affaires (CH_30)","accounts","4"
234 changes: 234 additions & 0 deletions l10n_ch_account_tags/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import logging

_logger = logging.getLogger(__name__)


def assign_account_tags(env):
"""Assign tags to specific accounts."""
# List of account codes and the corresponding tags to assign
account_tags = {
"transfer_account_id": "l10n_ch_account_tags.account_tag_ch_106",
"ch_coa_1060": "l10n_ch_account_tags.account_tag_ch_106",
"ch_coa_1069": "l10n_ch_account_tags.account_tag_ch_106",
"ch_coa_1091": "l10n_ch_account_tags.account_tag_ch_106",
"ch_coa_1099": "l10n_ch_account_tags.account_tag_ch_106",
"ch_coa_1100": "l10n_ch_account_tags.account_tag_ch_110",
"ch_coa_1109": "l10n_ch_account_tags.account_tag_ch_110",
"ch_coa_1140": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1149": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1170": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1171": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1176": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1180": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1189": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1190": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1199": "l10n_ch_account_tags.account_tag_ch_114",
"ch_coa_1200": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1207": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1208": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1209": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1210": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1217": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1218": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1219": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1220": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1230": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1250": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1260": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1267": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1269": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1270": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1277": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1279": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1280": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1287": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1289": "l10n_ch_account_tags.account_tag_ch_120",
"ch_coa_1300": "l10n_ch_account_tags.account_tag_ch_130",
"ch_coa_1301": "l10n_ch_account_tags.account_tag_ch_130",
"ch_coa_1400": "l10n_ch_account_tags.account_tag_ch_140",
"ch_coa_1409": "l10n_ch_account_tags.account_tag_ch_140",
"ch_coa_1440": "l10n_ch_account_tags.account_tag_ch_140",
"ch_coa_1441": "l10n_ch_account_tags.account_tag_ch_140",
"ch_coa_1449": "l10n_ch_account_tags.account_tag_ch_140",
"ch_coa_1480": "l10n_ch_account_tags.account_tag_ch_148",
"ch_coa_1489": "l10n_ch_account_tags.account_tag_ch_148",
"ch_coa_1500": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1509": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1510": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1519": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1520": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1529": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1530": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1539": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1540": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1549": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1550": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1559": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1570": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1579": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1590": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1599": "l10n_ch_account_tags.account_tag_ch_150",
"ch_coa_1600": "l10n_ch_account_tags.account_tag_ch_160",
"ch_coa_1609": "l10n_ch_account_tags.account_tag_ch_160",
"ch_coa_1700": "l10n_ch_account_tags.account_tag_ch_170",
"ch_coa_1709": "l10n_ch_account_tags.account_tag_ch_170",
"ch_coa_1770": "l10n_ch_account_tags.account_tag_ch_170",
"ch_coa_1779": "l10n_ch_account_tags.account_tag_ch_170",
"ch_coa_1850": "l10n_ch_account_tags.account_tag_ch_180",
"ch_coa_2000": "l10n_ch_account_tags.account_tag_ch_200",
"ch_coa_2030": "l10n_ch_account_tags.account_tag_ch_200",
"ch_coa_2100": "l10n_ch_account_tags.account_tag_ch_210",
"ch_coa_2120": "l10n_ch_account_tags.account_tag_ch_210",
"ch_coa_2140": "l10n_ch_account_tags.account_tag_ch_210",
"ch_coa_2160": "l10n_ch_account_tags.account_tag_ch_210",
"ch_coa_2200": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2201": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2206": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2208": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2210": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2261": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2270": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2279": "l10n_ch_account_tags.account_tag_ch_220",
"ch_coa_2300": "l10n_ch_account_tags.account_tag_ch_230",
"ch_coa_2301": "l10n_ch_account_tags.account_tag_ch_230",
"ch_coa_2330": "l10n_ch_account_tags.account_tag_ch_230",
"ch_coa_2400": "l10n_ch_account_tags.account_tag_ch_240",
"ch_coa_2420": "l10n_ch_account_tags.account_tag_ch_240",
"ch_coa_2430": "l10n_ch_account_tags.account_tag_ch_240",
"ch_coa_2450": "l10n_ch_account_tags.account_tag_ch_240",
"ch_coa_2451": "l10n_ch_account_tags.account_tag_ch_240",
"ch_coa_2500": "l10n_ch_account_tags.account_tag_ch_250",
"ch_coa_2600": "l10n_ch_account_tags.account_tag_ch_260",
"ch_coa_2800": "l10n_ch_account_tags.account_tag_ch_280",
"ch_coa_2900": "l10n_ch_account_tags.account_tag_ch_290",
"ch_coa_2940": "l10n_ch_account_tags.account_tag_ch_290",
"ch_coa_2950": "l10n_ch_account_tags.account_tag_ch_290",
"ch_coa_2960": "l10n_ch_account_tags.account_tag_ch_290",
"ch_coa_2970": "l10n_ch_account_tags.account_tag_ch_290",
"ch_coa_2979": "l10n_ch_account_tags.account_tag_ch_297",
"ch_coa_2980": "l10n_ch_account_tags.account_tag_ch_290",
"ch_coa_3000": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3009": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3200": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3400": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3600": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3700": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3710": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3800": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3801": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3802": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3803": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3804": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3805": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3806": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3807": "l10n_ch_account_tags.account_tag_ch_30",
"ch_coa_3900": "l10n_ch_account_tags.account_tag_ch_39",
"ch_coa_3901": "l10n_ch_account_tags.account_tag_ch_39",
"ch_coa_3940": "l10n_ch_account_tags.account_tag_ch_39",
"ch_coa_4000": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4008": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4009": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4070": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4071": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4072": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4080": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4086": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4092": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4200": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4400": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4500": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4510": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4520": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4521": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4530": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4540": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4800": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4801": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4900": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4901": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4903": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_4906": "l10n_ch_account_tags.account_tag_ch_4",
"ch_coa_5000": "l10n_ch_account_tags.account_tag_ch_5",
"ch_coa_5700": "l10n_ch_account_tags.account_tag_ch_5",
"ch_coa_5800": "l10n_ch_account_tags.account_tag_ch_5",
"ch_coa_5900": "l10n_ch_account_tags.account_tag_ch_5",
"ch_coa_6000": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6100": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6105": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6200": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6260": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6300": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6400": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6500": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6570": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6600": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6700": "l10n_ch_account_tags.account_tag_ch_60",
"ch_coa_6800": "l10n_ch_account_tags.account_tag_ch_68",
"ch_coa_6900": "l10n_ch_account_tags.account_tag_ch_69",
"ch_coa_6950": "l10n_ch_account_tags.account_tag_ch_69",
"ch_coa_7000": "l10n_ch_account_tags.account_tag_ch_7",
"ch_coa_7010": "l10n_ch_account_tags.account_tag_ch_7",
"ch_coa_7500": "l10n_ch_account_tags.account_tag_ch_7",
"ch_coa_7510": "l10n_ch_account_tags.account_tag_ch_7",
"ch_coa_8000": "l10n_ch_account_tags.account_tag_ch_80",
"ch_coa_8100": "l10n_ch_account_tags.account_tag_ch_80",
"ch_coa_8500": "l10n_ch_account_tags.account_tag_ch_85",
"ch_coa_8510": "l10n_ch_account_tags.account_tag_ch_85",
"ch_coa_8900": "l10n_ch_account_tags.account_tag_ch_89",
}

# Search for companies with chart template 'ch'
companies = env["res.company"].search([("chart_template", "=", "ch")])

# Create a dictionary to hold account IDs and their corresponding tags
account_tag_mapping = {}

# Loop through the companies and account_tags to group account-tag pairs
for company in companies:
for account_code, tag_code in account_tags.items():
# Construct the xml_id of the account based on company ID and account code
xml_id = f"account.{company.id}_{account_code}"

try:
# Use env.ref() to search for the account by xml_id
account = env.ref(xml_id)

# Use env.ref() to search for the tag by tag_code
tag = env.ref(tag_code)

if account and tag:
# If the account is found, group the tags by account_id
if account.id not in account_tag_mapping:
account_tag_mapping[account.id] = []

account_tag_mapping[account.id].append(tag.id)
else:
if not account:
_logger.warning(f"Account with xml_id {xml_id} not found.")
if not tag:
_logger.warning(f"Tag with code {tag_code} not found.")

except (ValueError, KeyError, AttributeError) as e:
_logger.error(
f"Error processing account {xml_id} and tag {tag_code}: "
f"{str(e)}"
)

# Perform bulk updates for each account by adding new tags
for account_id, tag_ids in account_tag_mapping.items():
account = env["account.account"].browse(account_id)

if account:
# Get the IDs of existing tags assigned to the account
existing_tags = account.tag_ids.ids

# Filter out the tags that are already assigned
new_tags = list(set(tag_ids) - set(existing_tags))

if new_tags:
# Add the new tags to the account
account.tag_ids = [(4, tag_id) for tag_id in new_tags]


def post_init(env):
assign_account_tags(env)
Loading

0 comments on commit 5046695

Please sign in to comment.