From 4599a5990f53438dfd46857ced310683d22def03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Nov 2014 23:35:54 +0100 Subject: [PATCH] Allow to set a description to cancel move issue4304 review6631002 --- CHANGELOG | 2 ++ __init__.py | 1 + move.py | 30 +++++++++++++++++++++++++----- move.xml | 6 ++++++ tests/scenario_move_cancel.rst | 4 ++++ view/move_cancel_default_form.xml | 7 +++++++ 6 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 view/move_cancel_default_form.xml diff --git a/CHANGELOG b/CHANGELOG index 65a8a6a707..f35fe32a5a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Allow to set a description to cancel move + Version 3.4.0 - 2014-10-20 * Bug fixes (see mercurial logs for details) * Add option on Account for party required diff --git a/__init__.py b/__init__.py index c38770f2aa..dae32351aa 100644 --- a/__init__.py +++ b/__init__.py @@ -47,6 +47,7 @@ def register(): OpenJournalAsk, ReconcileLinesWriteOff, ReconcileShow, + CancelMovesDefault, FiscalYearLine, FiscalYear2, PrintGeneralJournalStart, diff --git a/move.py b/move.py index f1658b10dc..27724b36cb 100644 --- a/move.py +++ b/move.py @@ -30,7 +30,7 @@ __all__ = ['Move', 'Reconciliation', 'Line', 'OpenJournalAsk', 'ReconcileLinesWriteOff', 'ReconcileLines', 'UnreconcileLines', 'Reconcile', 'ReconcileShow', - 'CancelMoves', + 'CancelMoves', 'CancelMovesDefault', 'FiscalYearLine', 'FiscalYear2', 'PrintGeneralJournalStart', 'PrintGeneralJournal', 'GeneralJournal'] __metaclass__ = PoolMeta @@ -366,9 +366,11 @@ class Move(ModelSQL, ModelView): }) return default - def cancel(self): + def cancel(self, default=None): 'Return a cancel move' - default = self._cancel_default() + if default is None: + default = {} + default.update(self._cancel_default()) cancel_move, = self.copy([self], default=default) for line in cancel_move.lines: line.debit *= -1 @@ -1892,9 +1894,20 @@ class ReconcileShow(ModelView): class CancelMoves(Wizard): 'Cancel Moves' __name__ = 'account.move.cancel' - start_state = 'cancel' + start_state = 'default' + default = StateView('account.move.cancel.default', + 'account.move_cancel_default_view_form', [ + Button('Cancel', 'end', 'tryton-cancel'), + Button('Ok', 'cancel', 'tryton-ok', default=True), + ]) cancel = StateTransition() + def default_cancel(self, move): + default = {} + if self.default.description: + default['description'] = self.default.description + return default + def transition_cancel(self): pool = Pool() Move = pool.get('account.move') @@ -1902,7 +1915,8 @@ class CancelMoves(Wizard): moves = Move.browse(Transaction().context['active_ids']) for move in moves: - cancel_move = move.cancel() + default = self.default_cancel(move) + cancel_move = move.cancel(default=default) to_reconcile = defaultdict(list) for line in move.lines + cancel_move.lines: if line.account.reconcile: @@ -1912,6 +1926,12 @@ class CancelMoves(Wizard): return 'end' +class CancelMovesDefault(ModelView): + 'Cancel Moves' + __name__ = 'account.move.cancel.default' + description = fields.Char('Description') + + class FiscalYearLine(ModelSQL): 'Fiscal Year - Move Line' __name__ = 'account.fiscalyear-account.move.line' diff --git a/move.xml b/move.xml index 0c1ba90f09..dd4dd2992e 100644 --- a/move.xml +++ b/move.xml @@ -310,6 +310,12 @@ this repository contains the full copyright notices and license terms. --> + + account.move.cancel.default + form + move_cancel_default_form + + account.move.print_general_journal.start form diff --git a/tests/scenario_move_cancel.rst b/tests/scenario_move_cancel.rst index 9878abbf39..e1429d79fa 100644 --- a/tests/scenario_move_cancel.rst +++ b/tests/scenario_move_cancel.rst @@ -84,6 +84,8 @@ Create Move to cancel:: Cancel Move:: >>> cancel_move = Wizard('account.move.cancel', [move]) + >>> cancel_move.form.description = 'Cancel' + >>> cancel_move.execute('cancel') >>> cancel_move.state 'end' >>> move.reload() @@ -94,6 +96,8 @@ Cancel Move:: ... if l.move != move] >>> cancel_move.origin == move True + >>> cancel_move.description + u'Cancel' >>> revenue.reload() >>> revenue.credit Decimal('0.00') diff --git a/view/move_cancel_default_form.xml b/view/move_cancel_default_form.xml new file mode 100644 index 0000000000..04a892ff86 --- /dev/null +++ b/view/move_cancel_default_form.xml @@ -0,0 +1,7 @@ + + +
+