Skip to content

Commit

Permalink
account_financial_report: fix account_type field
Browse files Browse the repository at this point in the history
When porting from v14 to v17, the `account_account.user_type_id`
has been changed to `account_type`. Previously `general_ledger_wizard`
was able to store multiple account types through the `account_type_ids`
field. To simplify the forward porting, for now only one `account_type`
can be selected in the wizard.
  • Loading branch information
henrybackman committed Oct 16, 2024
1 parent 032fee9 commit 93daacf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions account_financial_report/tests/test_general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,19 +736,19 @@ def test_account_type_filter(self):
company_id = self.env.user.company_id
account_model = self.env["account.account"]
account = account_model.search([], limit=1)
account_type = account.user_type_id
account_type = account.account_type
accounts = account_model.search(
[
("company_id", "=", company_id.id),
("user_type_id", "in", account_type.ids),
("account_type", "=", account_type),
]
)
wizard = self.env["general.ledger.report.wizard"].create(
{"account_type_ids": account_type, "company_id": company_id.id}
{"account_type": account_type, "company_id": company_id.id}
)
wizard.onchange_company_id()
self.assertEqual(wizard.account_ids, accounts)

wizard.account_type_ids = False
wizard._onchange_account_type_ids()
wizard.account_type = False
wizard._onchange_account_type()
self.assertEqual(wizard.account_ids, account_model)
20 changes: 11 additions & 9 deletions account_financial_report/wizard/general_ledger_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class GeneralLedgerReportWizard(models.TransientModel):
)
receivable_accounts_only = fields.Boolean()
payable_accounts_only = fields.Boolean()
account_type_ids = fields.Many2many(
comodel_name="account.account.type",
string="Account Types",
account_type = fields.Selection(
selection="_get_account_type_selection",
)
partner_ids = fields.Many2many(
comodel_name="res.partner",
Expand Down Expand Up @@ -97,6 +96,9 @@ def _get_account_move_lines_domain(self):
domain = literal_eval(self.domain) if self.domain else []
return domain

def _get_account_type_selection(self):
return self.env["account.account"]._fields["account_type"].selection

@api.onchange("account_code_from", "account_code_to")
def on_change_account_range(self):
if (
Expand All @@ -115,13 +117,13 @@ def on_change_account_range(self):
lambda a: a.company_id == self.company_id
)

@api.onchange("account_type_ids")
def _onchange_account_type_ids(self):
if self.account_type_ids:
@api.onchange("account_type")
def _onchange_account_type(self):
if self.account_type:
self.account_ids = self.env["account.account"].search(
[
("company_id", "=", self.company_id.id),
("user_type_id", "in", self.account_type_ids.ids),
("account_type", "=", self.account_type),
]
)
else:
Expand Down Expand Up @@ -195,8 +197,8 @@ def onchange_company_id(self):
self.account_ids = self.account_ids.filtered(
lambda a: a.company_id == self.company_id
)
if self.company_id and self.account_type_ids:
self._onchange_account_type_ids()
if self.company_id and self.account_type:
self._onchange_account_type()
if self.company_id and self.cost_center_ids:
self.cost_center_ids = self.cost_center_ids.filtered(
lambda c: c.company_id == self.company_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@
/>
</div>
</div>
<field
name="account_type_ids"
widget="many2many_tags"
options="{'no_create': True}"
/>
<field name="account_type" widget="selection" />
<field
name="account_ids"
nolabel="1"
Expand Down

0 comments on commit 93daacf

Please sign in to comment.