Skip to content

Commit

Permalink
extra pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreschenkels authored and tarteo committed May 7, 2024
1 parent 3becce5 commit f987631
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion account_journal_subtype/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright 2023 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import account_journal
from . import account_journal
8 changes: 3 additions & 5 deletions account_journal_subtype/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AccountJournal(models.Model):
_inherit = "account.journal"

subtype = fields.Selection(
selection=[
("general_misc", "Miscellaneous"),
Expand All @@ -17,7 +17,5 @@ class AccountJournal(models.Model):
("general_stj", "Inventory revaluation"),
("general_fcr", "Foreign currency revaluation"),
("general_exch", "Exchange difference"),
])



]
)
5 changes: 3 additions & 2 deletions l10n_nl_rgs/models/account_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ 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):
records = super().create(vals_list)
if not self._context.get("group_allowed_journal_change"):
records.group_set_allowed_journals()
return records

8 changes: 4 additions & 4 deletions l10n_nl_rgs/models/account_chart_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
34 changes: 19 additions & 15 deletions l10n_nl_rgs/models/account_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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

0 comments on commit f987631

Please sign in to comment.