Update reconcile wizard to use write off method

issue7450
review60331002
This commit is contained in:
Cédric Krier
2018-09-11 00:18:55 +02:00
parent cc9f1e7c68
commit b6fa9fb328
4 changed files with 140 additions and 20 deletions
+19 -16
View File
@@ -1610,7 +1610,7 @@ class Reconcile(Wizard):
defaults['party'] = self.show.party.id if self.show.party else None
defaults['currency_digits'] = self.show.account.company.currency.digits
defaults['lines'] = self._default_lines()
defaults['write_off'] = Decimal(0)
defaults['write_off_amount'] = Decimal(0)
defaults['date'] = Date.today()
return defaults
@@ -1666,8 +1666,8 @@ class Reconcile(Wizard):
if self.show.lines:
Line.reconcile(self.show.lines,
journal=self.show.journal,
date=self.show.date,
writeoff=self.show.write_off,
description=self.show.description)
return 'next_'
@@ -1690,31 +1690,34 @@ class ReconcileShow(ModelView):
depends=['account', 'party'])
_write_off_states = {
'required': Bool(Eval('write_off', 0)),
'invisible': ~Eval('write_off', 0),
'required': Bool(Eval('write_off_amount', 0)),
'invisible': ~Eval('write_off_amount', 0),
}
_write_off_depends = ['write_off']
_write_off_depends = ['write_off_amount']
write_off = fields.Function(fields.Numeric('Write-Off',
write_off_amount = fields.Function(fields.Numeric('Amount',
digits=(16, Eval('currency_digits', 2)),
states=_write_off_states,
depends=_write_off_depends + ['currency_digits']),
'on_change_with_write_off')
'on_change_with_write_off_amount')
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
journal = fields.Many2One('account.journal', 'Journal',
states=_write_off_states, depends=_write_off_depends,
domain=[
('type', '=', 'write-off'),
])
write_off = fields.Many2One(
'account.move.reconcile.write_off', "Write Off",
states=_write_off_states, depends=_write_off_depends)
date = fields.Date('Date',
states=_write_off_states, depends=_write_off_depends)
description = fields.Char('Description',
states=_write_off_states, depends=_write_off_depends)
states={
'invisible': _write_off_states['invisible'],
}, depends=_write_off_depends)
@fields.depends('lines')
def on_change_with_write_off(self, name=None):
return sum((l.debit - l.credit) for l in self.lines)
@fields.depends('lines', 'currency_digits')
def on_change_with_write_off_amount(self, name=None):
digits = self.currency_digits or 0
exp = Decimal(str(10.0 ** -digits))
amount = sum(((l.debit - l.credit) for l in self.lines), Decimal(0))
return amount.quantize(exp)
@fields.depends('account')
def on_change_with_currency_digits(self, name=None):
+112
View File
@@ -0,0 +1,112 @@
==========================
Account Reconcile Scenario
==========================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company, \
... get_company
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
... create_chart, get_accounts
Install account::
>>> config = activate_modules('account')
Create company::
>>> _ = create_company()
>>> company = get_company()
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']
>>> expense = accounts['expense']
>>> cash = accounts['cash']
Create parties::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.save()
Create Moves to reconcile::
>>> 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(42)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.debit = Decimal(42)
>>> line.party = customer
>>> move.save()
>>> move = Move()
>>> move.period = period
>>> move.journal = journal_cash
>>> move.date = period.start_date
>>> line = move.lines.new()
>>> line.account = cash
>>> line.debit = Decimal(40)
>>> line = move.lines.new()
>>> line.account = receivable
>>> line.credit = Decimal(40)
>>> line.party = customer
>>> move.save()
Create a write off method::
>>> Sequence = Model.get('ir.sequence')
>>> sequence_journal, = Sequence.find([('code', '=', 'account.journal')])
>>> journal_writeoff = Journal(name='Write-Off', type='write-off',
... sequence=sequence_journal)
>>> journal_writeoff.save()
>>> WriteOff = Model.get('account.move.reconcile.write_off')
>>> writeoff_method = WriteOff()
>>> writeoff_method.name = 'Write Off'
>>> writeoff_method.journal = journal_writeoff
>>> writeoff_method.debit_account = expense
>>> writeoff_method.credit_account = expense
>>> writeoff_method.save()
Run Reconcile wizard::
>>> reconcile = Wizard('account.reconcile')
>>> reconcile.form.party == customer
True
>>> reconcile.form.write_off_amount
Decimal('0.00')
>>> len(reconcile.form.lines)
0
>>> reconcile.form.lines.extend(reconcile.form.lines.find())
>>> len(reconcile.form.lines)
2
>>> reconcile.form.write_off_amount
Decimal('2.00')
>>> reconcile.form.write_off = writeoff_method
>>> reconcile.execute('reconcile')
+5
View File
@@ -1072,6 +1072,11 @@ def suite():
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
suite.addTests(doctest.DocFileSuite(
'scenario_account_reconcile.rst',
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
suite.addTests(doctest.DocFileSuite(
'scenario_move_cancel.rst',
tearDown=doctest_teardown, encoding='utf-8',
+4 -4
View File
@@ -8,12 +8,12 @@ this repository contains the full copyright notices and license terms. -->
<field name="party"/>
<field name="lines" colspan="4"/>
<separator name="write_off" colspan="4"/>
<label name="write_off" string="Amount"/>
<field name="write_off"/>
<label name="write_off_amount"/>
<field name="write_off_amount"/>
<label name="date"/>
<field name="date"/>
<label name="journal"/>
<field name="journal"/>
<label name="write_off"/>
<field name="write_off"/>
<newline/>
<label name="description"/>
<field name="description" colspan="3"/>