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=None):
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!'), _('Cannot find any account journal of %s type for this company.\n\nYou can create one in the menu: \nConfiguration/Journals/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'], context=context).get('name',False)
96 journal_string = _("Journal: %s") % tools.ustr(journal)
98 journal_string = _("Journal: All")
102 period = period_pool.browse(cr, uid, period_id, context=context).name
103 period_string = _("Period: %s") % tools.ustr(period)
105 open_string = _("Open")
106 view = """<?xml version="1.0" encoding="utf-8"?>
107 <form string="Standard entries" version="7.0">
109 <field name="target_move"/>
111 %s: <label string="%s"/>
112 %s: <label string="%s"/>
114 <button string="%s" name="action_open_window" default_focus="1" type="object" class="oe_highlight"/>
116 <button string="Cancel" class="oe_link" special="cancel"/>
118 </form>""" % (_('Journal'), journal_string, _('Period'), period_string, open_string)
120 view = etree.fromstring(view.encode('utf8'))
121 xarch, xfields = self._view_look_dom_arch(cr, uid, view, view_id, context=context)
128 def action_open_window(self, cr, uid, ids, context=None):
130 This function Open action move line window on given period and Journal/Payment Mode
131 @param cr: the current row, from the database cursor,
132 @param uid: the current user’s ID for security checks,
133 @param ids: account move journal’s ID or list of IDs
134 @return: dictionary of Open action move line window on given period and Journal/Payment Mode
137 period_pool = self.pool.get('account.journal.period')
138 data_pool = self.pool.get('ir.model.data')
139 journal_pool = self.pool.get('account.journal')
140 account_period_obj = self.pool.get('account.period')
145 journal_id = self._get_journal(cr, uid, context)
146 period_id = self._get_period(cr, uid, context)
147 target_move = self.read(cr, uid, ids, ['target_move'], context=context)[0]['target_move']
149 name = _("Journal Items")
151 ids = period_pool.search(cr, uid, [('journal_id', '=', journal_id), ('period_id', '=', period_id)], context=context)
154 journal = journal_pool.browse(cr, uid, journal_id, context=context)
155 period = account_period_obj.browse(cr, uid, period_id, context=context)
161 raise osv.except_osv(_('User Error!'), _('This period is already closed.'))
163 company = period.company_id.id
166 'period_id': period_id,
167 'journal_id': journal_id,
168 'company_id': company
170 period_pool.create(cr, uid, res,context=context)
172 ids = period_pool.search(cr, uid, [('journal_id', '=', journal_id), ('period_id', '=', period_id)], context=context)
173 period = period_pool.browse(cr, uid, ids[0], context=context)
174 name = (period.journal_id.code or '') + ':' + (period.period_id.code or '')
176 result = data_pool.get_object_reference(cr, uid, 'account', 'view_account_move_line_filter')
177 res_id = result and result[1] or False
179 if target_move == 'posted':
184 'view_mode': 'tree,graph,form',
185 'res_model': 'account.move.line',
187 'context': "{'search_default_posted': %d, 'search_default_journal_id':%d, 'search_default_period_id':%d}" % (move, journal_id, period_id),
188 'type': 'ir.actions.act_window',
189 'search_view_id': res_id
192 account_move_journal()
194 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: