[REF] account wizard: code clean

bzr revid: ara@tinyerp.com-20101015133522-dmxhk5szekf7ybap
This commit is contained in:
ARA (OpenERP) 2010-10-15 19:05:22 +05:30
parent 2974ecec46
commit 8b2622b607
15 changed files with 60 additions and 38 deletions

View File

@ -248,4 +248,4 @@ class account_automatic_reconcile(osv.osv_memory):
account_automatic_reconcile() account_automatic_reconcile()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -19,6 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from osv import osv, fields from osv import osv, fields
from tools.translate import _ from tools.translate import _
@ -77,4 +78,4 @@ class account_change_currency(osv.osv_memory):
account_change_currency() account_change_currency()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import time import time
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _
@ -40,8 +41,9 @@ class account_chart(osv.osv_memory):
def _get_fiscalyear(self, cr, uid, context=None): def _get_fiscalyear(self, cr, uid, context=None):
"""Return default Fiscalyear value""" """Return default Fiscalyear value"""
fy_obj = self.pool.get('account.fiscalyear')
now = time.strftime('%Y-%m-%d') now = time.strftime('%Y-%m-%d')
fiscalyears = self.pool.get('account.fiscalyear').search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 ) fiscalyears = fy_obj.search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 )
return fiscalyears and fiscalyears[0] or False return fiscalyears and fiscalyears[0] or False
def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None): def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
@ -81,19 +83,21 @@ class account_chart(osv.osv_memory):
""" """
mod_obj = self.pool.get('ir.model.data') mod_obj = self.pool.get('ir.model.data')
act_obj = self.pool.get('ir.actions.act_window') act_obj = self.pool.get('ir.actions.act_window')
period_obj = self.pool.get('account.period')
fy_obj = self.pool.get('account.fiscalyear')
if context is None: if context is None:
context = {} context = {}
data = self.read(cr, uid, ids, [], context=context)[0] data = self.read(cr, uid, ids, [], context=context)[0]
result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree') result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree')
id = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id'] id = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id']
result = act_obj.read(cr, uid, [id], context=context)[0] result = act_obj.read(cr, uid, [id], context=context)[0]
result['periods'] = [] result['periods'] = []
if data['period_from'] and data['period_to']: if data['period_from'] and data['period_to']:
result['periods'] = self.pool.get('account.period').build_ctx_periods(cr, uid, data['period_from'], data['period_to']) result['periods'] = period_obj.build_ctx_periods(cr, uid, data['period_from'], data['period_to'])
result['context'] = str({'fiscalyear': data['fiscalyear'], 'periods': result['periods'], \ result['context'] = str({'fiscalyear': data['fiscalyear'], 'periods': result['periods'], \
'state': data['target_move']}) 'state': data['target_move']})
if data['fiscalyear']: if data['fiscalyear']:
result['name'] += ':' + self.pool.get('account.fiscalyear').read(cr, uid, [data['fiscalyear']], context=context)[0]['code'] result['name'] += ':' + fy_obj.read(cr, uid, [data['fiscalyear']], context=context)[0]['code']
return result return result
_defaults = { _defaults = {
@ -103,4 +107,4 @@ class account_chart(osv.osv_memory):
account_chart() account_chart()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _
@ -220,4 +221,4 @@ class account_fiscalyear_close(osv.osv_memory):
account_fiscalyear_close() account_fiscalyear_close()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -61,4 +61,4 @@ class account_fiscalyear_close_state(osv.osv_memory):
account_fiscalyear_close_state() account_fiscalyear_close_state()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -84,7 +84,7 @@ class account_invoice_refund(osv.osv_memory):
wf_service = netsvc.LocalService('workflow') wf_service = netsvc.LocalService('workflow')
inv_tax_obj = self.pool.get('account.invoice.tax') inv_tax_obj = self.pool.get('account.invoice.tax')
inv_line_obj = self.pool.get('account.invoice.line') inv_line_obj = self.pool.get('account.invoice.line')
res_users_obj = self.pool.get('res.users')
if context is None: if context is None:
context = {} context = {}
@ -93,7 +93,7 @@ class account_invoice_refund(osv.osv_memory):
date = False date = False
period = False period = False
description = False description = False
company = self.pool.get('res.users').browse(cr, uid, uid).company_id company = res_users_obj.browse(cr, uid, uid).company_id
journal_id = form.get('journal_id', False) journal_id = form.get('journal_id', False)
for inv in inv_obj.browse(cr, uid, context.get('active_ids'), context=context): for inv in inv_obj.browse(cr, uid, context.get('active_ids'), context=context):
if inv.state in ['draft', 'proforma2', 'cancel']: if inv.state in ['draft', 'proforma2', 'cancel']:

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _
import netsvc import netsvc

View File

@ -45,8 +45,6 @@ class account_journal_select(osv.osv_memory):
result['context'] = str({'journal_id': journal_id, 'period_id': period_id}) result['context'] = str({'journal_id': journal_id, 'period_id': period_id})
return result return result
account_journal_select() account_journal_select()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,11 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import tools import tools
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _
class account_move_bank_reconcile(osv.osv_memory): class account_move_bank_reconcile(osv.osv_memory):
""" """
Bank Reconciliation Bank Reconciliation

View File

@ -31,7 +31,8 @@ class account_move_journal(osv.osv_memory):
""" """
Return default account period value Return default account period value
""" """
ids = self.pool.get('account.period').find(cr, uid, context=context) account_period_obj = self.pool.get('account.period')
ids = account_period_obj.find(cr, uid, context=context)
period_id = False period_id = False
if ids: if ids:
period_id = ids[0] period_id = ids[0]
@ -119,6 +120,7 @@ class account_move_journal(osv.osv_memory):
period_pool = self.pool.get('account.journal.period') period_pool = self.pool.get('account.journal.period')
data_pool = self.pool.get('ir.model.data') data_pool = self.pool.get('ir.model.data')
journal_pool = self.pool.get('account.journal') journal_pool = self.pool.get('account.journal')
account_period_obj = self.pool.get('account.period')
if context is None: if context is None:
context = {} context = {}
@ -132,7 +134,7 @@ class account_move_journal(osv.osv_memory):
if not ids: if not ids:
journal = journal_pool.browse(cr, uid, journal_id) journal = journal_pool.browse(cr, uid, journal_id)
period = self.pool.get('account.period').browse(cr, uid, period_id) period = account_period_obj.browse(cr, uid, period_id)
name = journal.name name = journal.name
state = period.state state = period.state
@ -169,4 +171,4 @@ class account_move_journal(osv.osv_memory):
account_move_journal() account_move_journal()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from osv import fields, osv from osv import fields, osv
from tools.translate import _ from tools.translate import _
@ -30,15 +31,19 @@ class account_open_closed_fiscalyear(osv.osv_memory):
} }
def remove_entries(self, cr, uid, ids, context={}): def remove_entries(self, cr, uid, ids, context={}):
fy_obj = self.pool.get('account.fiscalyear')
move_obj = self.pool.get('account.move')
data = self.read(cr, uid, ids, [])[0] data = self.read(cr, uid, ids, [])[0]
data_fyear = self.pool.get('account.fiscalyear').browse(cr, uid, data['fyear_id']) data_fyear = fy_obj.browse(cr, uid, data['fyear_id'])
if not data_fyear.end_journal_period_id: if not data_fyear.end_journal_period_id:
raise osv.except_osv(_('Error'), _('No journal for ending writing has been defined for the fiscal year')) raise osv.except_osv(_('Error'), _('No journal for ending writing has been defined for the fiscal year'))
period_journal = data_fyear.end_journal_period_id period_journal = data_fyear.end_journal_period_id
ids_move = self.pool.get('account.move').search(cr, uid, [('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)]) ids_move = move_obj.search(cr, uid, [('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])
if ids_move: if ids_move:
cr.execute('delete from account_move where id IN %s', (tuple(ids_move),)) cr.execute('delete from account_move where id IN %s', (tuple(ids_move),))
return {} return {}
account_open_closed_fiscalyear() account_open_closed_fiscalyear()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -39,6 +39,7 @@ class account_period_close(osv.osv_memory):
@param uid: the current users ID for security checks, @param uid: the current users ID for security checks,
@param ids: account period closes ID or list of IDs @param ids: account period closes ID or list of IDs
""" """
period_pool = self.pool.get('account.period')
mode = 'done' mode = 'done'
for form in self.read(cr, uid, ids, context=context): for form in self.read(cr, uid, ids, context=context):
@ -48,7 +49,6 @@ class account_period_close(osv.osv_memory):
cr.execute('update account_period set state=%s where id=%s', (mode, id)) cr.execute('update account_period set state=%s where id=%s', (mode, id))
# Log message for Period # Log message for Period
period_pool = self.pool.get('account.period')
for period_id, name in period_pool.name_get(cr, uid, [id]): for period_id, name in period_pool.name_get(cr, uid, [id]):
period_pool.log(cr, uid, period_id, "Period '%s' is closed, no more modification allowed for this period." % (name)) period_pool.log(cr, uid, period_id, "Period '%s' is closed, no more modification allowed for this period." % (name))
return {} return {}

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import time import time
from osv import fields, osv from osv import fields, osv
@ -72,6 +73,7 @@ class account_move_line_reconcile(osv.osv_memory):
def trans_rec_reconcile_full(self, cr, uid, ids, context=None): def trans_rec_reconcile_full(self, cr, uid, ids, context=None):
account_move_line_obj = self.pool.get('account.move.line') account_move_line_obj = self.pool.get('account.move.line')
period_obj = self.pool.get('account.period')
date = False date = False
period_id = False period_id = False
journal_id= False journal_id= False
@ -82,7 +84,7 @@ class account_move_line_reconcile(osv.osv_memory):
data = self.read(cr, uid, ids, context=context) data = self.read(cr, uid, ids, context=context)
date = time.strftime('%Y-%m-%d') date = time.strftime('%Y-%m-%d')
ids = self.pool.get('account.period').find(cr, uid, dt=date, context=context) ids = period_obj.find(cr, uid, dt=date, context=context)
if ids: if ids:
period_id = ids[0] period_id = ids[0]
#stop the reconciliation process by partner (manual reconciliation) only if there is nothing more to reconcile for this partner #stop the reconciliation process by partner (manual reconciliation) only if there is nothing more to reconcile for this partner
@ -148,6 +150,7 @@ class account_move_line_reconcile_writeoff(osv.osv_memory):
def trans_rec_reconcile(self, cr, uid, ids, context=None): def trans_rec_reconcile(self, cr, uid, ids, context=None):
account_move_line_obj = self.pool.get('account.move.line') account_move_line_obj = self.pool.get('account.move.line')
period_obj = self.pool.get('account.period')
if context is None: if context is None:
context = {} context = {}
data = self.read(cr, uid, ids,context=context)[0] data = self.read(cr, uid, ids,context=context)[0]
@ -160,7 +163,7 @@ class account_move_line_reconcile_writeoff(osv.osv_memory):
if context['date_p']: if context['date_p']:
date = context['date_p'] date = context['date_p']
ids = self.pool.get('account.period').find(cr, uid, dt=date, context=context) ids = period_obj.find(cr, uid, dt=date, context=context)
if ids: if ids:
period_id = ids[0] period_id = ids[0]
@ -171,4 +174,4 @@ class account_move_line_reconcile_writeoff(osv.osv_memory):
account_move_line_reconcile_writeoff() account_move_line_reconcile_writeoff()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import time import time
from osv import osv, fields from osv import osv, fields
@ -29,15 +30,15 @@ class account_partner_reconcile_process(osv.osv_memory):
def _get_to_reconcile(self, cr, uid, context=None): def _get_to_reconcile(self, cr, uid, context=None):
cr.execute(""" cr.execute("""
SELECT p_id FROM (SELECT l.partner_id as p_id, SUM(l.debit) AS debit, SUM(l.credit) AS credit SELECT p_id FROM (SELECT l.partner_id as p_id, SUM(l.debit) AS debit, SUM(l.credit) AS credit
FROM account_move_line AS l LEFT JOIN account_account a ON (l.account_id = a.id) FROM account_move_line AS l LEFT JOIN account_account a ON (l.account_id = a.id)
LEFT JOIN res_partner p ON (p.id = l.partner_id) LEFT JOIN res_partner p ON (p.id = l.partner_id)
WHERE a.reconcile = 't' WHERE a.reconcile = 't'
AND l.reconcile_id IS NULL AND l.reconcile_id IS NULL
AND (%s > to_char(p.last_reconciliation_date, 'YYYY-MM-DD') OR p.last_reconciliation_date IS NULL ) AND (%s > to_char(p.last_reconciliation_date, 'YYYY-MM-DD') OR p.last_reconciliation_date IS NULL )
AND l.state <> 'draft' AND l.state <> 'draft'
GROUP BY l.partner_id) AS tmp GROUP BY l.partner_id) AS tmp
WHERE debit > 0 WHERE debit > 0
AND credit > 0 AND credit > 0
""",(time.strftime('%Y-%m-%d'),) """,(time.strftime('%Y-%m-%d'),)
) )
@ -55,7 +56,9 @@ class account_partner_reconcile_process(osv.osv_memory):
return len(map(lambda x: x[0], cr.fetchall())) + 1 return len(map(lambda x: x[0], cr.fetchall())) + 1
def _get_partner(self, cr, uid, context=None): def _get_partner(self, cr, uid, context=None):
partner = self.pool.get('account.move.line').get_next_partner_only(cr, uid, offset=1, context=context) move_line_obj = self.pool.get('account.move.line')
partner = move_line_obj.get_next_partner_only(cr, uid, offset=1, context=context)
if not partner: if not partner:
return False return False
return partner[0] return partner[0]
@ -71,9 +74,12 @@ class account_partner_reconcile_process(osv.osv_memory):
return res return res
def next_partner(self, cr, uid, ids, context=None): def next_partner(self, cr, uid, ids, context=None):
partner_id = self.pool.get('account.move.line').read(cr, uid, context['active_id'], ['partner_id'])['partner_id'] move_line_obj = self.pool.get('account.move.line')
res_partner_obj = self.pool.get('res.partner')
partner_id = move_line_obj.read(cr, uid, context['active_id'], ['partner_id'])['partner_id']
if partner_id: if partner_id:
self.pool.get('res.partner').write(cr, uid, partner_id[0], {'last_reconciliation_date': time.strftime('%Y-%m-%d')}, context) res_partner_obj.write(cr, uid, partner_id[0], {'last_reconciliation_date': time.strftime('%Y-%m-%d')}, context)
#TODO: we have to find a way to update the context of the current tab (we could open a new tab with the context but it's not really handy) #TODO: we have to find a way to update the context of the current tab (we could open a new tab with the context but it's not really handy)
#TODO: remove that comments when the client side dev is done #TODO: remove that comments when the client side dev is done
return {} return {}
@ -93,4 +99,4 @@ class account_partner_reconcile_process(osv.osv_memory):
account_partner_reconcile_process() account_partner_reconcile_process()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: