[FIX] move all unported addons into __unported__ folder instead of adding _unported suffix

This commit is contained in:
Nicolas Bessi
2014-07-02 14:47:06 +02:00
committed by Iryna Vushnevska
parent ee6766a4e4
commit 8c1631e635
12 changed files with 0 additions and 1047 deletions

View File

@@ -1,24 +0,0 @@
# -*- coding: utf-8 -*-
###############################################################################
# #
# Author: Leonardo Pistone
# Copyright 2014 Camptocamp SA
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
"""Account Move Batch Validate."""
from . import account # noqa
from . import wizard # noqa

View File

@@ -1,81 +0,0 @@
# -*- coding: utf-8 -*-
###############################################################################
# #
# Author: Leonardo Pistone
# Copyright 2014 Camptocamp SA
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
{
'name': "Account Move Batch Validate",
'version': '0.2',
'author': 'Camptocamp',
'maintainer': 'Camptocamp',
'category': 'Finance',
'complexity': 'normal',
'depends': [
'account',
'account_default_draft_move',
'connector',
],
'description': """
Account Move Batch Validate
This module provides a wizard to post many Journal Entries in batch. it
uses the queue system introduced by the OpenERP Connector to handle a
big quantity of moves in batch.
The module account_default_draft_move introdoces a workflow where the
Journal Entries are always entered in OpenERP in draft state, and the
posting happens later, for example at the end of the period. The core
account module provides a wizard to post all the moves in the period,
but that is problematic when there are many moves.
The posting of a move takes some time, and doing that synchronously,
in one transaction is problematic.
In this module, we leverage the power of the queue system of the
OpenERP Connector, that can be very well used without other concepts
like Backends and Bindings.
This approach provides many advantages, similar to the ones we get
using that connector for e-commerce:
- Asynchronous: the operation is done in background, and users can
continue to work.
- Dedicated workers: the queued jobs are performed by specific workers
(processes). This is good for a long task, since the main workers are
busy handling HTTP requests and can be killed if operations take
too long, for example.
- Multiple transactions: this is an operation that doesn't need to be
atomic, and if a line out of 100,000 fails, it is possible to catch
it, see the error message, and fix the situation. Meanwhile, all
other jobs can proceed.
""",
'website': 'http://www.camptocamp.com',
'data': [
'account_view.xml',
'wizard/move_marker_view.xml',
],
'test': [
'test/batch_validate.yml',
'test/batch_validate_then_unmark.yml',
'test/batch_validate_then_delete_move.yml',
],
'installable': False,
'images': [],
'license': 'AGPL-3',
}

View File

@@ -1,157 +0,0 @@
# -*- coding: utf-8 -*-
###############################################################################
# #
# Author: Leonardo Pistone
# Copyright 2014 Camptocamp SA
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
"""Accounting customisation for delayed posting."""
import logging
from openerp.osv import fields, orm
from openerp.tools.translate import _
from openerp.addons.connector.queue.job import job
from openerp.addons.connector.session import ConnectorSession
from openerp.addons.connector.queue.job import OpenERPJobStorage
_logger = logging.getLogger(__name__)
# do a massive write on account moves BLOCK_SIZE at a time
BLOCK_SIZE = 1000
class account_move(orm.Model):
"""We modify the account move to allow delayed posting."""
_name = 'account.move'
_inherit = 'account.move'
_columns = {
'to_post': fields.boolean(
'Posting Requested',
readonly=True,
help='Check this box to mark the move for batch posting'
),
'post_job_uuid': fields.char(
'UUID of the Job to approve this move'
),
}
def _delay_post_marked(self, cr, uid, eta=None, context=None):
"""Create a job for every move marked for posting.
If some moves already have a job, they are skipped.
"""
if context is None:
context = {}
session = ConnectorSession(cr, uid, context=context)
move_ids = self.search(cr, uid, [
('to_post', '=', True),
('post_job_uuid', '=', False),
('state', '=', 'draft'),
], context=context)
name = self._name
# maybe not creating too many dictionaries will make us a bit faster
values = {'post_job_uuid': None}
_logger.info(
u'{0} jobs for posting moves have been created.'.format(
len(move_ids)
)
)
for move_id in move_ids:
job_uuid = validate_one_move.delay(session, name, move_id,
eta=eta)
values['post_job_uuid'] = job_uuid
self.write(cr, uid, [move_id], values)
def _cancel_jobs(self, cr, uid, context=None):
"""Find moves where the mark has been removed and cancel the jobs.
For the moves that are posted already it's too late: we skip them.
"""
if context is None:
context = {}
session = ConnectorSession(cr, uid, context=context)
storage = OpenERPJobStorage(session)
move_ids = self.search(cr, uid, [
('to_post', '=', False),
('post_job_uuid', '!=', False),
('state', '=', 'draft'),
], context=context)
for move in self.browse(cr, uid, move_ids, context=context):
job = storage.load(move.post_job_uuid)
if job.state in (u'pending', u'enqueued'):
job.set_done(result=_(
u'Task set to Done because the user unmarked the move'
))
storage.store(job)
def mark_for_posting(self, cr, uid, move_ids, eta=None, context=None):
"""Mark a list of moves for delayed posting, and enqueue the jobs."""
if context is None:
context = {}
# For massive amounts of moves, this becomes necessary to avoid
# MemoryError's
_logger.info(
u'{0} moves marked for posting.'.format(len(move_ids))
)
for start in xrange(0, len(move_ids), BLOCK_SIZE):
self.write(
cr,
uid,
move_ids[start:start + BLOCK_SIZE],
{'to_post': True},
context=context)
# users like to see the flag sooner rather than later
cr.commit()
self._delay_post_marked(cr, uid, eta=eta, context=context)
def unmark_for_posting(self, cr, uid, move_ids, context=None):
"""Unmark moves for delayed posting, and cancel the jobs."""
if context is None:
context = {}
self.write(cr, uid, move_ids, {'to_post': False}, context=context)
self._cancel_jobs(cr, uid, context=context)
@job
def validate_one_move(session, model_name, move_id):
"""Validate a move, and leave the job reference in place."""
move_pool = session.pool['account.move']
if move_pool.exists(session.cr, session.uid, [move_id]):
move_pool.button_validate(
session.cr,
session.uid,
[move_id]
)
else:
return _(u'Nothing to do because the record has been deleted')

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_move_to_post_tree" model="ir.ui.view">
<field name="name">view.move.to_post.tree</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_tree"/>
<field name="arch" type="xml">
<field name="to_check" position="after">
<field name="to_post"/>
</field>
</field>
</record>
<record id="view_move_to_post_form" model="ir.ui.view">
<field name="name">view.move.to_post.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<field name="to_check" position="after">
<field name="to_post"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@@ -1,191 +0,0 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_move_batch_validate
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-01-17 14:17+0000\n"
"PO-Revision-Date: 2014-01-17 14:17+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_move_batch_validate
#: field:account.move,post_job_uuid:0
msgid "UUID of the Job to approve this move"
msgstr ""
#. module: account_move_batch_validate
#: help:account.move,to_post:0
msgid "Check this box to mark the move for batch posting"
msgstr ""
#. module: account_move_batch_validate
#: code:addons/account_move_batch_validate/account.py:95
#, python-format
msgid "Task set to Done because the user unmarked the move"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Mark"
msgstr ""
#. module: account_move_batch_validate
#: selection:account.move.marker,action:0
msgid "Unmark for posting"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move,to_post:0
msgid "To Post"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,company_id:0
msgid "Company"
msgstr "Société"
#. module: account_move_batch_validate
#: model:ir.actions.act_window,name:account_move_batch_validate.action_account_move_marker
#: model:ir.ui.menu,name:account_move_batch_validate.menu_account_move_marker
msgid "Mark Journal Items for Batch Posting"
msgstr ""
#. module: account_move_batch_validate
#: selection:account.move.marker,filter:0
msgid "Date"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,chart_account_id:0
msgid "Chart of Account"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
#: field:account.move.marker,journal_ids:0
msgid "Journals"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,target_move:0
msgid "Target Moves"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Report Options"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
#: selection:account.move.marker,filter:0
msgid "Periods"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,date_to:0
msgid "End Date"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Dates"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,period_from:0
msgid "Start Period"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,eta:0
msgid "Seconds to wait before starting the jobs"
msgstr ""
#. module: account_move_batch_validate
#: selection:account.move.marker,target_move:0
msgid "All Posted Entries"
msgstr ""
#. module: account_move_batch_validate
#: help:account.move.marker,fiscalyear_id:0
msgid "Keep empty for all open fiscal year"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,period_to:0
msgid "End Period"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,fiscalyear_id:0
msgid "Fiscal Year"
msgstr ""
#. module: account_move_batch_validate
#: selection:account.move.marker,filter:0
msgid "No Filters"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,action:0
msgid "Action"
msgstr ""
#. module: account_move_batch_validate
#: model:ir.model,name:account_move_batch_validate.model_account_move
msgid "Account Entry"
msgstr ""
#. module: account_move_batch_validate
#: selection:account.move.marker,action:0
msgid "Mark for posting"
msgstr ""
#. module: account_move_batch_validate
#: model:ir.model,name:account_move_batch_validate.model_account_move_marker
msgid "Mark Journal Items for batch posting"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Filters"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Cancel"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,date_from:0
msgid "Start Date"
msgstr ""
#. module: account_move_batch_validate
#: help:account.move.marker,chart_account_id:0
msgid "Select Charts of Accounts"
msgstr ""
#. module: account_move_batch_validate
#: field:account.move.marker,filter:0
msgid "Filter by"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "or"
msgstr ""
#. module: account_move_batch_validate
#: selection:account.move.marker,target_move:0
msgid "All Entries"
msgstr ""

View File

@@ -1,192 +0,0 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_move_batch_validate
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-01-17 14:17+0000\n"
"PO-Revision-Date: 2014-02-24 05:21+0000\n"
"Last-Translator: Leonardo Pistone - camptocamp "
"<leonardo.pistone@camptocamp.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2014-06-12 06:31+0000\n"
"X-Generator: Launchpad (build 17041)\n"
#. module: account_move_batch_validate
#: field:account.move,post_job_uuid:0
msgid "UUID of the Job to approve this move"
msgstr "UUID du Job pour approuver cette move"
#. module: account_move_batch_validate
#: help:account.move,to_post:0
msgid "Check this box to mark the move for batch posting"
msgstr "Check this box to mark the move for batch posting"
#. module: account_move_batch_validate
#: code:addons/account_move_batch_validate/account.py:95
#, python-format
msgid "Task set to Done because the user unmarked the move"
msgstr ""
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Mark"
msgstr "Mark"
#. module: account_move_batch_validate
#: selection:account.move.marker,action:0
msgid "Unmark for posting"
msgstr "Unmark for posting"
#. module: account_move_batch_validate
#: field:account.move,to_post:0
msgid "To Post"
msgstr "Validation demandée"
#. module: account_move_batch_validate
#: field:account.move.marker,company_id:0
msgid "Company"
msgstr "Société"
#. module: account_move_batch_validate
#: model:ir.actions.act_window,name:account_move_batch_validate.action_account_move_marker
#: model:ir.ui.menu,name:account_move_batch_validate.menu_account_move_marker
msgid "Mark Journal Items for Batch Posting"
msgstr ""
#. module: account_move_batch_validate
#: selection:account.move.marker,filter:0
msgid "Date"
msgstr "Date"
#. module: account_move_batch_validate
#: field:account.move.marker,chart_account_id:0
msgid "Chart of Account"
msgstr "Plan Comptable"
#. module: account_move_batch_validate
#: view:account.move.marker:0
#: field:account.move.marker,journal_ids:0
msgid "Journals"
msgstr "Journaux"
#. module: account_move_batch_validate
#: field:account.move.marker,target_move:0
msgid "Target Moves"
msgstr "Target Moves"
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Report Options"
msgstr "Report Options"
#. module: account_move_batch_validate
#: view:account.move.marker:0
#: selection:account.move.marker,filter:0
msgid "Periods"
msgstr "Periods"
#. module: account_move_batch_validate
#: field:account.move.marker,date_to:0
msgid "End Date"
msgstr "End Date"
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Dates"
msgstr "Dates"
#. module: account_move_batch_validate
#: field:account.move.marker,period_from:0
msgid "Start Period"
msgstr "Période de debut"
#. module: account_move_batch_validate
#: field:account.move.marker,eta:0
msgid "Seconds to wait before starting the jobs"
msgstr "Seconds to wait before starting the jobs"
#. module: account_move_batch_validate
#: selection:account.move.marker,target_move:0
msgid "All Posted Entries"
msgstr "Toutes les écritures passées"
#. module: account_move_batch_validate
#: help:account.move.marker,fiscalyear_id:0
msgid "Keep empty for all open fiscal year"
msgstr "Keep empty for all open fiscal year"
#. module: account_move_batch_validate
#: field:account.move.marker,period_to:0
msgid "End Period"
msgstr "Période de fin"
#. module: account_move_batch_validate
#: field:account.move.marker,fiscalyear_id:0
msgid "Fiscal Year"
msgstr "Exercice"
#. module: account_move_batch_validate
#: selection:account.move.marker,filter:0
msgid "No Filters"
msgstr "Aucun filtre"
#. module: account_move_batch_validate
#: field:account.move.marker,action:0
msgid "Action"
msgstr "Action"
#. module: account_move_batch_validate
#: model:ir.model,name:account_move_batch_validate.model_account_move
msgid "Account Entry"
msgstr "Pièce comptable"
#. module: account_move_batch_validate
#: selection:account.move.marker,action:0
msgid "Mark for posting"
msgstr "Sélectionner pour validation"
#. module: account_move_batch_validate
#: model:ir.model,name:account_move_batch_validate.model_account_move_marker
msgid "Mark Journal Items for batch posting"
msgstr "Sélectionner Ecritures comptables à Valider en batch"
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Filters"
msgstr "Filtres"
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "Cancel"
msgstr "Annuler"
#. module: account_move_batch_validate
#: field:account.move.marker,date_from:0
msgid "Start Date"
msgstr "Date de début"
#. module: account_move_batch_validate
#: help:account.move.marker,chart_account_id:0
msgid "Select Charts of Accounts"
msgstr "Sélectionner Plan Comptable"
#. module: account_move_batch_validate
#: field:account.move.marker,filter:0
msgid "Filter by"
msgstr "Filtrer par"
#. module: account_move_batch_validate
#: view:account.move.marker:0
msgid "or"
msgstr "ou"
#. module: account_move_batch_validate
#: selection:account.move.marker,target_move:0
msgid "All Entries"
msgstr "Toutes les écritures"

View File

@@ -1,49 +0,0 @@
-
I create a move
-
!record {model: account.move, id: move1}:
journal_id: account.sales_journal
line_id:
- name: Receivable line
account_id: account.a_recv
debit: 1000.0
- name: Sales line
account_id: account.a_sale
credit: 1000.0
-
I check that the move is still draft
-
!assert {model: account.move, id: move1}:
- state == 'draft'
-
I create a wizard
-
!record {model: account.move.marker, id: wiz_marker1}:
action: mark
-
I run the wizard
-
!python {model: account.move.marker}: |
context['automated_test_execute_now'] = True
self.button_mark(
cr, uid, [ref('wiz_marker1')], context=context
)
-
I read the UUID from the move, I dequeue the job and run it
-
!python {model: account.move}: |
from openerp.addons.connector.queue.job import OpenERPJobStorage
from openerp.addons.connector.session import ConnectorSession
move = self.browse(cr, uid, ref('move1'), context=context)
uuid = move.post_job_uuid
session = ConnectorSession(cr, uid, context=context)
storage = OpenERPJobStorage(session)
myjob = storage.load(uuid)
myjob.perform(session)
-
I check that the move is now approved
-
!assert {model: account.move, id: move1}:
- state == 'posted'

View File

@@ -1,52 +0,0 @@
-
I create a move
-
!record {model: account.move, id: move3}:
journal_id: account.sales_journal
line_id:
- name: Receivable line
account_id: account.a_recv
debit: 3000.0
- name: Sales line
account_id: account.a_sale
credit: 3000.0
-
I check that the move is still draft
-
!assert {model: account.move, id: move3}:
- state == 'draft'
-
I create a wizard with a long ETA
-
!record {model: account.move.marker, id: wiz_marker4}:
action: mark
eta: 10000
-
I run the wizard
-
!python {model: account.move.marker}: |
context['automated_test_execute_now'] = True
self.button_mark(
cr, uid, [ref('wiz_marker4')], context=context
)
-
I read the UUID from the move, delete the move, then dequeue the job and run it.
It should raise no exceptions.
-
!python {model: account.move}: |
from openerp.addons.connector.queue.job import OpenERPJobStorage
from openerp.addons.connector.session import ConnectorSession
move = self.browse(cr, uid, ref('move3'), context=context)
uuid = move.post_job_uuid
assert uuid, 'The Job has not been created.'
self.unlink(cr, uid, ref('move3'), context=context)
session = ConnectorSession(cr, uid, context=context)
storage = OpenERPJobStorage(session)
myjob = storage.load(uuid)
myjob.perform(session)
assert myjob.result == u'Nothing to do because the record has been deleted'

View File

@@ -1,63 +0,0 @@
-
I create a move
-
!record {model: account.move, id: move2}:
journal_id: account.sales_journal
line_id:
- name: Receivable line
account_id: account.a_recv
debit: 2000.0
- name: Sales line
account_id: account.a_sale
credit: 2000.0
-
I check that the move is still draft
-
!assert {model: account.move, id: move2}:
- state == 'draft'
-
I create a wizard with a long ETA
-
!record {model: account.move.marker, id: wiz_marker2}:
action: mark
eta: 10000
-
I run the wizard
-
!python {model: account.move.marker}: |
context['automated_test_execute_now'] = True
self.button_mark(
cr, uid, [ref('wiz_marker2')], context=context
)
-
Now I change my mind and I create a wizard to unmark the moves
-
!record {model: account.move.marker, id: wiz_unmarker3}:
action: unmark
-
I run the wizard
-
!python {model: account.move.marker}: |
self.button_mark(
cr, uid, [ref('wiz_unmarker3')], context=context
)
-
Now I checked that my job is done, and the move is still draft
-
!python {model: account.move}: |
from openerp.addons.connector.queue.job import OpenERPJobStorage
from openerp.addons.connector.session import ConnectorSession
session = ConnectorSession(cr, uid, context=context)
storage = OpenERPJobStorage(session)
move = self.browse(cr, uid, ref('move2'), context=context)
myjob = storage.load(move.post_job_uuid)
assert myjob.state == 'done', 'Job is in state {0}, should be done'.format(
myjob.state
)
-
I check that the move is still draft
-
!assert {model: account.move, id: move2}:
- state == 'draft'

View File

@@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
###############################################################################
# #
# Author: Leonardo Pistone
# Copyright 2014 Camptocamp SA
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
"""Wizard to mark account moves for batch posting."""
from . import move_marker # noqa

View File

@@ -1,128 +0,0 @@
# -*- coding: utf-8 -*-
###############################################################################
# #
# Author: Leonardo Pistone
# Copyright 2014 Camptocamp SA
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
"""Wizards for batch posting."""
from openerp.osv import fields, orm
from openerp.addons.connector.session import ConnectorSession
from openerp.addons.connector.queue.job import job
class AccountMoveMarker(orm.TransientModel):
"""Wizard to mark account moves for batch posting."""
_name = "account.move.marker"
_inherit = "account.common.report"
_description = "Mark Journal Items for batch posting"
_columns = {
'action': fields.selection([
('mark', 'Mark for posting'),
('unmark', 'Unmark for posting'),
], "Action", required=True),
'eta': fields.integer('Seconds to wait before starting the jobs')
}
_defaults = {
'action': 'mark',
}
def button_mark(self, cr, uid, ids, context=None):
"""Create a single job that will create one job per move.
Return action.
"""
session = ConnectorSession(cr, uid, context=context)
for wizard_id in ids:
# to find out what _classic_write does, read the documentation.
wizard_data = self.read(cr, uid, wizard_id, context=context,
load='_classic_write')
wizard_data.pop('id')
if context.get('automated_test_execute_now'):
process_wizard(session, self._name, wizard_data)
else:
process_wizard.delay(session, self._name, wizard_data)
return {'type': 'ir.actions.act_window_close'}
def process_wizard(self, cr, uid, ids, context=None):
"""Choose the correct list of moves to mark and then validate."""
for wiz in self.browse(cr, uid, ids, context=context):
move_obj = self.pool['account.move']
domain = [('state', '=', 'draft')]
if wiz.filter == 'filter_period':
period_pool = self.pool['account.period']
period_ids = period_pool.search(cr, uid, [
('date_start', '>=', wiz.period_from.date_start),
('date_stop', '<=', wiz.period_to.date_stop),
], context=context)
domain.append((
'period_id',
'in',
period_ids
))
elif wiz.filter == 'filter_date':
domain += [
('date', '>=', wiz.date_from),
('date', '<=', wiz.date_to),
]
if wiz.journal_ids:
domain.append((
'journal_id',
'in',
[journal.id for journal in wiz.journal_ids]
))
move_ids = move_obj.search(cr, uid, domain, context=context)
if wiz.action == 'mark':
move_obj.mark_for_posting(cr, uid, move_ids, eta=wiz.eta,
context=context)
elif wiz.action == 'unmark':
move_obj.unmark_for_posting(cr, uid, move_ids, context=context)
@job
def process_wizard(session, model_name, wizard_data):
"""Create jobs to validate Journal Entries."""
wiz_obj = session.pool[model_name]
new_wiz_id = wiz_obj.create(
session.cr,
session.uid,
wizard_data,
session.context
)
wiz_obj.process_wizard(
session.cr,
session.uid,
ids=[new_wiz_id],
context=session.context,
)

View File

@@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_account_move_marker" model="ir.ui.view">
<field name="name">Mark Jornal Items for Batch Posting</field>
<field name="model">account.move.marker</field>
<field name="arch" type="xml">
<form string="Report Options" version="7.0">
<label string=""/> <!-- binding for inherited views -->
<group col="4">
<field name="chart_account_id" widget='selection' on_change="onchange_chart_id(chart_account_id, context)"/>
<field name="company_id" invisible="1"/>
<field name="fiscalyear_id" domain="[('company_id','=',company_id)]"/>
<field name="action"/>
</group>
<notebook tabpos="up" colspan="4">
<page string="Filters" name="filters">
<group>
<field name="filter" on_change="onchange_filter(filter, fiscalyear_id)"/>
</group>
<group string="Dates" attrs="{'invisible':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}">
<field name="date_from" />
<field name="date_to" />
</group>
<group string="Periods" attrs="{'invisible':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}">
<field name="period_from" domain="[('fiscalyear_id', '=', fiscalyear_id)]"/>
<field name="period_to" domain="[('fiscalyear_id', '=', fiscalyear_id)]"/>
</group>
</page>
<page string="Journals" name="journal_ids">
<field name="journal_ids"/>
</page>
</notebook>
<footer>
<button name="button_mark" string="Mark" type="object" default_focus="1" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_account_move_marker" model="ir.actions.act_window">
<field name="name">Mark Jornal Items for Batch Posting</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.move.marker</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- replace existing menuitem -->
<record id="account.menu_validate_account_moves" model="ir.ui.menu">
<field name="name">Mark Journal Items for Batch Posting</field>
<field name="action" ref="action_account_move_marker" />
</record>
</data>
</openerp>