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 _
|
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-08-10 13:29:34 +00:00
|
|
|
data = {}
|
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-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')
|
2010-10-01 09:26:28 +00:00
|
|
|
cr.execute("SELECT DISTINCT journal_id FROM pos_journal_users "
|
2010-10-01 13:18:28 +00:00
|
|
|
"WHERE user_id=%s ORDER BY journal_id"% (uid,))
|
2010-08-09 09:06:00 +00:00
|
|
|
j_ids = map(lambda x1: x1[0], cr.fetchall())
|
2010-08-10 12:38:18 +00:00
|
|
|
journal_ids = journal_obj.search(cr, uid, [('auto_cash', '=', True), ('type', '=', 'cash'), ('id', 'in', j_ids)])
|
2010-06-24 05:17:49 +00:00
|
|
|
|
2010-08-09 09:06:00 +00:00
|
|
|
for journal in journal_obj.browse(cr, uid, 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-08-09 09:06:00 +00:00
|
|
|
if len(ids):
|
2010-09-11 10:06:10 +00:00
|
|
|
raise osv.except_osv(_('Message'), _('You can not open a Cashbox for "%s".\nPlease close its related Register.' %(journal.name)))
|
2010-10-01 13:18:28 +00:00
|
|
|
|
2010-08-09 09:06:00 +00:00
|
|
|
number = ''
|
|
|
|
if journal.sequence_id:
|
|
|
|
number = sequence_obj.get_id(cr, uid, journal.sequence_id.id)
|
|
|
|
else:
|
2010-10-01 13:18:28 +00:00
|
|
|
number = sequence_obj.get(cr, uid, 'account.cash.statement')
|
2010-08-13 12:20:05 +00:00
|
|
|
|
|
|
|
data.update({'journal_id': journal.id,
|
2010-08-10 13:29:34 +00:00
|
|
|
'company_id': company_id,
|
|
|
|
'user_id': uid,
|
2010-10-01 13:18:28 +00:00
|
|
|
'state': 'draft',
|
2010-08-10 13:29:34 +00:00
|
|
|
'name': number })
|
|
|
|
statement_id = statement_obj.create(cr, uid, data)
|
2010-08-09 09:06:00 +00:00
|
|
|
statement_obj.button_open(cr, uid, [statement_id], context)
|
2010-07-01 11:03:45 +00:00
|
|
|
|
|
|
|
data_obj = self.pool.get('ir.model.data')
|
|
|
|
id2 = data_obj._get_id(cr, uid, 'account', 'view_bank_statement_tree')
|
|
|
|
id3 = data_obj._get_id(cr, uid, 'account', 'view_bank_statement_form2')
|
2010-09-13 05:37:35 +00:00
|
|
|
result = data_obj._get_id(cr, uid, 'point_of_sale', 'view_pos_open_cash_statement_filter')
|
|
|
|
search_id = mod_obj.read(cr, uid, result, ['res_id'], context=context)
|
2010-07-01 11:03:45 +00:00
|
|
|
if id2:
|
|
|
|
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
|
|
|
|
if id3:
|
|
|
|
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
|
|
|
|
|
2010-06-24 05:17:49 +00:00
|
|
|
return {
|
2010-09-17 09:22:57 +00:00
|
|
|
'domain': "[('state','=','open'),('user_id','=',"+ str(uid) +")]",
|
2010-06-24 05:17:49 +00:00
|
|
|
'name': 'Open Statement',
|
|
|
|
'view_type': 'form',
|
|
|
|
'view_mode': 'tree,form',
|
2010-09-13 05:37:35 +00:00
|
|
|
'search_view_id': search_id['res_id'],
|
2010-06-24 05:17:49 +00:00
|
|
|
'res_model': 'account.bank.statement',
|
2010-07-01 11:03:45 +00:00
|
|
|
'views': [(id2, 'tree'),(id3, 'form')],
|
2010-09-13 05:37:35 +00:00
|
|
|
'context': {'search_default_open': 1},
|
2010-06-24 05:17:49 +00:00
|
|
|
'type': 'ir.actions.act_window'
|
2010-08-13 12:20:05 +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:
|