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)},
depends=['code_readonly'],
code = fields.Char('Code', select=True,
states={
'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'),
'get_code_readonly')
......@@ -45,7 +47,13 @@ class Member(Workflow, ModelSQL, ModelView):
required=True,
help="The party that represents the member.")
join_date = fields.Date('Join Date',
states={'readonly': Eval('state') != 'draft'},
states={
'readonly':
Or(
Not(Eval('state').in_(['draft'])),
Eval('join_date', False)
),
'required': Eval('state') != 'draft'},
domain=[
If(
(Eval('join_date')) & (Eval('leave_date')),
......@@ -63,8 +71,12 @@ class Member(Workflow, ModelSQL, ModelView):
)],
depends=['join_date', 'state'],
states={
'readonly': Eval('state') != 'running',
'invisible': ~Eval('state').in_(['running', 'stopped'])
'invisible':
Or(
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:])]
@classmethod
def create(cls, vlist):
for values in vlist:
if not values.get('code'):
values['code'] = cls._new_code()
return super(Member, cls).create(vlist)
@classmethod
def copy(cls, members, default=None):
if default is None:
......@@ -161,10 +166,9 @@ class Member(Workflow, ModelSQL, ModelView):
@Workflow.transition('running')
def run(cls, members):
pool = Pool()
Date = pool.get('ir.date')
for member in members:
if not member.join_date:
member.join_date = Date.today()
if not member.code:
member.code = cls._new_code()
cls.save(members)
@classmethod
......@@ -172,19 +176,12 @@ class Member(Workflow, ModelSQL, ModelView):
@Workflow.transition('stopped')
def stop(cls, members):
pool = Pool()
Date = pool.get('ir.date')
Fee = pool.get('association.membership.fee')
pending_fees = Fee.search([('member', 'in', members)])
if not all(x.paid for x in pending_fees):
raise MemberUnpaidFeeError(
gettext('association.msg_unpaid_fee',
member=", ".join([x.rec_name for x in members])))
for member in members:
if not member.leave_date:
member.leave_date = Date.today()
cls.save(members)
......@@ -197,9 +194,7 @@ class MembersBookReport(Report):
pool = Pool()
Member = pool.get('association.member')
Company = pool.get('company.company')
clause = [('state', '!=', 'draft'), ('company', '=', data['company'])]
context = super(MembersBookReport, cls).get_context(records, data)
members = Member.search(clause)
context["members"] = members
......
......@@ -114,6 +114,7 @@ Test memebrship fee::
Make member active::
>>> member.join_date = start_date
>>> member.click('run')
>>> member.state
'running'
......
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