[CHG][account_move_batch_validate] Overload standard wizard

This commit is contained in:
Adrien Peiffer (ACSONE)
2015-06-30 10:10:10 +02:00
committed by Iryna Vushnevska
parent 3da052c643
commit 6d0a030ee0
5 changed files with 103 additions and 113 deletions

View File

@@ -18,14 +18,26 @@
-
I create a wizard
-
!record {model: account.move.marker, id: wiz_marker1}:
!record {model: validate.account.move, id: wiz_marker1}:
action: mark
-
I set the period and the journal on the wizard
-
!python {model: validate.account.move}: |
move = self.pool['account.move'].browse(cr, uid, ref('move1'),
context=context)
journal_ids = [(6, 0, [move.journal_id.id])]
period_ids = [(6, 0, [move.period_id.id])]
vals = {'journal_ids': journal_ids,
'period_ids': period_ids,
}
self.write(cr, uid, ref('wiz_marker1'), vals, context=context)
-
I run the wizard
-
!python {model: account.move.marker}: |
!python {model: validate.account.move}: |
context['automated_test_execute_now'] = True
self.button_mark(
self.validate_move(
cr, uid, [ref('wiz_marker1')], context=context
)
-

View File

@@ -18,15 +18,27 @@
-
I create a wizard with a long ETA
-
!record {model: account.move.marker, id: wiz_marker4}:
!record {model: validate.account.move, id: wiz_marker4}:
action: mark
eta: 10000
-
I set the period and the journal on the wizard
-
!python {model: validate.account.move}: |
move = self.pool['account.move'].browse(cr, uid, ref('move3'),
context=context)
journal_ids = [(6, 0, [move.journal_id.id])]
period_ids = [(6, 0, [move.period_id.id])]
vals = {'journal_ids': journal_ids,
'period_ids': period_ids,
}
self.write(cr, uid, ref('wiz_marker4'), vals, context=context)
-
I run the wizard
-
!python {model: account.move.marker}: |
!python {model: validate.account.move}: |
context['automated_test_execute_now'] = True
self.button_mark(
self.validate_move(
cr, uid, [ref('wiz_marker4')], context=context
)
-

View File

@@ -18,27 +18,51 @@
-
I create a wizard with a long ETA
-
!record {model: account.move.marker, id: wiz_marker2}:
!record {model: validate.account.move, id: wiz_marker2}:
action: mark
eta: 10000
-
I set the period and the journal on the wizard
-
!python {model: validate.account.move}: |
move = self.pool['account.move'].browse(cr, uid, ref('move2'),
context=context)
journal_ids = [(6, 0, [move.journal_id.id])]
period_ids = [(6, 0, [move.period_id.id])]
vals = {'journal_ids': journal_ids,
'period_ids': period_ids,
}
self.write(cr, uid, ref('wiz_marker2'), vals, context=context)
-
I run the wizard
-
!python {model: account.move.marker}: |
!python {model: validate.account.move}: |
context['automated_test_execute_now'] = True
self.button_mark(
self.validate_move(
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}:
!record {model: validate.account.move, id: wiz_unmarker3}:
action: unmark
-
I set the period and the journal on the wizard
-
!python {model: validate.account.move}: |
move = self.pool['account.move'].browse(cr, uid, ref('move2'),
context=context)
journal_ids = [(6, 0, [move.journal_id.id])]
period_ids = [(6, 0, [move.period_id.id])]
vals = {'journal_ids': journal_ids,
'period_ids': period_ids,
}
self.write(cr, uid, ref('wiz_unmarker3'), vals, context=context)
-
I run the wizard
-
!python {model: account.move.marker}: |
self.button_mark(
!python {model: validate.account.move}: |
self.validate_move(
cr, uid, [ref('wiz_unmarker3')], context=context
)
-

View File

@@ -25,52 +25,53 @@ from openerp.addons.connector.session import ConnectorSession
from openerp.addons.connector.queue.job import job
class AccountMoveMarker(orm.TransientModel):
class ValidateAccountMove(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"
_inherit = "validate.account.move"
_columns = {
'action': fields.selection([
('mark', 'Mark for posting'),
('unmark', 'Unmark for posting'),
], "Action", required=True),
'action': fields.selection([('mark', 'Mark for posting'),
('unmark', 'Unmark for posting')],
"Action", required=True),
'eta': fields.integer('Seconds to wait before starting the jobs'),
'journal_ids': fields.many2many('account.journal',
'account_post_journal_rel',
'wiz_id', 'journal_id', 'Journals',
required=True),
'asynchronous': fields.boolean('Use asynchronous validation'),
}
_defaults = {
'action': 'mark',
'journal_ids': [],
'asynchronous': True,
}
def button_mark(self, cr, uid, ids, context=None):
def validate_move(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 wizard_data.get('journal_ids'):
journals_ids_vals = [(6, False,
wizard_data.get('journal_ids'))]
wizard_data['journal_ids'] = journals_ids_vals
wizard_id = ids[0]
# to find out what _classic_write does, read the documentation.
wizard_data = self.read(cr, uid, wizard_id, context=context,
load='_classic_write')
if not wizard_data.get('asynchronous'):
return super(ValidateAccountMove, self)\
.validate_move(cr, uid, ids, context=context)
wizard_data.pop('id')
if wizard_data.get('journal_ids'):
journals_ids_vals = [(6, False,
wizard_data.get('journal_ids'))]
wizard_data['journal_ids'] = journals_ids_vals
if wizard_data.get('period_ids'):
periods_ids_vals = [(6, False,
wizard_data.get('period_ids'))]
wizard_data['period_ids'] = periods_ids_vals
if context.get('automated_test_execute_now'):
process_wizard(session, self._name, wizard_data)
else:
process_wizard.delay(session, self._name, wizard_data)
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'}
@@ -80,34 +81,11 @@ class AccountMoveMarker(orm.TransientModel):
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)
domain = [('state', '=', 'draft'),
('journal_id', 'in', wiz.journal_ids.ids),
('period_id', 'in', wiz.period_ids.ids)]
move_ids = move_obj.search(cr, uid, domain, order='date',
context=context)
if wiz.action == 'mark':
move_obj.mark_for_posting(cr, uid, move_ids, eta=wiz.eta,

View File

@@ -2,58 +2,22 @@
<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>
<record id="validate_account_move_view" model="ir.ui.view">
<field name="name">Post Journal Entries</field>
<field name="model">validate.account.move</field>
<field name="inherit_id" ref="account.validate_account_move_view" />
<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"/>
<xpath expr="//group" position="before">
<group>
<field name="asynchronous" />
<field name="action" attrs="{'invisible': [('asynchronous', '=', False)]}"/>
</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>
</xpath>
</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" />
<field name="name">Post Journal Entries</field>
</record>
</data>