Commit bfffe87d authored by Luca Cristaldi's avatar Luca Cristaldi

join_date and leave_date now require user input

parent c75d50b2
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import Workflow, ModelView, ModelSQL, fields, Unique
from trytond.pyson import Eval, If
from trytond.pyson import Eval, If, Bool, Not, And, Or
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.i18n import gettext
......@@ -30,9 +30,11 @@ class Member(Workflow, ModelSQL, ModelView):
__name__ = "association.member"
state = fields.Selection(STATES, 'State', readonly=True)
code = fields.Char('Code', required=True, select=True,
states={'readonly': Eval('code_readonly', True)},
code = fields.Char('Code', select=True,
'readonly': Eval('code_readonly', True),
'required': Eval('state') != 'draft'},
depends=['code_readonly', 'state'],
help="The internal identifier for the associate.")
code_readonly = fields.Function(fields.Boolean('Code Readonly'),
......@@ -45,7 +47,13 @@ class Member(Workflow, ModelSQL, ModelView):
help="The party that represents the member.")
join_date = fields.Date('Join Date',
states={'readonly': Eval('state') != 'draft'},
Eval('join_date', False)
'required': Eval('state') != 'draft'},
(Eval('join_date')) & (Eval('leave_date')),
......@@ -63,8 +71,12 @@ class Member(Workflow, ModelSQL, ModelView):
depends=['join_date', 'state'],
'readonly': Eval('state') != 'running',
'invisible': ~Eval('state').in_(['running', 'stopped'])
Not(Eval('state').in_(['running', 'stopped'])),
Eval('leave_date', False)
'readonly': Eval('state') != 'running'
help="The date the member left the association.")
memberships = fields.One2Many('association.membership', 'member',
......@@ -120,13 +132,6 @@ class Member(Workflow, ModelSQL, ModelView):
def search_rec_name(cls, name, clause):
return [('party', ) + tuple(clause[1:])]
def create(cls, vlist):
for values in vlist:
if not values.get('code'):
values['code'] = cls._new_code()
return super(Member, cls).create(vlist)
def copy(cls, members, default=None):
if default is None:
......@@ -161,10 +166,9 @@ class Member(Workflow, ModelSQL, ModelView):
def run(cls, members):
pool = Pool()
Date = pool.get('')
for member in members:
if not member.join_date:
member.join_date =
if not member.code:
member.code = cls._new_code()
......@@ -172,19 +176,12 @@ class Member(Workflow, ModelSQL, ModelView):
def stop(cls, members):
pool = Pool()
Date = pool.get('')
Fee = pool.get('association.membership.fee')
pending_fees =[('member', 'in', members)])
if not all(x.paid for x in pending_fees):
raise MemberUnpaidFeeError(
member=", ".join([x.rec_name for x in members])))
for member in members:
if not member.leave_date:
member.leave_date =
......@@ -197,9 +194,7 @@ class MembersBookReport(Report):
pool = Pool()
Member = pool.get('association.member')
Company = pool.get('')
clause = [('state', '!=', 'draft'), ('company', '=', data['company'])]
context = super(MembersBookReport, cls).get_context(records, data)
members =
context["members"] = members
......@@ -114,6 +114,7 @@ Test memebrship fee::
Make member active::
>>> member.join_date = start_date
>>> member.state
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