Report API refactorization
review8831002
This commit is contained in:
+8
-6
@@ -45,7 +45,9 @@ class Letter(CompanyReport):
|
||||
__name__ = 'account.dunning.letter'
|
||||
|
||||
@classmethod
|
||||
def parse(cls, report, records, data, localcontext):
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(Letter, cls).get_context(records, data)
|
||||
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
@@ -72,11 +74,11 @@ class Letter(CompanyReport):
|
||||
continue
|
||||
letters[party] = PartyLetter(dunnings=current_dunnings,
|
||||
payments=current_payments)
|
||||
localcontext['letters'] = letters
|
||||
localcontext['today'] = Date.today()
|
||||
localcontext['get_payment_amount'] = cls.get_payment_amount
|
||||
localcontext['get_payment_currency'] = cls.get_payment_currency
|
||||
return super(Letter, cls).parse(report, records, data, localcontext)
|
||||
report_context['letters'] = letters
|
||||
report_context['today'] = Date.today()
|
||||
report_context['get_payment_amount'] = cls.get_payment_amount
|
||||
report_context['get_payment_currency'] = cls.get_payment_currency
|
||||
return report_context
|
||||
|
||||
@staticmethod
|
||||
def get_party_letter():
|
||||
|
||||
BIN
Binary file not shown.
@@ -0,0 +1,181 @@
|
||||
========================
|
||||
Account Dunning Scenario
|
||||
========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from dateutil.relativedelta import relativedelta
|
||||
>>> from decimal import Decimal
|
||||
>>> from proteus import config, Model, Wizard
|
||||
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||
... get_company
|
||||
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
|
||||
... create_chart, get_accounts
|
||||
>>> today = datetime.date.today()
|
||||
|
||||
Create database::
|
||||
|
||||
>>> config = config.set_trytond()
|
||||
>>> config.pool.test = True
|
||||
|
||||
Install account_dunning_letter::
|
||||
|
||||
>>> Module = Model.get('ir.module.module')
|
||||
>>> module, = Module.find([
|
||||
... ('name', '=', 'account_dunning_letter'),
|
||||
... ])
|
||||
>>> module.click('install')
|
||||
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Reload the context::
|
||||
|
||||
>>> User = Model.get('res.user')
|
||||
>>> Group = Model.get('res.group')
|
||||
>>> config._context = User.get_preferences(True, config.context)
|
||||
|
||||
Create account admin user::
|
||||
|
||||
>>> account_admin_user = User()
|
||||
>>> account_admin_user.name = 'Account Admin'
|
||||
>>> account_admin_user.login = 'account_admin'
|
||||
>>> account_admin_group, = Group.find([
|
||||
... ('name', '=', 'Account Administration'),
|
||||
... ])
|
||||
>>> account_admin_user.groups.append(account_admin_group)
|
||||
>>> account_admin_user.save()
|
||||
|
||||
Create account user::
|
||||
|
||||
>>> account_user = User()
|
||||
>>> account_user.name = 'Account'
|
||||
>>> account_user.login = 'account'
|
||||
>>> account_group, = Group.find([
|
||||
... ('name', '=', 'Account'),
|
||||
... ])
|
||||
>>> account_user.groups.append(account_group)
|
||||
>>> account_user.save()
|
||||
|
||||
Create dunning user::
|
||||
|
||||
>>> dunning_user = User()
|
||||
>>> dunning_user.name = 'Dunning'
|
||||
>>> dunning_user.login = 'dunning'
|
||||
>>> dunning_group, = Group.find([('name', '=', 'Dunning')])
|
||||
>>> dunning_user.groups.append(dunning_group)
|
||||
>>> dunning_user.save()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(company)
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period = fiscalyear.periods[0]
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = get_accounts(company)
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> cash = accounts['cash']
|
||||
|
||||
Create dunning procedure::
|
||||
|
||||
>>> config.user = account_admin_user.id
|
||||
>>> Procedure = Model.get('account.dunning.procedure')
|
||||
>>> procedure = Procedure(name='Procedure')
|
||||
>>> level = procedure.levels.new()
|
||||
>>> level.sequence = 1
|
||||
>>> level.days = 5
|
||||
>>> level = procedure.levels.new()
|
||||
>>> level.sequence = 2
|
||||
>>> level.days = 20
|
||||
>>> level = procedure.levels.new()
|
||||
>>> level.sequence = 3
|
||||
>>> level.days = 40
|
||||
>>> procedure.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.dunning_procedure = procedure
|
||||
>>> customer.save()
|
||||
|
||||
Create some moves::
|
||||
|
||||
>>> config.user = account_user.id
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Move = Model.get('account.move')
|
||||
>>> journal_revenue, = Journal.find([
|
||||
... ('code', '=', 'REV'),
|
||||
... ])
|
||||
>>> journal_cash, = Journal.find([
|
||||
... ('code', '=', 'CASH'),
|
||||
... ])
|
||||
>>> move = Move()
|
||||
>>> move.period = period
|
||||
>>> move.journal = journal_revenue
|
||||
>>> move.date = period.start_date
|
||||
>>> line = move.lines.new()
|
||||
>>> line.account = revenue
|
||||
>>> line.credit = Decimal(100)
|
||||
>>> line = move.lines.new()
|
||||
>>> line.account = receivable
|
||||
>>> line.debit = Decimal(100)
|
||||
>>> line.party = customer
|
||||
>>> line.maturity_date = period.start_date
|
||||
>>> move.save()
|
||||
>>> reconcile1, = [l for l in move.lines if l.account == receivable]
|
||||
>>> move = Move()
|
||||
>>> move.period = period
|
||||
>>> move.journal = journal_cash
|
||||
>>> move.date = period.start_date
|
||||
>>> line = move.lines.new()
|
||||
>>> line.account = cash
|
||||
>>> line.debit = Decimal(100)
|
||||
>>> line = move.lines.new()
|
||||
>>> line.account = receivable
|
||||
>>> line.credit = Decimal(100)
|
||||
>>> line.party = customer
|
||||
>>> move.save()
|
||||
>>> reconcile2, = [l for l in move.lines if l.account == receivable]
|
||||
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
|
||||
... [reconcile1, reconcile2])
|
||||
>>> move = Move()
|
||||
>>> move.period = period
|
||||
>>> move.journal = journal_revenue
|
||||
>>> move.date = period.start_date
|
||||
>>> line = move.lines.new()
|
||||
>>> line.account = revenue
|
||||
>>> line.credit = Decimal(100)
|
||||
>>> line = move.lines.new()
|
||||
>>> line.account = receivable
|
||||
>>> line.debit = Decimal(100)
|
||||
>>> line.party = customer
|
||||
>>> line.maturity_date = period.start_date
|
||||
>>> move.save()
|
||||
>>> dunning_line, = [l for l in move.lines if l.account == receivable]
|
||||
|
||||
Create dunnings::
|
||||
|
||||
>>> Dunning = Model.get('account.dunning')
|
||||
>>> create_dunning = Wizard('account.dunning.create')
|
||||
>>> create_dunning.form.date = period.start_date + relativedelta(days=5)
|
||||
>>> create_dunning.execute('create_')
|
||||
>>> dunning, = Dunning.find([])
|
||||
|
||||
Process dunning::
|
||||
|
||||
>>> process_dunning = Wizard('account.dunning.process',
|
||||
... [dunning])
|
||||
>>> process_dunning.execute('process')
|
||||
>>> dunning.reload()
|
||||
>>> dunning.state
|
||||
u'done'
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import unittest
|
||||
import doctest
|
||||
import trytond.tests.test_tryton
|
||||
from trytond.tests.test_tryton import test_view, test_depends, test_menu_action
|
||||
from trytond.tests.test_tryton import (test_view, test_depends,
|
||||
test_menu_action, doctest_setup, doctest_teardown)
|
||||
|
||||
|
||||
class AccountDunningLetterTestCase(unittest.TestCase):
|
||||
@@ -28,4 +30,7 @@ def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
AccountDunningLetterTestCase))
|
||||
suite.addTests(doctest.DocFileSuite('scenario_account_dunning_letter.rst',
|
||||
setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8',
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
return suite
|
||||
|
||||
Reference in New Issue
Block a user