diff --git a/CHANGELOG b/CHANGELOG
index 7c6a758ad2..bb267a2592 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add writeoff method
+* Remove default account from journal
* Add replacement account
* Add period on account and tax code
* Add template override mechanism to tax rules and tax rule lines
diff --git a/__init__.py b/__init__.py
index fc7049008b..f145c731eb 100644
--- a/__init__.py
+++ b/__init__.py
@@ -44,13 +44,13 @@ def register():
Period,
Journal,
JournalSequence,
- JournalAccount,
JournalCashContext,
JournalPeriod,
Move,
Reconciliation,
ConfigurationTaxRounding,
Line,
+ WriteOff,
OpenJournalAsk,
ReconcileLinesWriteOff,
ReconcileShow,
diff --git a/doc/index.rst b/doc/index.rst
index bc327926e0..1322cac1cb 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -102,12 +102,24 @@ A Journal contains the following fields:
- Name
- Code
- Active: A checkbox that allow to disable the tax.
-- Default Credit Account, Default Debit Account: Used as default
- accounts on move lines for journals of *Cash* type.
- Type: By default take one of the following values: *General*,
*Revenue*, *Expense*, *Cash*, *Situation*.
+Reconcile Write Off
+*******************
+
+A reconcile write off is used to set the writeoff options when reconciling
+unbalanced moves. It has the following fields:
+
+- Name
+- Company
+- Journal: Will be used for creating the write off move
+- Credit Account and Debit Account: The accounts used for the write off move
+ depending on the amount sign.
+- Active: A checkbox that allow to disable the writeoff.
+
+
Move
****
diff --git a/journal.py b/journal.py
index 1498f94e54..dc31f5deb6 100644
--- a/journal.py
+++ b/journal.py
@@ -16,7 +16,7 @@ from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
-__all__ = ['Journal', 'JournalSequence', 'JournalAccount',
+__all__ = ['Journal', 'JournalSequence',
'JournalCashContext',
'JournalPeriod']
@@ -52,32 +52,6 @@ class Journal(
}))
sequences = fields.One2Many(
'account.journal.sequence', 'journal', "Sequences")
- credit_account = fields.MultiValue(fields.Many2One(
- 'account.account', "Default Credit Account",
- domain=[
- ('kind', '!=', 'view'),
- ('company', '=', Eval('context', {}).get('company', -1)),
- ],
- states={
- 'required': ((Eval('type').in_(['cash', 'write-off']))
- & (Eval('context', {}).get('company', -1) != -1)),
- 'invisible': ~Eval('context', {}).get('company', -1),
- },
- depends=['type']))
- debit_account = fields.MultiValue(fields.Many2One(
- 'account.account', "Default Debit Account",
- domain=[
- ('kind', '!=', 'view'),
- ('company', '=', Eval('context', {}).get('company', -1)),
- ],
- states={
- 'required': ((Eval('type').in_(['cash', 'write-off']))
- & (Eval('context', {}).get('company', -1) != -1)),
- 'invisible': ~Eval('context', {}).get('company', -1),
- },
- depends=['type']))
- accounts = fields.One2Many(
- 'account.journal.account', 'journal', "Accounts")
debit = fields.Function(fields.Numeric('Debit',
digits=(16, Eval('currency_digits', 2)),
depends=['currency_digits']), 'get_debit_credit_balance')
diff --git a/move.py b/move.py
index accaf87c90..bb29ba9e60 100644
--- a/move.py
+++ b/move.py
@@ -10,7 +10,7 @@ from sql import Null, Literal
from sql.aggregate import Sum, Max
from sql.conditionals import Coalesce, Case
-from trytond.model import ModelView, ModelSQL, fields, Check
+from trytond.model import ModelView, ModelSQL, fields, Check, DeactivableMixin
from trytond.wizard import Wizard, StateTransition, StateView, StateAction, \
StateReport, Button
from trytond.report import Report
@@ -22,7 +22,7 @@ from trytond.rpc import RPC
from trytond.tools import reduce_ids, grouped_slice
from trytond.config import config
-__all__ = ['Move', 'Reconciliation', 'Line', 'OpenJournalAsk',
+__all__ = ['Move', 'Reconciliation', 'Line', 'WriteOff', 'OpenJournalAsk',
'OpenJournal', 'OpenAccount',
'ReconcileLinesWriteOff', 'ReconcileLines',
'UnreconcileLines',
@@ -1158,10 +1158,11 @@ class Line(ModelSQL, ModelView):
return toolbar
@classmethod
- def reconcile(cls, *lines_list, **writeoff):
+ def reconcile(
+ cls, *lines_list, date=None, writeoff=None, description=None):
"""
Reconcile each list of lines together.
- The writeoff keys are: journal, date, account and description.
+ The writeoff keys are: date, method and description.
"""
pool = Pool()
Reconciliation = pool.get('account.move.reconciliation')
@@ -1185,7 +1186,8 @@ class Line(ModelSQL, ModelView):
reconcile_party = line.party
if amount:
move = cls._get_writeoff_move(
- reconcile_account, reconcile_party, amount, **writeoff)
+ reconcile_account, reconcile_party, amount,
+ date, writeoff, description)
move.save()
lines += cls.search([
('move', '=', move.id),
@@ -1203,7 +1205,7 @@ class Line(ModelSQL, ModelView):
@classmethod
def _get_writeoff_move(cls, reconcile_account, reconcile_party, amount,
- journal=None, date=None, account=None, description=None):
+ date=None, writeoff=None, description=None):
pool = Pool()
Date = pool.get('ir.date')
Period = pool.get('account.period')
@@ -1211,11 +1213,14 @@ class Line(ModelSQL, ModelView):
if not date:
date = Date.today()
period_id = Period.find(reconcile_account.company.id, date=date)
- if not account and journal:
+ account = None
+ journal = None
+ if writeoff:
if amount >= 0:
- account = journal.debit_account
+ account = writeoff.debit_account
else:
- account = journal.credit_account
+ account = writeoff.credit_account
+ journal = writeoff.journal
move = Move()
move.journal = journal
@@ -1243,6 +1248,33 @@ class Line(ModelSQL, ModelView):
return move
+class WriteOff(DeactivableMixin, ModelSQL, ModelView):
+ 'Reconcile Write Off'
+ __name__ = 'account.move.reconcile.write_off'
+ company = fields.Many2One('company.company', "Company", required=True)
+ name = fields.Char("Name", required=True, translate=True)
+ journal = fields.Many2One('account.journal', "Journal", required=True,
+ domain=[('type', '=', 'write-off')])
+ credit_account = fields.Many2One('account.account', "Credit Account",
+ required=True,
+ domain=[
+ ('kind', '!=', 'view'),
+ ('company', '=', Eval('company')),
+ ],
+ depends=['company'])
+ debit_account = fields.Many2One('account.account', "Debit Account",
+ required=True,
+ domain=[
+ ('kind', '!=', 'view'),
+ ('company', '=', Eval('company')),
+ ],
+ depends=['company'])
+
+ @classmethod
+ def default_company(cls):
+ return Transaction().context.get('company')
+
+
class OpenJournalAsk(ModelView):
'Open Journal Ask'
__name__ = 'account.move.open_journal.ask'
@@ -1368,14 +1400,17 @@ class OpenAccount(Wizard):
class ReconcileLinesWriteOff(ModelView):
'Reconcile Lines Write-Off'
__name__ = 'account.move.reconcile_lines.writeoff'
- journal = fields.Many2One('account.journal', 'Journal', required=True,
+ company = fields.Many2One('company.company', "Company", readonly=True)
+ writeoff = fields.Many2One('account.move.reconcile.write_off', "Write Off",
domain=[
- ('type', '=', 'write-off'),
- ])
+ ('company', '=', Eval('company')),
+ ],
+ depends=['company'])
date = fields.Date('Date', required=True)
amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
readonly=True, depends=['currency_digits'])
- currency_digits = fields.Integer('Currency Digits', readonly=True)
+ currency_digits = fields.Function(fields.Integer('Currency Digits'),
+ 'on_change_with_currency_digits')
description = fields.Char('Description')
@staticmethod
@@ -1383,6 +1418,11 @@ class ReconcileLinesWriteOff(ModelView):
Date = Pool().get('ir.date')
return Date.today()
+ @fields.depends('company')
+ def on_change_with_currency_digits(self, name=None):
+ if self.company:
+ return self.company.currency.digits
+
class ReconcileLines(Wizard):
'Reconcile Lines'
@@ -1419,17 +1459,17 @@ class ReconcileLines(Wizard):
amount, company = self.get_writeoff()
return {
'amount': amount,
- 'currency_digits': company.currency.digits,
+ 'company': company.id,
}
def transition_reconcile(self):
Line = Pool().get('account.move.line')
- journal = getattr(self.writeoff, 'journal', None)
+ writeoff = getattr(self.writeoff, 'writeoff', None)
date = getattr(self.writeoff, 'date', None)
description = getattr(self.writeoff, 'description', None)
Line.reconcile(Line.browse(Transaction().context['active_ids']),
- journal=journal, date=date, description=description)
+ writeoff=writeoff, date=date, description=description)
return 'end'
diff --git a/move.xml b/move.xml
index 40d22482c0..bf42bda1ce 100644
--- a/move.xml
+++ b/move.xml
@@ -348,6 +348,50 @@ this repository contains the full copyright notices and license terms. -->
move_cancel_default_form
+
+ account.move.reconcile.write_off
+ form
+ writeoff_form
+
+
+ account.move.reconcile.write_off
+ tree
+ writeoff_tree
+
+
+ WriteOff Methods
+ account.move.reconcile.write_off
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
account.move.print_general_journal.start
form
diff --git a/tests/scenario_account_reconciliation.rst b/tests/scenario_account_reconciliation.rst
index 5b592c714d..71d3c265b0 100644
--- a/tests/scenario_account_reconciliation.rst
+++ b/tests/scenario_account_reconciliation.rst
@@ -124,19 +124,28 @@ Create Moves for writeoff reconciliation::
>>> move.save()
>>> reconcile2, = [l for l in move.lines if l.account == receivable]
-Reconcile Lines with writeoff::
+Create a writeof payment 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,
- ... credit_account=revenue, debit_account=expense)
+ ... 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()
+
+Reconcile Lines with writeoff::
>>> reconcile_lines = Wizard('account.move.reconcile_lines',
... [reconcile1, reconcile2])
>>> reconcile_lines.form_state == 'writeoff'
True
- >>> reconcile_lines.form.journal = journal_writeoff
+ >>> reconcile_lines.form.writeoff = writeoff_method
>>> reconcile_lines.execute('reconcile')
>>> reconcile1.reload()
>>> reconcile2.reload()
diff --git a/view/journal_form.xml b/view/journal_form.xml
index 9c014d6b17..dacd91ba10 100644
--- a/view/journal_form.xml
+++ b/view/journal_form.xml
@@ -14,10 +14,6 @@ this repository contains the full copyright notices and license terms. -->
-
-
-
-
diff --git a/view/reconcile_lines_writeoff_form.xml b/view/reconcile_lines_writeoff_form.xml
index a7842f68b8..c3f375b71a 100644
--- a/view/reconcile_lines_writeoff_form.xml
+++ b/view/reconcile_lines_writeoff_form.xml
@@ -6,8 +6,8 @@ this repository contains the full copyright notices and license terms. -->
-
-
+
+
diff --git a/view/writeoff_form.xml b/view/writeoff_form.xml
new file mode 100644
index 0000000000..1a0b5ef923
--- /dev/null
+++ b/view/writeoff_form.xml
@@ -0,0 +1,17 @@
+
+
+
diff --git a/view/writeoff_tree.xml b/view/writeoff_tree.xml
new file mode 100644
index 0000000000..9b9e542ed2
--- /dev/null
+++ b/view/writeoff_tree.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+