diff --git a/setup.py b/setup.py
index 0a2dd2e2e8..fcf261e14f 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ minor_version = int(minor_version)
requires = []
for dep in info.get('depends', []):
- if not re.match(r'(ir|res|workflow|webdav)(\W|$)', dep):
+ if not re.match(r'(ir|res|webdav)(\W|$)', dep):
requires.append('trytond_%s >= %s.%s, < %s.%s' %
(dep, major_version, minor_version, major_version,
minor_version + 1))
diff --git a/statement.py b/statement.py
index 86030dfd7f..0f6a599dec 100644
--- a/statement.py
+++ b/statement.py
@@ -1,7 +1,7 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from decimal import Decimal
-from trytond.model import ModelWorkflow, ModelView, ModelSQL, fields
+from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.pyson import Eval, If
from trytond.transaction import Transaction
from trytond.backend import TableHandler
@@ -11,7 +11,7 @@ _STATES = {'readonly': Eval('state') != 'draft'}
_DEPENDS = ['state']
-class Statement(ModelWorkflow, ModelSQL, ModelView):
+class Statement(Workflow, ModelSQL, ModelView):
'Account Statement'
_name = 'account.statement'
_description = __doc__
@@ -63,13 +63,30 @@ class Statement(ModelWorkflow, ModelSQL, ModelView):
def __init__(self):
super(Statement, self).__init__()
- self._rpc.update({
- 'draft_workflow': True,
- })
self._order[0] = ('id', 'DESC')
self._error_messages.update({
'wrong_end_balance': 'End Balance must be %s!',
})
+ self._transitions |= set((
+ ('draft', 'validated'),
+ ('validated', 'posted'),
+ ('validated', 'cancel'),
+ ('cancel', 'draft'),
+ ))
+ self._buttons.update({
+ 'draft': {
+ 'invisible': Eval('state') != 'cancel',
+ },
+ 'validate': {
+ 'invisible': Eval('state') != 'draft',
+ },
+ 'post': {
+ 'invisible': Eval('state') != 'validated',
+ },
+ 'cancel': {
+ 'invisible': Eval('state') != 'validated',
+ },
+ })
def init(self, module_name):
cursor = Transaction().cursor
@@ -256,51 +273,51 @@ class Statement(ModelWorkflow, ModelSQL, ModelView):
amount_to_pay - abs(line['amount'])
return res
- def wkf_validated(self, statement):
+ @ModelView.button
+ @Workflow.transition('draft')
+ def draft(self, ids):
+ pass
+
+ @ModelView.button
+ @Workflow.transition('validated')
+ def validate(self, ids):
statement_line_obj = Pool().get('account.statement.line')
lang_obj = Pool().get('ir.lang')
- computed_end_balance = statement.start_balance
- for line in statement.lines:
- computed_end_balance += line.amount
- if computed_end_balance != statement.end_balance:
- lang_id, = lang_obj.search([
- ('code', '=', Transaction().language),
- ])
- lang = lang_obj.browse(lang_id)
+ for statement in self.browse(ids):
+ computed_end_balance = statement.start_balance
+ for line in statement.lines:
+ computed_end_balance += line.amount
+ if computed_end_balance != statement.end_balance:
+ lang_id, = lang_obj.search([
+ ('code', '=', Transaction().language),
+ ])
+ lang = lang_obj.browse(lang_id)
- amount = lang_obj.format(lang,
- '%.' + str(statement.journal.currency.digits) + 'f',
- computed_end_balance, True)
- self.raise_user_error('wrong_end_balance', error_args=(amount,))
- for line in statement.lines:
- statement_line_obj.create_move(line)
- self.write(statement.id, {
- 'state':'validated',
- })
+ amount = lang_obj.format(lang,
+ '%.' + str(statement.journal.currency.digits) + 'f',
+ computed_end_balance, True)
+ self.raise_user_error('wrong_end_balance', error_args=(amount,))
+ for line in statement.lines:
+ statement_line_obj.create_move(line)
- def wkf_posted(self, statement):
+ @ModelView.button
+ @Workflow.transition('posted')
+ def post(self, ids):
statement_line_obj = Pool().get('account.statement.line')
- statement_line_obj.post_move(statement.lines)
- self.write(statement.id, {
- 'state':'posted',
- })
+ statements = self.browse(ids)
+ lines = [l for s in statements for l in s.lines]
+ statement_line_obj.post_move(lines)
- def wkf_cancel(self, statement):
+ @ModelView.button
+ @Workflow.transition('cancel')
+ def cancel(self, ids):
statement_line_obj = Pool().get('account.statement.line')
- statement_line_obj.delete_move(statement.lines)
- self.write(statement.id, {
- 'state':'cancel',
- })
-
- def draft_workflow(self, ids):
- self.workflow_trigger_create(ids)
- self.write(ids, {
- 'state': 'draft',
- })
- return True
+ statements = self.browse(ids)
+ lines = [l for s in statements for l in s.lines]
+ statement_line_obj.delete_move(lines)
Statement()
@@ -426,10 +443,7 @@ class Line(ModelSQL, ModelView):
def create_move(self, line):
'''
- Create move for the statement line
-
- :param line: a BrowseRecord of the line
- :return: the move id
+ Create move for the statement line and return move id if created.
'''
pool = Pool()
move_obj = pool.get('account.move')
@@ -439,6 +453,9 @@ class Line(ModelSQL, ModelView):
move_line_obj = pool.get('account.move.line')
lang_obj = pool.get('ir.lang')
+ if line.move:
+ return
+
period_id = period_obj.find(line.statement.company.id,
date=line.date)
diff --git a/statement.xml b/statement.xml
index 9824b21699..a9dd7399bc 100644
--- a/statement.xml
+++ b/statement.xml
@@ -43,15 +43,14 @@ this repository contains the full copyright notices and license terms. -->
-
+
-
-
+ type="object"/>
+
+
@@ -226,53 +225,6 @@ this repository contains the full copyright notices and license terms. -->
-
-
- Statement
- account.statement
-
-
-
-
-
- Draft
-
-
-
- wkf_validated
- Validated
-
-
-
- wkf_posted
- Posted
-
-
-
-
- wkf_cancel
- Canceled
-
-
-
-
-
-
- validated
-
-
-
-
-
- posted
-
-
-
-
-
- cancel
-
-
@@ -323,5 +275,49 @@ this repository contains the full copyright notices and license terms. -->
+
+ draft
+
+
+
+
+
+
+
+
+ validate
+
+
+
+
+
+
+
+
+ post
+
+
+
+
+
+
+
+
+ cancel
+
+
+
+
+
+
+
diff --git a/tests/scenario_account_statement.rst b/tests/scenario_account_statement.rst
index 3b8d4bafc7..c9afb5a2e4 100644
--- a/tests/scenario_account_statement.rst
+++ b/tests/scenario_account_statement.rst
@@ -25,7 +25,7 @@ Install account_statement and account_invoice::
>>> modules = Module.find([
... ('name', 'in', ('account_statement', 'account_invoice')),
... ])
- >>> Module.button_install([x.id for x in modules], config.context)
+ >>> Module.install([x.id for x in modules], config.context)
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
Create company::
@@ -148,8 +148,7 @@ Create 2 customer invoices::
>>> invoice_line.account = revenue
>>> invoice_line.description = 'Test'
>>> customer_invoice1.save()
- >>> Invoice.workflow_trigger_validate(customer_invoice1.id, 'open',
- ... config.context)
+ >>> Invoice.open([customer_invoice1.id], config.context)
>>> customer_invoice1.state
u'open'
@@ -163,8 +162,7 @@ Create 2 customer invoices::
>>> invoice_line.account = revenue
>>> invoice_line.description = 'Test'
>>> customer_invoice2.save()
- >>> Invoice.workflow_trigger_validate(customer_invoice2.id, 'open',
- ... config.context)
+ >>> Invoice.open([customer_invoice2.id], config.context)
>>> customer_invoice2.state
u'open'
@@ -180,8 +178,7 @@ Create 1 supplier invoices::
>>> invoice_line.account = expense
>>> invoice_line.description = 'Test'
>>> supplier_invoice.save()
- >>> Invoice.workflow_trigger_validate(supplier_invoice.id, 'open',
- ... config.context)
+ >>> Invoice.open([supplier_invoice.id], config.context)
>>> supplier_invoice.state
u'open'
@@ -252,8 +249,7 @@ Paid 50 to supplier::
Validate statement::
- >>> Statement.workflow_trigger_validate(statement.id, 'validated',
- ... config.context)
+ >>> Statement.validate([statement.id], config.context)
>>> statement.state
u'validated'