From e955052e01f59a9bfeedc5dec3c85a7a6011bdd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 3 Oct 2021 00:42:46 +0200 Subject: [PATCH] Fill default accounts when creating chart issue10602 review359871002 --- __init__.py | 1 + account.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/__init__.py b/__init__.py index c6f084270d..c3e6599f88 100644 --- a/__init__.py +++ b/__init__.py @@ -33,6 +33,7 @@ def register(): reporting_tax.VATBookReport, module='account_es', type_='report') Pool.register( + account.CreateChart, reporting_tax.PrintAEAT, module='account_es', type_='wizard') Pool.register( diff --git a/account.py b/account.py index 19ff53a7b7..173d056fd0 100644 --- a/account.py +++ b/account.py @@ -143,6 +143,27 @@ class Tax(metaclass=PoolMeta): cls.write(*to_write) +class CreateChart(metaclass=PoolMeta): + __name__ = 'account.create_chart' + + def default_properties(self, fields): + pool = Pool() + ModelData = pool.get('ir.model.data') + defaults = super().default_properties(fields) + for type_ in ['normal', 'pyme']: + try: + template_id = ModelData.get_id('account_es.pgc_0_' + type_) + except KeyError: + continue + if self.account.account_template.id == template_id: + defaults['account_receivable'] = self.get_account( + 'account_es.pgc_4300_' + type_) + defaults['account_payable'] = self.get_account( + 'account_es.pgc_4000_' + type_) + break + return defaults + + class Invoice(metaclass=PoolMeta): __name__ = 'account.invoice'