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 '
2010-10-26 13:40:31 +00:00
def open_statement ( self , cr , uid , ids , context = None ) :
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
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-11-23 07:05:05 +00:00
if context is None :
2010-11-22 10:37:53 +00:00
context = { }
2010-06-24 05:17:49 +00:00
2011-09-25 21:00:20 +00:00
st_ids = [ ]
j_ids = journal_obj . search ( cr , uid , [ ( ' journal_user ' , ' = ' , 1 ) ] , context = context )
2011-12-30 17:14:02 +00:00
if not j_ids :
2012-08-03 17:26:36 +00:00
raise osv . except_osv ( _ ( ' No Cash Register Defined ! ' ) , _ ( ' You have to define which payment method must be available in the point of sale by reusing existing bank and cash through " Accounting / Configuration / Journals / Journals " . Select a journal and check the field " PoS Payment Method " from the " Point of Sale " tab. You can also create new payment methods directly from menu " PoS Backend / Configuration / Payment Methods " . ' ) )
2011-09-25 21:00:20 +00:00
for journal in journal_obj . browse ( cr , uid , j_ids , context = context ) :
2010-10-26 13:40:31 +00:00
ids = statement_obj . search ( cr , uid , [ ( ' state ' , ' != ' , ' confirm ' ) , ( ' user_id ' , ' = ' , uid ) , ( ' journal_id ' , ' = ' , journal . id ) ] , context = context )
2010-08-09 09:06:00 +00:00
if journal . sequence_id :
2012-03-14 12:53:24 +00:00
number = sequence_obj . next_by_id ( cr , uid , journal . sequence_id . id , context = context )
2010-08-09 09:06:00 +00:00
else :
2012-03-14 12:53:24 +00:00
number = sequence_obj . next_by_code ( cr , uid , ' account.cash.statement ' , context = context )
2010-08-13 12:20:05 +00:00
2011-09-25 21:00:20 +00:00
data . update ( {
' journal_id ' : journal . id ,
' user_id ' : uid ,
' state ' : ' draft ' ,
2012-08-03 17:26:36 +00:00
' name ' : number
2011-09-25 21:00:20 +00:00
} )
2010-10-26 13:40:31 +00:00
statement_id = statement_obj . create ( cr , uid , data , context = context )
2012-02-10 08:19:09 +00:00
st_ids . append ( int ( statement_id ) )
2012-08-03 17:26:36 +00:00
2012-04-16 09:01:22 +00:00
if journal . opening_control :
2011-09-25 21:00:20 +00:00
statement_obj . button_open ( cr , uid , [ statement_id ] , context )
2010-07-01 11:03:45 +00:00
2011-09-25 21:00:20 +00:00
tree_res = mod_obj . get_object_reference ( cr , uid , ' point_of_sale ' , ' view_cash_statement_pos_tree ' )
2010-10-28 13:16:19 +00:00
tree_id = tree_res and tree_res [ 1 ] or False
form_res = mod_obj . get_object_reference ( cr , uid , ' account ' , ' view_bank_statement_form2 ' )
form_id = form_res and form_res [ 1 ] or False
2012-02-09 18:04:33 +00:00
search_res = mod_obj . get_object_reference ( cr , uid , ' account ' , ' view_account_bank_statement_filter ' )
search_id = search_res and search_res [ 1 ] or False
2012-08-03 17:26:36 +00:00
2011-12-30 17:14:02 +00:00
return {
2012-02-09 18:04:33 +00:00
' type ' : ' ir.actions.act_window ' ,
' name ' : _ ( ' List of Cash Registers ' ) ,
' view_type ' : ' form ' ,
2012-02-10 13:46:06 +00:00
' view_mode ' : ' tree,form ' ,
2012-02-09 18:04:33 +00:00
' res_model ' : ' account.bank.statement ' ,
2012-02-10 13:57:54 +00:00
' domain ' : str ( [ ( ' id ' , ' in ' , st_ids ) ] ) ,
2012-02-09 18:04:33 +00:00
' views ' : [ ( tree_id , ' tree ' ) , ( form_id , ' form ' ) ] ,
' search_view_id ' : search_id ,
2010-08-13 12:20:05 +00:00
}
2012-08-03 17:26:36 +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: