2010-03-12 06:39:09 +00:00
# -*- coding: utf-8 -*-
##############################################################################
2010-03-29 12:38:53 +00:00
#
2010-03-12 06:39:09 +00:00
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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
2010-03-29 12:38:53 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2010-03-12 06:39:09 +00:00
#
##############################################################################
2010-03-29 12:38:53 +00:00
from osv import osv
2010-03-12 06:39:09 +00:00
from tools . translate import _
import time
2010-03-29 12:38:53 +00:00
2010-03-12 06:39:09 +00:00
class pos_open_statement ( osv . osv_memory ) :
_name = ' pos.open.statement '
_description = ' Open Statements '
def open_statement ( self , cr , uid , ids , context ) :
2010-03-29 12:38:53 +00:00
"""
Open the statements
2010-03-12 06:39:09 +00:00
@param self : The object pointer .
@param cr : A database cursor
@param uid : ID of the user currently logged in
2010-03-29 12:38:53 +00:00
@param context : A standard dictionary
@return : Blank Directory
"""
2010-06-21 16:12:29 +00:00
list_statement = [ ]
2010-06-24 05:17:49 +00:00
mod_obj = self . pool . get ( ' ir.model.data ' )
2010-03-29 12:38:53 +00:00
company_id = self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid ) . company_id . id
statement_obj = self . pool . get ( ' account.bank.statement ' )
2010-03-12 06:39:09 +00:00
singer_obj = self . pool . get ( ' singer.statement ' )
2010-06-21 16:12:29 +00:00
sequence_obj = self . pool . get ( ' ir.sequence ' )
2010-03-29 12:38:53 +00:00
journal_obj = self . pool . get ( ' account.journal ' )
journal_lst = journal_obj . search ( cr , uid , [ ( ' company_id ' , ' = ' , company_id ) , ( ' auto_cash ' , ' = ' , True ) ] )
2010-06-24 05:17:49 +00:00
sql = """
select journal_id from pos_journal_users
where user_id = % d
""" % (uid)
cr . execute ( sql )
user_journals = cr . fetchall ( )
lst = map ( lambda x : x [ 0 ] , user_journals )
journal_ids = journal_obj . browse ( cr , uid , lst )
2010-03-12 06:39:09 +00:00
for journal in journal_ids :
2010-03-29 12:38:53 +00:00
ids = statement_obj . search ( cr , uid , [ ( ' state ' , ' != ' , ' confirm ' ) , ( ' user_id ' , ' = ' , uid ) , ( ' journal_id ' , ' = ' , journal . id ) ] )
2010-03-12 06:39:09 +00:00
if len ( ids ) :
2010-03-29 12:38:53 +00:00
raise osv . except_osv ( _ ( ' Message ' ) , _ ( ' You can not open a Cashbox for " %s " . \n Please close the cashbox related to. ' % ( journal . name ) ) )
2010-03-12 06:39:09 +00:00
sql = """ Select id from account_bank_statement
where journal_id = % d
and company_id = % d
2010-03-29 12:38:53 +00:00
order by id desc limit 1 """ % (journal.id, company_id)
2010-03-12 06:39:09 +00:00
cr . execute ( sql )
st_id = cr . fetchone ( )
2010-03-29 12:38:53 +00:00
number = ' '
2010-06-29 13:30:13 +00:00
if journal . sequence_id :
2010-03-12 06:39:09 +00:00
number = sequence_obj . get_id ( cr , uid , journal . id )
else :
number = sequence_obj . get ( cr , uid ,
' account.bank.statement ' )
2010-03-29 12:38:53 +00:00
2010-06-29 13:30:13 +00:00
statement_id = statement_obj . create ( cr , uid , { ' journal_id ' : journal . id ,
' company_id ' : company_id ,
' user_id ' : uid ,
' state ' : ' open ' ,
' name ' : number
} )
statement_obj . button_open ( cr , uid , [ statement_id ] , context )
# period = statement_obj._get_period(cr, uid, context) or None
# cr.execute("INSERT INTO account_bank_statement(journal_id,company_id,user_id,state,name, period_id,date) VALUES(%d,%d,%d,'open','%s',%d,'%s')"%(journal.id, company_id, uid, number, period, time.strftime('%Y-%m-%d %H:%M:%S')))
# cr.commit()
# cr.execute("select id from account_bank_statement where journal_id=%d and company_id=%d and user_id=%d and state='open' and name='%s'"%(journal.id, company_id, uid, number))
# statement_id = cr.fetchone()[0]
# print "statement_id",statement_id
# if st_id:
# statemt_id = statement_obj.browse(cr, uid, st_id[0])
# list_statement.append(statemt_id.id)
# if statemt_id and statemt_id.ending_details_ids:
# statement_obj.write(cr, uid, [statement_id], {
# 'balance_start': statemt_id.balance_end,
# 'state': 'open',
# })
# if statemt_id.ending_details_ids:
# for i in statemt_id.ending_details_ids:
# c = statement_obj.create(cr, uid, {
# 'pieces': i.pieces,
# 'number': i.number,
# 'starting_id': statement_id,
# })
2010-06-24 05:17:49 +00:00
model_data_ids = mod_obj . search ( cr , uid , [ ( ' model ' , ' = ' , ' ir.ui.view ' ) , ( ' name ' , ' = ' , ' view_bank_statement_tree ' ) ] , context = context )
resource_id = mod_obj . read ( cr , uid , model_data_ids , fields = [ ' res_id ' ] , context = context ) [ 0 ] [ ' res_id ' ]
return {
# 'domain': "[('id','in', ["+','.join(map(str,list_statement))+"])]",
' domain ' : " [( ' state ' , ' = ' , ' open ' )] " ,
' name ' : ' Open Statement ' ,
' view_type ' : ' form ' ,
' view_mode ' : ' tree,form ' ,
' res_model ' : ' account.bank.statement ' ,
' views ' : [ ( resource_id , ' tree ' ) ] ,
' type ' : ' ir.actions.act_window '
}
# return {}
2010-03-29 12:38:53 +00:00
2010-03-12 06:39:09 +00:00
pos_open_statement ( )
2010-03-29 12:38:53 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: