diff --git a/account_journal_subtype/models/__init__.py b/account_journal_subtype/models/__init__.py index 8011f8f..6f92994 100644 --- a/account_journal_subtype/models/__init__.py +++ b/account_journal_subtype/models/__init__.py @@ -1,3 +1,3 @@ # Copyright 2023 Onestein () # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from . import account_journal \ No newline at end of file +from . import account_journal diff --git a/account_journal_subtype/models/account_journal.py b/account_journal_subtype/models/account_journal.py index 548449d..681becf 100644 --- a/account_journal_subtype/models/account_journal.py +++ b/account_journal_subtype/models/account_journal.py @@ -6,7 +6,7 @@ class AccountJournal(models.Model): _inherit = "account.journal" - + subtype = fields.Selection( selection=[ ("general_misc", "Miscellaneous"), @@ -17,7 +17,5 @@ class AccountJournal(models.Model): ("general_stj", "Inventory revaluation"), ("general_fcr", "Foreign currency revaluation"), ("general_exch", "Exchange difference"), - ]) - - - \ No newline at end of file + ] + ) diff --git a/l10n_nl_rgs/models/account_account.py b/l10n_nl_rgs/models/account_account.py index c6a3153..b3d2f26 100644 --- a/l10n_nl_rgs/models/account_account.py +++ b/l10n_nl_rgs/models/account_account.py @@ -28,7 +28,9 @@ def write(self, vals): def group_set_allowed_journals(self): for rec in self: if rec.group_id and rec.group_id.auto_allowed_journals: - rec.with_context(group_allowed_journal_change=True).allowed_journal_ids = rec.group_id.active_allowed_journal_ids + rec.with_context( + group_allowed_journal_change=True + ).allowed_journal_ids = rec.group_id.active_allowed_journal_ids @api.model_create_multi def create(self, vals_list): @@ -36,4 +38,3 @@ def create(self, vals_list): if not self._context.get("group_allowed_journal_change"): records.group_set_allowed_journals() return records - \ No newline at end of file diff --git a/l10n_nl_rgs/models/account_chart_template.py b/l10n_nl_rgs/models/account_chart_template.py index 89bcbf7..031f113 100644 --- a/l10n_nl_rgs/models/account_chart_template.py +++ b/l10n_nl_rgs/models/account_chart_template.py @@ -21,7 +21,7 @@ def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None): "code": _("ACCR"), "favorite": True, "color": 11, - "sequence": 15 + "sequence": 15, }, { "name": _("Depreciations"), @@ -292,7 +292,7 @@ def add_account_group_allowed_journals(self, company): ("company_id", "=", company.id), ] ) - + for group_template in group_templates: group = all_groups.filtered( lambda g: g.referentiecode == group_template.referentiecode @@ -324,13 +324,13 @@ def get_allowed_account_journals_based_on_type(self, all_journals, type_list): def get_allowed_account_journals_based_on_code(self, all_journals, code_list): subtype_mapping = { - "WAG": "general_wag", + "WAG": "general_wag", "DEPR": "general_depr", "FCR": "general_fcr", "STJ": "general_stj", "TAX": "general_tax", "MISC": "general_misc", - } + } subtype_list = [] for k, v in subtype_mapping.items(): if k in code_list and v not in subtype_list: diff --git a/l10n_nl_rgs/models/account_group.py b/l10n_nl_rgs/models/account_group.py index 44ac8b6..09c4ef2 100644 --- a/l10n_nl_rgs/models/account_group.py +++ b/l10n_nl_rgs/models/account_group.py @@ -14,19 +14,21 @@ class AccountGroup(models.Model): code = fields.Char() sort_code = fields.Char(string="Sorting code") allowed_journal_ids = fields.Many2many( - comodel_name="account.journal", string="Saved Allowed Journals", - help="Define in which journals this account can be used. If empty, can be used in all journals." + comodel_name="account.journal", + string="Saved Allowed Journals", + help="Define in which journals this account can be used. If empty, can be used in all journals.", ) active_allowed_journal_ids = fields.Many2many( - comodel_name="account.journal", string="Allowed Journals", + comodel_name="account.journal", + string="Allowed Journals", help="This is the allowed journal for this group. It's calculated from all parent_groups", - compute="compute_active_allowed_journals", - inverse="set_allowed_journals" + compute="_compute_active_allowed_journals", + inverse="_inverse_set_allowed_journals", ) auto_allowed_journals = fields.Boolean( string="Automatic Allowed Journals", default=True, - help="If Automatic Allowed Journals is on. Changes here will be brought to the underlying accounts." + help="If Automatic Allowed Journals is on. Changes here will be brought to the underlying accounts.", ) # From account financial report group_child_ids = fields.One2many( @@ -35,7 +37,7 @@ class AccountGroup(models.Model): account_ids = fields.One2many( comodel_name="account.account", inverse_name="group_id", string="Accounts" ) - + def _adapt_parent_account_group(self): if self.company_id.chart_template_id != self.env.ref( "l10n_nl_rgs.l10nnl_rgs_chart_template", False @@ -49,7 +51,7 @@ def get_all_account_ids(self): if rec.group_child_ids: accounts |= rec.group_child_ids.get_all_account_ids() return accounts - + def get_all_allowed_journal_ids(self): allowed_journals = self.env["account.journal"] for rec in self: @@ -63,25 +65,27 @@ def write(self, vals): # Always check the allowed journals if auto_allowed_journals self.accounts_set_allowed_journals() return ret - + @api.model_create_multi def create(self, vals_list): records = super().create(vals_list) records.accounts_set_allowed_journals() 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 + rec.with_context( + group_allowed_journal_change=True + ).account_ids.allowed_journal_ids = rec.active_allowed_journal_ids - @api.depends('parent_id','parent_id.allowed_journal_ids') - @api.onchange('parent_id', 'allowed_journal_ids') - def compute_active_allowed_journals(self): + @api.depends("parent_id", "parent_id.allowed_journal_ids") + @api.onchange("parent_id", "allowed_journal_ids") + def _compute_active_allowed_journals(self): for rec in self: rec.active_allowed_journal_ids = rec.get_all_allowed_journal_ids() - def set_allowed_journals(self): + def _inverse_set_allowed_journals(self): for rec in self: parent_journals = rec.parent_id.get_all_allowed_journal_ids() rec.allowed_journal_ids = rec.active_allowed_journal_ids - parent_journals