Allow galatea user by companies

#048340
This commit is contained in:
Raimon Esteve 2022-04-28 15:26:50 +02:00
parent 29b414891d
commit 93c83f8d48
4 changed files with 70 additions and 0 deletions

View File

@ -6,6 +6,7 @@ from . import activity
from . import bank
from . import employee
from . import carrier
from . import galatea
from . import party
from . import user
@ -32,3 +33,7 @@ def register():
carrier.Carrier,
depends=['carrier'],
module='party_company', type_='model')
Pool.register(
galatea.GalateaUser,
depends=['galatea'],
module='party_company', type_='model')

44
galatea.py Normal file
View File

@ -0,0 +1,44 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond.model import fields
from trytond.pyson import Eval
__all__ = ['GalateaUser']
class GalateaUser(metaclass=PoolMeta):
__name__ = 'galatea.user'
companies = fields.Function(fields.One2Many(
'company.company', None, 'Companies'), 'on_change_with_companies')
@classmethod
def __setup__(cls):
super(GalateaUser, cls).__setup__()
cls.websites.domain += [('company', 'in', Eval('companies'))]
cls.websites.depends += ['companies']
@fields.depends('party')
def on_change_with_companies(self, name=None):
User = Pool().get('res.user')
if self.party and self.party.companies:
return [c.id for c in self.party.companies]
else:
user = User(Transaction().user)
return [c.id for c in user.companies]
@staticmethod
def default_websites():
# overwrite default_websites from galatea module because add websites
# by company
pool = Pool()
Website = pool.get('galatea.website')
User = pool.get('res.user')
user = User(Transaction().user)
return [p.id for p in Website.search([
('registration', '=', True),
('company', '=', user.company)
])]

19
galatea.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data depends="galatea">
<!-- rule -->
<record model="ir.rule.group" id="rule_group_galatea_user">
<field name="name">User in company</field>
<field name="model" search="[('model', '=', 'galatea.user')]"/>
<field name="global_p" eval="True"/>
</record>
<record model="ir.rule" id="rule_galatea_user">
<field name="domain"
eval="[('websites.company', '=', Eval('user', {}).get('company', None))]"
pyson="1"/>
<field name="rule_group" ref="rule_group_galatea_user"/>
</record>
</data>
</tryton>

View File

@ -10,6 +10,7 @@ extras_depend:
bank
carrier
commission
galatea
sale_shop
stock
xml:
@ -18,6 +19,7 @@ xml:
carrier.xml
commission.xml
employee.xml
galatea.xml
party.xml
shop.xml
messages.xml