From 465d15d4b218b525b92d113991bcb66aef015b62 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 25 Nov 2024 08:35:37 +0000 Subject: [PATCH] [IMP] l10n_fr_account_vat_return: make it easy to inherit adjust account codes Code clean-up in computation of adjust accounts --- .../models/l10n_fr_account_vat_return.py | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/l10n_fr_account_vat_return/models/l10n_fr_account_vat_return.py b/l10n_fr_account_vat_return/models/l10n_fr_account_vat_return.py index c4fae3b1a..10ed17c96 100644 --- a/l10n_fr_account_vat_return/models/l10n_fr_account_vat_return.py +++ b/l10n_fr_account_vat_return/models/l10n_fr_account_vat_return.py @@ -370,6 +370,13 @@ def _prepare_speedy(self): # used to create negative boxes at the end "negative_box2logs": defaultdict(list), "vat_groups": ["regular", "extracom_product", "oil"], + "adjust_account_codes": { + "expense_adjust_account": ( + "658", + "Charges diverses de gestion courante", + ), + "income_adjust_account": ("758", "Produits divers de gestion courante"), + }, } speedy["bank_cash_journals"] = speedy["aj_obj"].search( speedy["company_domain"] + [("type", "in", ("bank", "cash"))] @@ -487,15 +494,10 @@ def _get_adjust_accounts(self, speedy): # that all French companies must use the PCG, # I select the account based on the code they should have self.ensure_one() - account_lookup = { - "expense_adjust_account": ("658", "Charges diverses de gestion courante"), - "income_adjust_account": ("758", "Produits divers de gestion courante"), - } - for key, (account_code, account_name) in account_lookup.items(): - limit = not account_code.startswith("445") and 1 or None + for key, (account_code, account_name) in speedy["adjust_account_codes"].items(): account = speedy["aa_obj"].search( speedy["company_domain"] + [("code", "=like", account_code + "%")], - limit=limit, + limit=1, ) if not account: raise UserError( @@ -507,18 +509,6 @@ def _get_adjust_accounts(self, speedy): company=self.company_id.display_name, ) ) - if len(account) > 1: - raise UserError( - _( - "There are %(count)d accounts " - "%(account_code)s %(account_name)s in the chart of account " - "of company '%(company)s'. This scenario is not supported.", - count=len(account), - account_code=account_code, - account_name=account_name, - company=self.company_id.display_name, - ) - ) speedy[key] = account def manual2auto(self):