2010-03-30 12:47:02 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# 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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
2010-10-25 08:11:24 +00:00
from lxml import etree
2010-12-10 10:31:12 +00:00
from osv import osv , fields
2010-03-30 12:47:02 +00:00
from tools . translate import _
2010-10-21 06:24:21 +00:00
import tools
2010-03-30 12:47:02 +00:00
class account_move_journal ( osv . osv_memory ) :
_name = " account.move.journal "
_description = " Move journal "
2010-12-10 10:31:12 +00:00
_columns = {
' target_move ' : fields . selection ( [ ( ' posted ' , ' All Posted Entries ' ) ,
( ' all ' , ' All Entries ' ) ,
] , ' Target Moves ' , required = True ) ,
}
_defaults = {
' target_move ' : ' posted '
}
2010-03-30 12:47:02 +00:00
def _get_period ( self , cr , uid , context = { } ) :
2010-08-12 20:17:33 +00:00
"""
Return default account period value
"""
2010-10-15 13:35:22 +00:00
account_period_obj = self . pool . get ( ' account.period ' )
ids = account_period_obj . find ( cr , uid , context = context )
2010-03-30 12:47:02 +00:00
period_id = False
2010-10-11 05:51:53 +00:00
if ids :
2010-03-30 12:47:02 +00:00
period_id = ids [ 0 ]
return period_id
2010-11-19 13:48:01 +00:00
def _get_journal ( self , cr , uid , context = None ) :
2010-08-12 20:17:33 +00:00
"""
Return journal based on the journal type
"""
journal_id = False
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
journal_pool = self . pool . get ( ' account.journal ' )
if context . get ( ' journal_type ' , False ) :
jids = journal_pool . search ( cr , uid , [ ( ' type ' , ' = ' , context . get ( ' journal_type ' ) ) ] )
2010-08-18 14:49:45 +00:00
if not jids :
2010-11-15 18:46:17 +00:00
raise osv . except_osv ( _ ( ' Configuration Error ! ' ) , _ ( ' Can \' t find any account journal of %s type for this company. \n \n You can create one in the menu: \n Configuration/Financial Accounting/Accounts/Journals. ' ) % context . get ( ' journal_type ' ) )
2010-08-12 20:17:33 +00:00
journal_id = jids [ 0 ]
return journal_id
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
def fields_view_get ( self , cr , uid , view_id = None , view_type = ' form ' , context = None , toolbar = False , submenu = False ) :
"""
Returns views and fields for current model where view will depend on { view_type } .
@param cr : A database cursor
@param user : ID of the user currently logged in
@param view_id : list of fields , which required to read signatures
@param view_type : defines a view type . it can be one of ( form , tree , graph , calender , gantt , search , mdx )
@param context : context arguments , like lang , time zone
@param toolbar : contains a list of reports , wizards , and links related to current model
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
@return : Returns a dict that contains definition for fields , views , and toolbars
"""
res = super ( account_move_journal , self ) . fields_view_get ( cr , uid , view_id , view_type , context , toolbar , submenu )
2010-04-29 07:27:46 +00:00
2010-08-12 20:17:33 +00:00
if not view_id :
return res
period_pool = self . pool . get ( ' account.period ' )
journal_pool = self . pool . get ( ' account.journal ' )
2010-09-29 13:33:06 +00:00
2010-08-12 20:17:33 +00:00
journal_id = self . _get_journal ( cr , uid , context )
period_id = self . _get_period ( cr , uid , context )
journal = False
if journal_id :
journal = journal_pool . read ( cr , uid , [ journal_id ] , [ ' name ' ] ) [ 0 ] [ ' name ' ]
2010-12-22 10:16:15 +00:00
journal_string = _ ( " Journal: %s " ) % tools . ustr ( journal )
2010-08-12 20:17:33 +00:00
else :
2010-12-22 10:16:15 +00:00
journal_string = _ ( " Journal: All " )
2010-08-12 20:17:33 +00:00
period = False
if period_id :
period = period_pool . browse ( cr , uid , [ period_id ] , [ ' name ' ] ) [ 0 ] [ ' name ' ]
2010-12-22 10:16:15 +00:00
period_string = _ ( " Period: %s " ) % tools . ustr ( period )
2010-08-12 20:17:33 +00:00
2011-01-07 15:56:23 +00:00
separator_string = _ ( " Open Journal Items ! " )
cancel_string = _ ( " Cancel " )
open_string = _ ( " Open " )
2010-08-12 20:17:33 +00:00
view = """ <?xml version= " 1.0 " encoding= " utf-8 " ?>
< form string = " Standard entries " >
2011-01-07 15:56:23 +00:00
< separator string = " %s " colspan = " 4 " / >
2010-12-10 10:31:12 +00:00
< field name = " target_move " / >
< newline / >
2010-08-12 20:17:33 +00:00
< group colspan = " 4 " >
2010-12-22 10:16:15 +00:00
< label width = " 300 " string = " %s " / >
2010-08-13 14:02:11 +00:00
< newline / >
2010-12-22 10:16:15 +00:00
< label width = " 300 " string = " %s " / >
2010-08-12 20:17:33 +00:00
< / group >
< group colspan = " 4 " col = " 4 " >
< label string = " " colspan = " 2 " / >
2011-01-07 15:56:23 +00:00
< button icon = " gtk-cancel " special = " cancel " string = " %s " / >
< button icon = " terp-gtk-go-back-rtl " string = " %s " name = " action_open_window " default_focus = " 1 " type = " object " / >
2010-08-12 20:17:33 +00:00
< / group >
2011-01-07 15:56:23 +00:00
< / form > """ % (separator_string, journal_string, period_string, cancel_string, open_string)
2010-09-29 13:33:06 +00:00
2010-10-25 06:27:48 +00:00
view = etree . fromstring ( view . encode ( ' utf8 ' ) )
xarch , xfields = self . _view_look_dom_arch ( cr , uid , view , view_id , context = context )
view = xarch
2010-08-12 20:17:33 +00:00
res . update ( {
2010-10-25 06:27:48 +00:00
' arch ' : view
2010-08-12 20:17:33 +00:00
} )
return res
2010-09-29 13:33:06 +00:00
2010-04-29 07:27:46 +00:00
def action_open_window ( self , cr , uid , ids , context = None ) :
2010-03-30 12:47:02 +00:00
"""
This function Open action move line window on given period and Journal / Payment Mode
@param cr : the current row , from the database cursor ,
@param uid : the current user ’ s ID for security checks ,
@param ids : account move journal ’ s ID or list of IDs
@return : dictionary of Open action move line window on given period and Journal / Payment Mode
"""
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
period_pool = self . pool . get ( ' account.journal.period ' )
data_pool = self . pool . get ( ' ir.model.data ' )
journal_pool = self . pool . get ( ' account.journal ' )
2010-10-15 13:35:22 +00:00
account_period_obj = self . pool . get ( ' account.period ' )
2010-10-08 12:49:22 +00:00
2010-04-29 07:27:46 +00:00
if context is None :
context = { }
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
journal_id = self . _get_journal ( cr , uid , context )
period_id = self . _get_period ( cr , uid , context )
2010-12-10 10:31:12 +00:00
target_move = self . read ( cr , uid , ids , [ ] ) [ 0 ] [ ' target_move ' ]
2010-03-30 12:47:02 +00:00
2010-08-12 20:17:33 +00:00
name = _ ( " Journal Items " )
if journal_id :
ids = period_pool . search ( cr , uid , [ ( ' journal_id ' , ' = ' , journal_id ) , ( ' period_id ' , ' = ' , period_id ) ] , context = context )
2010-10-08 12:49:22 +00:00
if not ids :
2010-12-13 06:43:09 +00:00
journal = journal_pool . browse ( cr , uid , journal_id , context = context )
period = account_period_obj . browse ( cr , uid , period_id , context = context )
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
name = journal . name
state = period . state
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
if state == ' done ' :
raise osv . except_osv ( _ ( ' UserError ' ) , _ ( ' This period is already closed ! ' ) )
2010-10-08 12:49:22 +00:00
2010-08-12 20:17:33 +00:00
company = period . company_id . id
res = {
2010-10-08 12:49:22 +00:00
' name ' : name ,
' period_id ' : period_id ,
' journal_id ' : journal_id ,
2010-08-12 20:17:33 +00:00
' company_id ' : company
}
period_pool . create ( cr , uid , res , context = context )
2010-10-08 12:49:22 +00:00
2010-12-10 10:31:12 +00:00
ids = period_pool . search ( cr , uid , [ ( ' journal_id ' , ' = ' , journal_id ) , ( ' period_id ' , ' = ' , period_id ) ] , context = context )
2010-08-12 20:17:33 +00:00
period = period_pool . browse ( cr , uid , ids [ 0 ] , context = context )
name = ( period . journal_id . code or ' ' ) + ' : ' + ( period . period_id . code or ' ' )
2010-10-08 12:49:22 +00:00
2010-10-28 08:35:00 +00:00
result = data_pool . get_object_reference ( cr , uid , ' account ' , ' view_account_move_line_filter ' )
res_id = result and result [ 1 ] or False
2010-12-10 10:31:12 +00:00
move = 0
if target_move == ' posted ' :
move = 1
2010-04-29 07:27:46 +00:00
return {
' name ' : name ,
' view_type ' : ' form ' ,
2010-08-13 12:22:26 +00:00
' view_mode ' : ' tree,graph,form ' ,
2010-04-29 07:27:46 +00:00
' res_model ' : ' account.move.line ' ,
2010-08-12 20:17:33 +00:00
' view_id ' : False ,
2010-12-10 10:31:12 +00:00
' context ' : " { ' search_default_posted ' : %d , ' visible_id ' : %s , ' search_default_journal_id ' : %d , ' search_default_period_id ' : %d } " % ( move , journal_id , journal_id , period_id ) ,
2010-04-29 07:27:46 +00:00
' type ' : ' ir.actions.act_window ' ,
2010-08-12 20:17:33 +00:00
' search_view_id ' : res_id
}
2010-10-08 12:49:22 +00:00
2010-03-30 12:47:02 +00:00
account_move_journal ( )
2010-12-22 10:16:15 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: