# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (). # # 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 . # ############################################################################## from lxml import etree from osv import osv, fields from tools.translate import _ import tools class account_move_journal(osv.osv_memory): _name = "account.move.journal" _description = "Move journal" _columns = { 'target_move': fields.selection([('posted', 'All Posted Entries'), ('all', 'All Entries'), ], 'Target Moves', required=True), } _defaults = { 'target_move': 'all' } def _get_period(self, cr, uid, context={}): """ Return default account period value """ account_period_obj = self.pool.get('account.period') ids = account_period_obj.find(cr, uid, context=context) period_id = False if ids: period_id = ids[0] return period_id def _get_journal(self, cr, uid, context=None): """ Return journal based on the journal type """ journal_id = False journal_pool = self.pool.get('account.journal') if context.get('journal_type', False): jids = journal_pool.search(cr, uid, [('type','=', context.get('journal_type'))]) if not jids: 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')) journal_id = jids[0] return journal_id 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 @return: Returns a dict that contains definition for fields, views, and toolbars """ if context is None:context = {} 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) if context: if not view_id: return res period_pool = self.pool.get('account.period') journal_pool = self.pool.get('account.journal') 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'] journal_string = _("Journal: %s") % tools.ustr(journal) else: journal_string = _("Journal: All") period = False if period_id: period = period_pool.browse(cr, uid, [period_id], ['name'])[0]['name'] period_string = _("Period: %s") % tools.ustr(period) open_string = _("Open") view = """
%s: