Add cron task to post clearing move after journal delay
issue6895 review43691002
This commit is contained in:
1 parent
827acd9e54
commit
4402bd8dd8
7 files changed
+78
-3
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Add cron task to post clearing move after journal delay
|
||||
|
||||
Version 4.6.0 - 2017-10-30
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Allow to use account instead of line for clearing
|
||||
|
||||
@@ -7,3 +7,6 @@ account defined on the payment journal.
|
||||
|
||||
The clearing account will be used for statement lines which are linked to such
|
||||
payment.
|
||||
|
||||
If a delay is configured on journal for posting, a scheduled task will post
|
||||
automatically clearing moves after this delay.
|
||||
+25
@@ -25,6 +25,31 @@ class Journal:
|
||||
'required': Bool(Eval('clearing_account')),
|
||||
},
|
||||
depends=['clearing_account'])
|
||||
clearing_posting_delay = fields.TimeDelta(
|
||||
"Clearing Posting Delay",
|
||||
help="Post automatically the clearing moves after the delay.\n"
|
||||
"Leave empty for no posting.")
|
||||
|
||||
@classmethod
|
||||
def cron_post_clearing_moves(cls, date=None):
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
Move = pool.get('account.move')
|
||||
if date is None:
|
||||
date = Date.today()
|
||||
moves = []
|
||||
journals = cls.search([
|
||||
('clearing_posting_delay', '!=', None),
|
||||
])
|
||||
for journal in journals:
|
||||
move_date = date - journal.clearing_posting_delay
|
||||
moves.extend(Move.search([
|
||||
('date', '<=', move_date),
|
||||
('origin.journal.id', '=', journal.id,
|
||||
'account.payment'),
|
||||
('state', '=', 'draft'),
|
||||
]))
|
||||
Move.post(moves)
|
||||
|
||||
|
||||
class Payment:
|
||||
|
||||
+28
@@ -33,5 +33,33 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="type">form</field>
|
||||
<field name="name">succeed_start_form</field>
|
||||
</record>
|
||||
|
||||
<record model="res.user" id="user_post_clearing_moves">
|
||||
<field name="login">user_cron_post_clearing_moves</field>
|
||||
<field name="name">Cron Post Clearing Moves</field>
|
||||
<field name="signature"></field>
|
||||
<field name="active" eval="False"/>
|
||||
</record>
|
||||
<record model="res.user-res.group"
|
||||
id="user_post_clearing_moves_group_account">
|
||||
<field name="user" ref="user_post_clearing_moves"/>
|
||||
<field name="group" ref="account.group_account"/>
|
||||
</record>
|
||||
<record model="res.user-res.group"
|
||||
id="user_post_clearing_moves_group_payment">
|
||||
<field name="user" ref="user_post_clearing_moves"/>
|
||||
<field name="group" ref="account_payment.group_payment"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.cron" id="cron_post_clearing_moves">
|
||||
<field name="name">Post Clearing Moves</field>
|
||||
<field name="request_user" ref="res.user_admin"/>
|
||||
<field name="user" ref="user_post_clearing_moves"/>
|
||||
<field name="interval_number" eval="1"/>
|
||||
<field name="interval_type">days</field>
|
||||
<field name="repeat_missed" eval="False"/>
|
||||
<field name="model">account.payment.journal</field>
|
||||
<field name="function">cron_post_clearing_moves</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
+3
-1
@@ -158,4 +158,6 @@ class StatementLine:
|
||||
Move = pool.get('account.move')
|
||||
super(StatementLine, cls).post_move(lines)
|
||||
Move.post([l.payment.clearing_move for l in lines
|
||||
if l.payment and l.payment.clearing_move])
|
||||
if l.payment
|
||||
and l.payment.clearing_move
|
||||
and l.payment.clearing_move.state == 'draft'])
|
||||
@@ -16,6 +16,7 @@ Imports::
|
||||
>>> from trytond.modules.account_invoice.tests.tools import \
|
||||
... set_fiscalyear_invoice_sequences
|
||||
>>> today = datetime.date.today()
|
||||
>>> yesterday = today - relativedelta(days=1)
|
||||
>>> first = today + relativedelta(day=1)
|
||||
|
||||
Install account_payment_clearing and account_statement::
|
||||
@@ -60,7 +61,8 @@ Create payment journal::
|
||||
>>> PaymentJournal = Model.get('account.payment.journal')
|
||||
>>> payment_journal = PaymentJournal(name='Manual',
|
||||
... process_method='manual', clearing_journal=expense,
|
||||
... clearing_account=bank_clearing)
|
||||
... clearing_account=bank_clearing,
|
||||
... clearing_posting_delay=datetime.timedelta(1))
|
||||
>>> payment_journal.save()
|
||||
|
||||
Create parties::
|
||||
@@ -183,11 +185,22 @@ Fail payment::
|
||||
Succeed payment and post clearing::
|
||||
|
||||
>>> succeed = Wizard('account.payment.succeed', [payment])
|
||||
>>> succeed.form.date = yesterday
|
||||
>>> succeed.execute('succeed')
|
||||
>>> payment.state
|
||||
u'succeeded'
|
||||
|
||||
>>> Cron = Model.get('ir.cron')
|
||||
>>> Company = Model.get('company.company')
|
||||
>>> cron_post_clearing_moves, = Cron.find([
|
||||
... ('model', '=', 'account.payment.journal'),
|
||||
... ('function', '=', 'cron_post_clearing_moves'),
|
||||
... ])
|
||||
>>> cron_post_clearing_moves.companies.append(Company(company.id))
|
||||
>>> cron_post_clearing_moves.click('run_once')
|
||||
|
||||
>>> payment.reload()
|
||||
>>> clearing_move = payment.clearing_move
|
||||
>>> clearing_move.click('post')
|
||||
>>> clearing_move.state
|
||||
u'posted'
|
||||
|
||||
|
||||
@@ -8,5 +8,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="clearing_account"/>
|
||||
<label name="clearing_journal"/>
|
||||
<field name="clearing_journal"/>
|
||||
<label name="clearing_posting_delay"/>
|
||||
<field name="clearing_posting_delay"/>
|
||||
</xpath>
|
||||
</data>
|
||||
Reference in new issue
Block a user