diff --git a/l10n_nl_rgs/models/account_account.py b/l10n_nl_rgs/models/account_account.py index b3d2f26..0b16cb3 100644 --- a/l10n_nl_rgs/models/account_account.py +++ b/l10n_nl_rgs/models/account_account.py @@ -13,7 +13,7 @@ class AccountAccount(models.Model): sort_code = fields.Char(string="Sorting code") def write(self, vals): - resp = super(AccountAccount, self).write(vals) + resp = super().write(vals) for rec in self.filtered( lambda acc: not acc.referentiecode diff --git a/l10n_nl_rgs/models/account_chart_template.py b/l10n_nl_rgs/models/account_chart_template.py index 44ef3c2..8bb32d9 100644 --- a/l10n_nl_rgs/models/account_chart_template.py +++ b/l10n_nl_rgs/models/account_chart_template.py @@ -68,22 +68,23 @@ def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None): for journal in resp_journals: if journal["code"] == "CABA": journal["active"] = False - if journal["type"] == "general" and journal["code"] == _("EXCH"): - journal["subtype"] = "general_exch" - if journal["type"] == "general" and journal["code"] == _("MISC"): - journal["subtype"] = "general_misc" - if journal["type"] == "general" and journal["code"] == _("ACCR"): - journal["subtype"] = "general_accr" - if journal["type"] == "general" and journal["code"] == _("DEPR"): - journal["subtype"] = "general_depr" - if journal["type"] == "general" and journal["code"] == _("FCR"): - journal["subtype"] = "general_fcr" - if journal["type"] == "general" and journal["code"] == _("WAG"): - journal["subtype"] = "general_wag" - if journal["type"] == "general" and journal["code"] == _("STJ"): - journal["subtype"] = "general_stj" - if journal["type"] == "general" and journal["code"] == _("TAX"): - journal["subtype"] = "general_tax" + if journal["type"] == "general": + subtype = "general_misc" + if journal["code"] == _("EXCH"): + subtype = "general_exch" + elif journal["code"] == _("ACCR"): + subtype = "general_accr" + elif journal["code"] == _("DEPR"): + subtype = "general_depr" + elif journal["code"] == _("FCR"): + subtype = "general_fcr" + elif journal["code"] == _("WAG"): + subtype = "general_wag" + elif journal["code"] == _("STJ"): + subtype = "general_stj" + elif journal["code"] == _("TAX"): + subtype = "general_tax" + journal["subtype"] = subtype return resp_journals @api.model @@ -319,6 +320,11 @@ def add_account_group_allowed_journals(self, company): if journals: group.allowed_journal_ids = journals + # Set the accounts allowed journal + all_groups = self.env["account.group"].search([("company_id", "=", company.id)]) + for group in all_groups: + group.accounts_set_allowed_journals() + def get_allowed_account_journals_based_on_type(self, all_journals, type_list): return all_journals.filtered(lambda j: j.type in type_list) diff --git a/l10n_nl_rgs/models/account_group.py b/l10n_nl_rgs/models/account_group.py index 09c4ef2..fa43b7d 100644 --- a/l10n_nl_rgs/models/account_group.py +++ b/l10n_nl_rgs/models/account_group.py @@ -73,13 +73,10 @@ def create(self, vals_list): return records def accounts_set_allowed_journals(self): - for rec in self: - if rec.auto_allowed_journals: - rec.with_context( - group_allowed_journal_change=True - ).account_ids.allowed_journal_ids = rec.active_allowed_journal_ids + for rec in self.filtered(lambda g: g.auto_allowed_journals): + rec.account_ids.group_set_allowed_journals() - @api.depends("parent_id", "parent_id.allowed_journal_ids") + @api.depends("parent_id", "parent_id.allowed_journal_ids", "allowed_journal_ids") @api.onchange("parent_id", "allowed_journal_ids") def _compute_active_allowed_journals(self): for rec in self: