Commit c75d50b2 authored by Luca Cristaldi's avatar Luca Cristaldi

Add company and company domain checks

parent 3b230280
......@@ -44,7 +44,6 @@ class Member(Workflow, ModelSQL, ModelView):
depends=_DEPENDS,
required=True,
help="The party that represents the member.")
join_date = fields.Date('Join Date',
states={'readonly': Eval('state') != 'draft'},
domain=[
......@@ -70,7 +69,10 @@ class Member(Workflow, ModelSQL, ModelView):
help="The date the member left the association.")
memberships = fields.One2Many('association.membership', 'member',
"Memberships",
depends=['state'],
domain=[
('company', '=', Eval('context', {}).get('company', -1))
],
depends=['state', 'company'],
states={'readonly': Eval('state') != 'draft'})
@classmethod
......@@ -202,7 +204,6 @@ class MembersBookReport(Report):
members = Member.search(clause)
context["members"] = members
context["company"] = Company(data['company'])
print(context)
return context
......
......@@ -64,28 +64,28 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.action.act_window.domain" id="act_members_form_domain_draft">
<field name="name">Draft</field>
<field name="sequence" eval="10" />
<field name="domain" eval="[('state', '=', 'draft')]" pyson="1" />
<field name="domain" eval="[('state', '=', 'draft'), ('company', '=', Eval('context', {}).get('company', -1))]" pyson="1" />
<field name="count" eval="True" />
<field name="act_window" ref="act_members_form" />
</record>
<record model="ir.action.act_window.domain" id="act_members_form_domain_accepted">
<field name="name">Running</field>
<field name="sequence" eval="30" />
<field name="domain" eval="[('state', '=', 'running')]" pyson="1" />
<field name="domain" eval="[('state', '=', 'running'), ('company', '=', Eval('context', {}).get('company', -1))]" pyson="1" />
<field name="count" eval="True" />
<field name="act_window" ref="act_members_form" />
</record>
<record model="ir.action.act_window.domain" id="act_members_form_domain_expelled">
<field name="name">Stopped</field>
<field name="sequence" eval="40" />
<field name="domain" eval="[('state', '=', 'stopped')]" pyson="1" />
<field name="domain" eval="[('state', '=', 'stopped'), ('company', '=', Eval('context', {}).get('company', -1))]" pyson="1" />
<field name="count" eval="True" />
<field name="act_window" ref="act_members_form" />
</record>
<record model="ir.action.act_window.domain" id="act_members_form_domain_all">
<field name="name">All</field>
<field name="sequence" eval="40" />
<field name="domain" eval="[('state', '!=', 'draft')]" pyson="1" />
<field name="domain" eval="[('state', '!=', 'draft'), ('company', '=', Eval('context', {}).get('company', -1))]" pyson="1" />
<field name="count" eval="False" />
<field name="act_window" ref="act_members_form" />
</record>
......
......@@ -21,9 +21,7 @@ __all__ = [
fee_digit = (16, config.getint('membership', 'fee_decimal', default=4))
fee_amount = fields.Numeric("Fee Amount", fee_digit, required=True)
_STATES = {'readonly': Eval('state') != 'open'}
_LINE_STATES = {'readonly': Eval('member_state', '') != 'draft'}
_LINE_STATES = {'readonly': Eval('member_state') != 'draft'}
_FEE_STATES = {
'readonly':
......@@ -68,9 +66,7 @@ class MembershipType(ModelSQL, ModelView):
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', -1)),
],
ondelete='RESTRICT',
states=_FEE_STATES,
help="The association that the membership type belongs to.")
ondelete='RESTRICT')
@classmethod
def default_company(cls):
......@@ -83,12 +79,23 @@ class Membership(ModelSQL, ModelView):
member = fields.Many2One('association.member', "Member",
states=_LINE_STATES,
depends=['member_state'],
domain=[
('company', '=', Eval('context', {}).get('company', -1))
],
depends=['member_state', 'company'],
ondelete='CASCADE')
membership = fields.Many2One('association.membership.type', "Membership",
depends=['member_state'],
domain=[
('company', '=', Eval('context', {}).get('company', -1))
],
depends=['member_state', 'company'],
states=_LINE_STATES,
ondelete='RESTRICT')
company = fields.Many2One('company.company', 'Company', required=True,
domain=[
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', -1)),
], select=True, states=_LINE_STATES, depends=['member_state'])
start_date = fields.Date('Start Date',
domain=[
If(
......@@ -117,6 +124,10 @@ class Membership(ModelSQL, ModelView):
member_leave_date = fields.Function(fields.Date("Member Leave Date"),
'on_change_with_member_leave_date')
@classmethod
def default_company(cls):
return Transaction().context.get('company')
@fields.depends('member', '_parent_member.state')
def on_change_with_member_state(self, name=None):
if self.member:
......@@ -139,8 +150,11 @@ class Period(ModelSQL, ModelView):
membership = fields.Many2One('association.membership.type', 'Membership',
required=True,
states=_STATES,
select=True,
domain=[
('company', '=', Eval('context', {}).get('company', -1))
],
depends=['company'],
ondelete='RESTRICT')
company = fields.Many2One('company.company', 'Company', required=True,
select=True,
......@@ -148,8 +162,7 @@ class Period(ModelSQL, ModelView):
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', -1)),
],
ondelete='RESTRICT',
states=_FEE_STATES)
ondelete='RESTRICT')
name = fields.Char('Name', size=None, required=True)
start_date = fields.Date('Starting Date', required=True,
domain=[
......
......@@ -3,7 +3,7 @@
this repository contains the full copyright notices and license terms. -->
<tryton>
<data depends="">
<!-- Membership -->
<!-- Membership Type-->
<record model="ir.ui.view" id="view_membership_type_tree">
<field name="model">association.membership.type</field>
<field name="type">tree</field>
......@@ -17,6 +17,7 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.action.act_window" id="act_membership_type_form">
<field name="name">Membership Types</field>
<field name="res_model">association.membership.type</field>
<field name="domain" eval="[('company', '=', Eval('context', {}).get('company', -1))]" pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_membership_type_form1">
<field name="sequence">10</field>
......@@ -86,6 +87,7 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.action.act_window" id="act_fee_form">
<field name="name">Fees</field>
<field name="res_model">association.membership.fee</field>
<field name="domain" eval="[('company', '=', Eval('context', {}).get('company', -1))]" pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_fee_form1">
<field name="sequence">10</field>
......@@ -159,7 +161,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="menu" ref="menu_act_membership_fee_create" />
<field name="group" ref="group_association_admin" />
</record>
<!-- membership line -->
<!-- membership -->
<record model="ir.ui.view" id="membership_view_tree_editable">
<field name="model">association.membership</field>
<field name="type">tree</field>
......@@ -218,7 +220,7 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.action.act_window" id="act_fees_form_relate">
<field name="name">Fees</field>
<field name="res_model">association.membership.fee</field>
<field name="domain" eval="[('member.id', 'in', Eval('active_ids'))]" pyson="1" />
<field name="domain" eval="[('member.id', 'in', Eval('active_ids')), ('company', '=', Eval('context', {}).get('company', -1))]" pyson="1" />
</record>
<record model="ir.action.keyword" id="act_open_fees_form_relate">
<field name="keyword">form_relate</field>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment