Check the currecnt company of the user to filter the data, if company none, don't show any data.

Fix eval in party_* domains to it matches the new funcionality.

041579
This commit is contained in:
Juanjo Garcia 2020-10-21 11:59:42 +02:00
parent a46e207eba
commit 029afec510
2 changed files with 37 additions and 4 deletions

View File

@ -22,6 +22,9 @@ class Party(metaclass=PoolMeta):
]), 'get_companies',
searcher='search_companies_field', setter='set_companies_field')
current_company = fields.Function(fields.Boolean('Current Company'),
'get_current_company', searcher='search_current_company')
@classmethod
def __register__(cls, module_name):
pool = Pool()
@ -84,6 +87,16 @@ class Party(metaclass=PoolMeta):
where=(party_company.party.in_(party_ids))
))
def get_current_company(self, name):
pool = Pool()
User = pool.get('res.user')
user = User(Transaction().user)
for company in self.companies:
if company == user.company:
return True
return False
@classmethod
def get_companies(cls, parties, names):
pool = Pool()
@ -117,6 +130,26 @@ class Party(metaclass=PoolMeta):
result[name][party].append(value)
return result
@classmethod
def search_current_company(cls, name, clause):
pool = Pool()
PartyCompany = pool.get('party.company.rel')
User = pool.get('res.user')
party_company = PartyCompany.__table__()
user = User(Transaction().user)
if not user.company:
return [('id', '=', -1)]
query = party_company.select(party_company.party,
where=party_company.company==user.company)
if clause[2] == '=':
return [('id', 'in', query)]
elif clause[2] == '!=':
return [('id', 'not in', query)]
return []
@classmethod
def search_companies_field(cls, name, clause):
pool = Pool()

View File

@ -17,7 +17,7 @@ this repository contains the full copyright notices and license terms. -->
</record>
<record model="ir.rule" id="rule_party1">
<field name="domain"
eval="['OR', ('companies', 'in', [Eval('user', {}).get('company', None)]), ('companies', 'in', [])]"
eval="[('current_company', '=', True)]"
pyson="1"/>
<field name="rule_group" ref="rule_group_party"/>
</record>
@ -30,7 +30,7 @@ this repository contains the full copyright notices and license terms. -->
</record>
<record model="ir.rule" id="rule_address1">
<field name="domain"
eval="['OR', ('companies', 'in', [Eval('user', {}).get('company', None)]), ('companies', 'in', [])]"
eval="[('party.current_company', '=', True)]"
pyson="1"/>
<field name="rule_group" ref="rule_group_address"/>
</record>
@ -43,7 +43,7 @@ this repository contains the full copyright notices and license terms. -->
</record>
<record model="ir.rule" id="rule_identifier1">
<field name="domain"
eval="['OR', ('companies', 'in', [Eval('user', {}).get('company', None)]), ('companies', 'in', [])]"
eval="[('party.current_company', '=', True)]"
pyson="1"/>
<field name="rule_group" ref="rule_group_identifier"/>
</record>
@ -56,7 +56,7 @@ this repository contains the full copyright notices and license terms. -->
</record>
<record model="ir.rule" id="rule_contact_mechanism1">
<field name="domain"
eval="['OR', ('companies', 'in', [Eval('user', {}).get('company', None)]), ('companies', 'in', [])]"
eval="[('party.current_company', '=', True)]"
pyson="1"/>
<field name="rule_group" ref="rule_group_contact_mechanism"/>
</record>