From 77cee84711a13c32eff747fa66612a9b581dbaeb Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Mon, 28 Nov 2022 18:13:59 +0100 Subject: [PATCH] Filter parties without parties and filter bank account by owner companies 072165 --- activity.xml | 2 +- bank.py | 40 +++++++++++++++++++++++++++++++++++++- bank.xml | 10 ++++++++-- carrier.xml | 2 +- commission.xml | 4 ++-- employee.xml | 2 +- locale/ca.po | 4 ++++ locale/es.po | 4 ++++ tests/test_module.py | 1 + view/bank_account_form.xml | 8 ++++++++ 10 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 view/bank_account_form.xml diff --git a/activity.xml b/activity.xml index 005b535..dde3c38 100644 --- a/activity.xml +++ b/activity.xml @@ -10,7 +10,7 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/bank.py b/bank.py index 85381ed..9a2425b 100644 --- a/bank.py +++ b/bank.py @@ -1,7 +1,8 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. from trytond.model import fields -from trytond.pool import PoolMeta +from trytond.pool import Pool, PoolMeta +from trytond.transaction import Transaction from . import party @@ -13,6 +14,15 @@ class BankAccount(metaclass=PoolMeta): __name__ = 'bank.account' companies = fields.Function(fields.One2Many('company.company', None, 'Companies'), 'get_companies', searcher='search_companies') + owners_by_companies = fields.Function( + fields.Many2Many('bank.account-party.party', 'account', 'owner', + 'Owners'), 'get_owners_by_companies', setter='set_owners_by_companies') + + @classmethod + def create(cls, vlist): + # allow create bank accounts from party when not select owners + with Transaction().set_context(_check_access=False): + return super(BankAccount, cls).create(vlist) def get_companies(self, name): if self.bank: @@ -21,3 +31,31 @@ class BankAccount(metaclass=PoolMeta): @classmethod def search_companies(cls, name, clause): return [('bank.party.companies',) + tuple(clause[1:])] + + @classmethod + def get_owners_by_companies(cls, records, name): + PartyCompany = Pool().get('party.company.rel') + + user_company = Transaction().context.get('company') + + res = dict((x.id, None) for x in records) + for record in records: + owners = [] + + for owner in record.owners: + owner_companies = [o.company for o in PartyCompany.search([ + ('party', '=', owner), + ])] + if not owner_companies: + owners.append(owner) + continue + for company in owner_companies: + if company.id == user_company: + owners.append(owner) + break + res[record.id] = [o.id for o in owners] + return res + + @classmethod + def set_owners_by_companies(cls, records, name, value): + cls.write(records, {'owners': value}) diff --git a/bank.xml b/bank.xml index 3ce381d..709e383 100644 --- a/bank.xml +++ b/bank.xml @@ -4,13 +4,19 @@ this repository contains the full copyright notices and license terms. --> + + bank.account + + bank_account_form + + Bank Company Rule - + @@ -20,7 +26,7 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/carrier.xml b/carrier.xml index 77a5ea7..05cf79c 100644 --- a/carrier.xml +++ b/carrier.xml @@ -10,7 +10,7 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/commission.xml b/commission.xml index 77dd2a5..df0236e 100644 --- a/commission.xml +++ b/commission.xml @@ -10,7 +10,7 @@ this repository contains the full copyright notices and license terms. --> - + @@ -21,7 +21,7 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/employee.xml b/employee.xml index 5b09218..f88d709 100644 --- a/employee.xml +++ b/employee.xml @@ -4,7 +4,7 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/locale/ca.po b/locale/ca.po index 41d354b..b7c5ff3 100644 --- a/locale/ca.po +++ b/locale/ca.po @@ -10,6 +10,10 @@ msgctxt "field:bank.account,companies:" msgid "Companies" msgstr "Empreses" +msgctxt "field:bank.account,owners_by_companies:" +msgid "Owners" +msgstr "Titulars" + msgctxt "field:carrier,companies:" msgid "Companies" msgstr "Empreses" diff --git a/locale/es.po b/locale/es.po index 9f1ff0a..05aa59a 100644 --- a/locale/es.po +++ b/locale/es.po @@ -10,6 +10,10 @@ msgctxt "field:bank.account,companies:" msgid "Companies" msgstr "Empresas" +msgctxt "field:bank.account,owners_by_companies:" +msgid "Owners" +msgstr "Titulares" + msgctxt "field:carrier,companies:" msgid "Companies" msgstr "Empresas" diff --git a/tests/test_module.py b/tests/test_module.py index e9a5b79..303dfa1 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -24,6 +24,7 @@ def set_company(company): class PartyCompanyTestCase(CompanyTestMixin, ModuleTestCase): 'Test PartyCompany module' module = 'party_company' + extras = ['bank'] @with_transaction() def test_party(self): diff --git a/view/bank_account_form.xml b/view/bank_account_form.xml new file mode 100644 index 0000000..7e970e6 --- /dev/null +++ b/view/bank_account_form.xml @@ -0,0 +1,8 @@ + + + + + + +