1
# -*- coding: utf-8 -*-
2
# -*- encoding: utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2004-2009 Pexego Sistemas Informáticos. All Rights Reserved
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
24
Revalidate Account Moves Wizard
26
__author__ = "Borja López Soilán (Pexego)"
29
from osv import fields,osv
30
from tools.translate import _
32
class pxgo_revalidate_moves_wizard(osv.osv_memory):
34
Revalidate Account Moves Wizard
36
Revalidates all the (already confirmed) moves, so their analytic lines
37
are recomputed (to fix the data after problems like this:
38
https://bugs.launchpad.net/openobject-addons/+bug/582988).
40
_name = "pxgo_revalidate_moves_wizard"
41
_description = "Revalidate Account Moves Wizard"
44
'company_id': fields.many2one('res.company', 'Company', required=True, readonly=True),
45
'period_ids': fields.many2many('account.period', 'pxgo_revalidate_moves_wizard_period_rel', 'wizard_id', 'period_id', "Periods"),
46
'move_ids': fields.many2many('account.move', 'pxgo_revalidate_moves_wizard_moves_rel', 'wizard_id', 'move_id', 'Moves'),
47
'state': fields.selection([('new','New'), ('ready', 'Ready'), ('done','Done')], 'Status', readonly=True),
51
'state': lambda *a: 'new',
54
def action_skip_new(self, cr, uid, ids, context=None):
56
Skips to the ready state.
58
for wiz in self.browse(cr, uid, ids, context):
59
self.write(cr, uid, [wiz.id], { 'state': 'ready' })
62
def action_find_moves_missing_analytic_lines(self, cr, uid, ids, context=None):
64
Finds account moves with missing analytic lines and adds them
65
to the move_ids many2many field.
67
for wiz in self.browse(cr, uid, ids, context):
68
period_ids = [period.id for period in wiz.period_ids]
70
SELECT account_move_line.move_id FROM account_move_line
71
LEFT JOIN account_analytic_line
72
ON account_analytic_line.move_id = account_move_line.id
73
WHERE account_move_line.analytic_account_id IS NOT NULL AND account_analytic_line.id IS NULL
75
periods_str = ','.join(map(str, period_ids))
77
query += """ AND period_id IN (%s)""" % periods_str
80
move_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
81
self.write(cr, uid, [wiz.id], {
82
'move_ids': [(6, 0, move_ids)],
87
def action_revalidate_moves(self, cr, uid, ids, context=None):
89
Calls the validate method of the account moves for each move in the
92
for wiz in self.browse(cr, uid, ids, context):
93
for move in wiz.move_ids:
94
# We validate the moves one by one to prevent problems
95
self.pool.get('account.move').validate(cr, uid, [move.id], context)
96
self.write(cr, uid, [wiz.id], { 'state': 'done' })
99
pxgo_revalidate_moves_wizard()