1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from lxml import etree
24 from osv import osv, fields
25 from tools.translate import _
28 class account_move_journal(osv.osv_memory):
29 _name = "account.move.journal"
30 _description = "Move journal"
33 'target_move': fields.selection([('posted', 'All Posted Entries'),
34 ('all', 'All Entries'),
35 ], 'Target Moves', required=True),
41 def _get_period(self, cr, uid, context={}):
43 Return default account period value
45 account_period_obj = self.pool.get('account.period')
46 ids = account_period_obj.find(cr, uid, context=context)
52 def _get_journal(self, cr, uid, context=None):
54 Return journal based on the journal type
59 journal_pool = self.pool.get('account.journal')
60 if context.get('journal_type', False):
61 jids = journal_pool.search(cr, uid, [('type','=', context.get('journal_type'))])
63 raise osv.except_osv(_('Configuration Error !'), _('Can\'t find any account journal of %s type for this company.\n\nYou can create one in the menu: \nConfiguration/Financial Accounting/Accounts/Journals.') % context.get('journal_type'))
68 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
70 Returns views and fields for current model where view will depend on {view_type}.
71 @param cr: A database cursor
72 @param user: ID of the user currently logged in
73 @param view_id: list of fields, which required to read signatures
74 @param view_type: defines a view type. it can be one of (form, tree, graph, calender, gantt, search, mdx)
75 @param context: context arguments, like lang, time zone
76 @param toolbar: contains a list of reports, wizards, and links related to current model
78 @return: Returns a dict that contains definition for fields, views, and toolbars
80 if context is None:context = {}
81 res = super(account_move_journal, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
87 period_pool = self.pool.get('account.period')
88 journal_pool = self.pool.get('account.journal')
90 journal_id = self._get_journal(cr, uid, context)
91 period_id = self._get_period(cr, uid, context)
95 journal = journal_pool.read(cr, uid, [journal_id], ['name'])[0]['name']
96 journal_string = _("Journal: %s") % tools.ustr(journal)
98 journal_string = _("Journal: All")
102 period = period_pool.browse(cr, uid, [period_id], ['name'])[0]['name']
103 period_string = _("Period: %s") % tools.ustr(period)
105 separator_string = _("Open Journal Items !")
106 cancel_string = _("Cancel")
107 open_string = _("Open")
108 view = """<?xml version="1.0" encoding="utf-8"?>
109 <form string="Standard entries">
111 <button icon="terp-gtk-go-back-rtl" string="%s" name="action_open_window" default_focus="1" type="object"/>
112 <button icon="gtk-cancel" special="cancel" string="%s"/>
114 <group string="%s" colspan="4">
115 <field name="target_move" />
118 <label width="300" string="%s"/>
120 <label width="300" string="%s"/>
122 </form>""" % (open_string, cancel_string, separator_string, journal_string, period_string)
124 view = etree.fromstring(view.encode('utf8'))
125 xarch, xfields = self._view_look_dom_arch(cr, uid, view, view_id, context=context)
132 def action_open_window(self, cr, uid, ids, context=None):
134 This function Open action move line window on given period and Journal/Payment Mode
135 @param cr: the current row, from the database cursor,
136 @param uid: the current user’s ID for security checks,
137 @param ids: account move journal’s ID or list of IDs
138 @return: dictionary of Open action move line window on given period and Journal/Payment Mode
141 period_pool = self.pool.get('account.journal.period')
142 data_pool = self.pool.get('ir.model.data')
143 journal_pool = self.pool.get('account.journal')
144 account_period_obj = self.pool.get('account.period')
149 journal_id = self._get_journal(cr, uid, context)
150 period_id = self._get_period(cr, uid, context)
151 target_move = self.read(cr, uid, ids, ['target_move'], context=context)[0]['target_move']
153 name = _("Journal Items")
155 ids = period_pool.search(cr, uid, [('journal_id', '=', journal_id), ('period_id', '=', period_id)], context=context)
158 journal = journal_pool.browse(cr, uid, journal_id, context=context)
159 period = account_period_obj.browse(cr, uid, period_id, context=context)
165 raise osv.except_osv(_('UserError'), _('This period is already closed !'))
167 company = period.company_id.id
170 'period_id': period_id,
171 'journal_id': journal_id,
172 'company_id': company
174 period_pool.create(cr, uid, res,context=context)
176 ids = period_pool.search(cr, uid, [('journal_id', '=', journal_id), ('period_id', '=', period_id)], context=context)
177 period = period_pool.browse(cr, uid, ids[0], context=context)
178 name = (period.journal_id.code or '') + ':' + (period.period_id.code or '')
180 result = data_pool.get_object_reference(cr, uid, 'account', 'view_account_move_line_filter')
181 res_id = result and result[1] or False
183 if target_move == 'posted':
188 'view_mode': 'tree,graph,form',
189 'res_model': 'account.move.line',
191 'context': "{'search_default_posted': %d, 'search_default_journal_id':%d, 'search_default_period_id':%d}" % (move, journal_id, period_id),
192 'type': 'ir.actions.act_window',
193 'search_view_id': res_id
196 account_move_journal()
198 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: