Commit 83d9a785 authored by Luca Cristaldi's avatar Luca Cristaldi
Browse files

Add print membership wizard and report

Some code refactoring
Fix member search
Move the memberships view in the Configuration tab
add documentation
parent 4e331564
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -20,11 +20,15 @@ def register():
        Move,
        GenerateFeeStart,
        Cron,
        PrintMembersBookStart,
        module='association', type_='model')

    Pool.register(
        PostFee,
        GenerateFee,
        MembersBookWizard,
        module='association', type_='wizard')

    Pool.register(module='association', type_='report')
    Pool.register(
        MembersBookReport,
    module='association', type_='report')
+74 −22
Original line number Diff line number Diff line
Association Module
##################
* association.membership
    * name
    * periods
    * account_revenue
    * company (from CompanyMultiValueMixin)
* association.membership.period
    * name
    * start_date
    * end_date
    * amount
    * membership (many2One)
    * company (function)
* association.membership.fee
    * member (many2one of association.member)
    * amount
    * period (the association.membership.period associated to this line)
    * payment_lines (a function field, like the one in the invoice model)
    * move (the account.move.line associate with this fee line)
    * paid (store the date when the move was reconciled)
    * company (from CompanyMultiValueMixin)
===========
Association
===========
------
Member
------
A member is defined by:
 * code: a sequential code, you can specify the format in the Configuration tab
 * Party: The party associated with this member
 * join_date: The date were the member joins the association
 * leave_date: The date were the member leaves the association
 * memberships: A list of Mebership Line

If you want easilly check if the member paied all his fees, you can use the "Fees" relate utility.

---------------
Membership Line
---------------
The membership line is used to specify the starting and ending date of the membership.
This so you can selecet a starting/ending date different from the member one.
If you leave the fields empty, it will use the join/leave date from the member.
A membership line is defined by:
 * membership: the membership the member enrolled
 * start_date: the strating date, if not specified use the join date from the member will be used
 * end_date: the ending date, if not specified the leave date from the member will be used

This is used by the "Create Fees" Wizard to filter wich period the user should be billed


----------
Membership
----------
A membership is a collection of Periods.
The list must contain Periods with no overlapping date.
A Membership is defined by:
 * name:            The name of the Membership
 * journal:         The Journal that will be used for posting accounting move
 * account_revenue: The account revenue that will be used for posting accounting move
 * periods:         A list of Periods

*******************
Print Member's Book
*******************
This wizard will print a Report of all the member that are not in the draft state.

------
Period
------
A periods define a date range and what the member should pay for the period
A period is defined by:
 * start_date:  the starting date of the period
 * end_date:    the ending date of the period
 * fee:         the amount that the member should pay for this period

---
Fee
---
A fee is associated to a Member and a Period.
Tryton will check if a Member have Fees with the same period,and will throw an error if you try to do so.
A feee is defined as:
 * member:  The Member associated with this fee
 * period:  The Period associated with this fee
 * move:    The move associated with this fee

The module will check if the move is reconciled and posted, if so the paid field will be checked.
You can post the move via the Post button/action, or manually.

******************
Create Fees Wizard
******************
The wizard will generate fee record based on the date.
This wizard is used by the cronjob that will trigger (by default) once every day.

+1 −7
Original line number Diff line number Diff line
@@ -16,12 +16,6 @@ class DateNotInPeriodError(PeriodValidationError):
class SequenceMissingError(ValidationError):
    pass


class MemberUnpaiedFeeError(ValidationError):
    pass


#cls._error_messages.update({
#            'no_sequence':
#            ('No sequence defined for member. You must '
#             'define a sequence or enter the member\'s number.'),
#        })
+76 −27
Original line number Diff line number Diff line
@@ -3,12 +3,13 @@ from trytond.pyson import Eval, If
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.i18n import gettext

from trytond.wizard import Wizard, StateView, Button, StateReport
from trytond.report import Report
from .exceptions import MemberUnpaiedFeeError

#TODO: create code only on state running, view subscription

__all__ = ['Member']
__all__ = [
    'Member', 'MembersBookWizard', 'PrintMembersBookStart', 'MembersBookReport'
]

STATES = [
    ('draft', 'Draft'),
@@ -22,12 +23,13 @@ _STATE = {'readonly': Eval('state') != 'draft'}


class Member(Workflow, ModelSQL, ModelView):
    """Member"""
    'Member'
    __name__ = "association.member"

    _rec_name = 'party_name'

    party_name = fields.Function(fields.Char("Party Name"), 'on_change_with_party_name')
    party_name = fields.Function(fields.Char("Party Name"),
                                 'on_change_with_party_name',searcher='search_party_member')
    state = fields.Selection(STATES, 'State', readonly=True)
    code = fields.Char('Code',
                       required=True,
@@ -37,9 +39,8 @@ class Member(Workflow, ModelSQL, ModelView):
                       help="The unique identifier of the associate.")
    code_readonly = fields.Function(fields.Boolean('Code Readonly'),
                                    'get_code_readonly')
    association = fields.Many2One(
        'company.company',
        'Association',
    company = fields.Many2One('company.company',
                              'Company',
                              states=_STATE,
                              depends=_DEPENDS,
                              required=True,
@@ -86,12 +87,7 @@ class Member(Workflow, ModelSQL, ModelView):
        "Memberships",
        depends=['state'],
        states={'readonly': Eval('state') != 'draft'})
    # fees = fields.One2Many('association.membership.fee',
    #                        'member',
    #                        'fee',
    #                        states={'readonly': Eval('state') != 'draft'},
    #                        depends=['state'])
    #TODO: check via sql verifi method


    @classmethod
    def __setup__(cls):
@@ -100,8 +96,7 @@ class Member(Workflow, ModelSQL, ModelView):
        cls._sql_constraints = [
            ('code_uniq', Unique(t, t.code), 'Member code must be unique.'),
        ]
        cls._transitions |= {('draft', 'running'),
                             ('running', 'draft'),
        cls._transitions |= {('draft', 'running'), ('running', 'draft'),
                             ('running', 'stopped')}

        cls._buttons.update({
@@ -137,6 +132,10 @@ class Member(Workflow, ModelSQL, ModelView):
        if sequence:
            return Sequence.get_id(sequence.id)

    @classmethod
    def search_party_member(cls,name, clause):
        return [('party',) + tuple(clause[1:])]

    @classmethod
    def create(cls, vlist):
        for values in vlist:
@@ -157,16 +156,16 @@ class Member(Workflow, ModelSQL, ModelView):
    def default_state(cls):
        return 'draft'

    @classmethod
    def default_company(cls):
        return Transaction().context.get('company')

    @classmethod
    def default_code_readonly(cls, **pattern):
        Configuration = Pool().get('association.configuration')
        config = Configuration(1)
        return bool(config.get_multivalue('member_sequence', **pattern))

    @classmethod
    def default_association(cls):
        return Transaction().context.get('company')

    @classmethod
    @ModelView.button
    @Workflow.transition('draft')
@@ -195,9 +194,59 @@ class Member(Workflow, ModelSQL, ModelView):
        pending_fees = Fee.search([('member', 'in', members)])

        if not all(x.paid for x in pending_fees):
            raise MemberUnpaiedFeeError(gettext('association.msg_unpaid_fee',member=", ".join([x.party_name for x in members])))
            raise MemberUnpaiedFeeError(
                gettext('association.msg_unpaid_fee',
                        member=", ".join([x.party_name for x in members])))

        for member in members:
            if not member.leave_date:
                member.leave_date = Date.today()
        cls.save(members)


class MembersBookReport(Report):
    'Members Book report'
    __name__ = 'association.member_print'

    @classmethod
    def get_context(cls, records, data):
        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
        context["company"] = Company(data['company'])
        print(context)
        return context


class PrintMembersBookStart(ModelView):
    'Print Members Book'
    __name__ = 'association.member.print_member_book.start'
    company = fields.Many2One('company.company', 'Company', required=True)

    @staticmethod
    def default_company():
        return Transaction().context.get('company')


class MembersBookWizard(Wizard):
    'Print member book'
    __name__ = 'association.member.print_member_book'
    start = StateView(
        'association.member.print_member_book.start',
        'association.print_member_book_start_view_from', [
            Button('Cancel', 'end', 'tryton-cancel'),
            Button('Print', 'print_', 'tryton-print', default=True)
        ])
    print_ = StateReport('association.member_print')

    def do_print_(self, action):
        data = {
            'company': self.start.company.id,
        }
        return action, data
+23 −0
Original line number Diff line number Diff line
@@ -128,5 +128,28 @@
            <field name="name">Member</field>
            <field name="code">association.member</field>
        </record>
        <!-- Report -->
        <record model="ir.action.report" id="report_members_book">
            <field name="name">Member Book</field>
            <field name="model">association.member</field>
            <field name="report_name">association.member_print</field>
            <field name="report">association/memberbook.fodt</field>
        </record>
        <record model="ir.action.keyword" id="report_members_book_keyword">
            <field name="keyword">form_print</field>
            <field name="model">association.member,-1</field>
            <field name="action" ref="report_members_book"/>
        </record>
        <!-- Wizard -->
        <record model="ir.ui.view" id="print_member_book_start_view_from">
            <field name="model">association.member.print_member_book.start</field>
            <field name="type">form</field>
            <field name="name">members_book_start_form</field>
        </record>
        <record model="ir.action.wizard" id="wizard_print_member_book">
            <field name="name">Print Member Book</field>
            <field name="wiz_name">association.member.print_member_book</field>
        </record>
        <menuitem parent="menu_association" sequence="80" action="wizard_print_member_book" id="menu_wizard_print_member_book" icon="tryton-print"/>
    </data>
</tryton>
 No newline at end of file
Loading