Skip to content
Snippets Groups Projects
Commit b534fe91 authored by Houzefa Abbasbhay's avatar Houzefa Abbasbhay :slight_smile:
Browse files

Fix account consultation partner filters:

* No accounting entry search when no accounts/partners (otherwise attempts to
  fetch every entry in the DB).
* Sync filters between account type / account / partners.
parent cfe85cda
No related branches found
No related tags found
No related merge requests found
......@@ -149,8 +149,8 @@
required=True,
)
@api.onchange("account_type_id")
def _handle_account_type_id_change(self):
"""Update selectable accounts based on the type."""
@api.onchange("account_type_id", "partner_id")
def _handle_account_criteria_change(self):
"""Update selectable accounts based on criteria."""
account_type = self.account_type_id.type
......@@ -155,5 +155,6 @@
account_type = self.account_type_id.type
partner = self.partner_id
if self.account_id.internal_type != account_type:
self.account_id = self.env["account.account"] # Clear out.
......@@ -161,7 +162,16 @@
account_domain = (
[("internal_type", "=", account_type)] if account_type else []
)
if partner:
accounts = self.env["account.account"]
for partner_field in self.get_partner_account_fields():
account = getattr(partner, partner_field)
if account:
accounts |= account
account_domain.append(("id", "in", accounts.ids))
return {"domain": {"account_id": account_domain}}
@api.onchange(
"account_id",
......@@ -164,7 +174,8 @@
return {"domain": {"account_id": account_domain}}
@api.onchange(
"account_id",
"partner_id",
"period_from_id",
"period_to_id",
"due_date_from",
......@@ -199,6 +210,17 @@
),
)
def get_partner_account_fields(self):
"""Provide partner fields that reference accounts. This method is here
to allow overrides.
:rtype: String list.
"""
return [
"property_account_receivable_id",
"property_account_payable_id",
]
@api.multi
def open_aml_list(self, list_view_ref, list_view_title):
"""Open the accounting entry list for the specified account.
......@@ -314,4 +336,9 @@
accounting entries.
"""
account = self.account_id
partner = self.partner_id
if not account and not partner:
return [("id", "=", 0)] # Not enough criteria.
aml_domain = []
......@@ -317,8 +344,14 @@
aml_domain = []
if self.partner_id:
aml_domain += self._build_aml_partner_domain()
if self.account_id:
aml_domain += [("account_id", "=", self.account_id.id)]
if account:
aml_domain = [("account_id", "=", account.id)]
elif partner:
accounts = self.env["account.account"]
for partner_field in self.get_partner_account_fields():
account = getattr(partner, partner_field)
if account:
accounts |= account
aml_domain = [("account_id", "in", accounts.ids)]
period_states = ["draft"]
if self.include_closed_periods:
......@@ -356,26 +389,6 @@
return aml_domain
@api.multi
def _build_aml_partner_domain(self):
partner = self.partner_id
partner_fields = self._get_aml_partner_fields()
accounts = self.env["account.account"]
for partner_field in partner_fields:
accounts |= getattr(partner, partner_field)
return [("account_id", "in", accounts.ids)]
@api.model
def _get_aml_partner_fields(self):
return [
"property_account_receivable_id",
"property_account_payable_id",
]
def _refresh_ref_preview(self):
"""Update the ref preview."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment