[ADD] account_analytic_plan: crossovered report => osv memory

bzr revid: mra@tinyerp.com-20100427073715-pjgwk3lnd21zf2s0
This commit is contained in:
mra (Open ERP)
2010-04-27 13:07:15 +05:30
parent 638cbefb65
commit bb6b33011c
6 changed files with 126 additions and 84 deletions
+2 -1
View File
@@ -62,7 +62,8 @@ of distribution models.
'security/ir.model.access.csv',
'account_analytic_plans_view.xml',
'account_analytic_plans_report.xml',
'wizard/analytic_plan_create_model_view.xml'
'wizard/analytic_plan_create_model_view.xml',
'wizard/account_crossovered_analytic_view.xml'
],
'demo_xml': [],
'installable': True,
@@ -11,12 +11,12 @@
auto="False"
menu="False"/>
<wizard
<!--<wizard
id="account_analytic_account_inverted_balance_report"
string="Crossovered Analytic"
model="account.analytic.account"
name="wizard.crossovered.analytic"
keyword="client_print_multi"/>
keyword="client_print_multi"/>-->
</data>
</openerp>
@@ -20,6 +20,6 @@
##############################################################################
import analytic_plan_create_model
import wizard_crossovered_analytic
import account_crossovered_analytic
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,74 @@
# -*- 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/>.
#
##############################################################################
import time
from osv import osv, fields
from tools.translate import _
class account_crossovered_analytic(osv.osv_memory):
_name = 'account.crossovered.analytic'
_description = 'Print Crossovered Analytic'
_columns = {
'date1': fields.date('Start Date', required=True),
'date2': fields.date('End Date', required=True),
'journal_ids': fields.many2many('account.analytic.journal', 'crossovered_journal_rel', 'crossover_id', 'journal_id', 'Analytic Journal'),
'ref': fields.many2one('account.analytic.account', 'Analytic Account Reference', required=True),
'empty_line': fields.boolean('Dont show empty lines'),
}
_defaults = {
'date1': lambda *a: time.strftime('%Y-01-01'),
'date2': lambda *a: time.strftime('%Y-%m-%d'),
}
def print_report(self, cr, uid, ids, context=None):
cr.execute('select account_id from account_analytic_line')
res = cr.fetchall()
acc_ids = [x[0] for x in res]
data = self.read(cr, uid, ids, [], context=context)[0]
obj_acc = self.pool.get('account.analytic.account').browse(cr, uid, data['ref'])
name = obj_acc.name
account_ids = self.pool.get('account.analytic.account').search(cr, uid, [('parent_id', 'child_of', [data['ref']])])
flag = True
for acc in account_ids:
if acc in acc_ids:
flag = False
break
if flag:
raise osv.except_osv(_('User Error'),_('There are no Analytic lines related to Account %s' % name))
datas = {
'ids': [],
'model': 'account.analytic.account',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'account.analytic.account.crossovered.analytic',
'datas': datas,
}
account_crossovered_analytic()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_account_crossovered_analytic" model="ir.ui.view">
<field name="name">account.crossovered.analytic.form</field>
<field name="model">account.crossovered.analytic</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Crossovered Analytic">
<group col="4" colspan="6">
<field name="date1"/>
<field name="date2"/>
<field name="ref" colspan="4"/>
<field name="journal_ids" colspan="4"/>
<field name="empty_line"/>
</group>
<separator colspan="4"/>
<group col="2" colspan="4">
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
<button name="print_report" string="Print" colspan="1" type="object" icon="gtk-print"/>
</group>
</form>
</field>
</record>
<record id="action_account_crossovered_analytic" model="ir.actions.act_window">
<field name="name">Crossovered Analytic</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.crossovered.analytic</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record model="ir.values" id="account_crossovered_analytic_values">
<field name="model_id" ref="analytic.model_account_analytic_account" />
<field name="object" eval="1" />
<field name="name">Crossovered Analytic</field>
<field name="key2">client_print_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_account_crossovered_analytic'))" />
<field name="key">action</field>
<field name="model">account.analytic.account</field>
</record>
</data>
</openerp>
@@ -1,80 +0,0 @@
# -*- 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/>.
#
##############################################################################
import wizard
import time
import datetime
import pooler
from tools.translate import _
form = """<?xml version="1.0"?>
<form string="Select Information">
<field name="date1"/>
<field name="date2"/>
<field name="ref" colspan="4"/>
<field name="journal_ids" colspan="4"/>
<field name="empty_line"/>
</form>"""
fields = {
'date1': {'string':'Start Date', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
'date2': {'string':'End Date', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
'journal_ids': {'string':'Analytic Journal', 'type':'many2many', 'relation':'account.analytic.journal'},
'ref' :{'string':'Analytic Account Reference', 'type':'many2one', 'relation':'account.analytic.account','required':True},
'empty_line': {'string':'Dont show empty lines', 'type':'boolean', 'default': lambda *a:False},
}
class wizard_crossovered_analytic(wizard.interface):
def _checklines(self, cr, uid, data, context):
cr.execute('select account_id from account_analytic_line')
res=cr.fetchall()
acc_ids=[x[0] for x in res]
obj_acc = pooler.get_pool(cr.dbname).get('account.analytic.account').browse(cr,uid,data['form']['ref'])
name=obj_acc.name
account_ids = pooler.get_pool(cr.dbname).get('account.analytic.account').search(cr, uid, [('parent_id', 'child_of', [data['form']['ref']])])
flag = True
for acc in account_ids:
if acc in acc_ids:
flag = False
break
if flag:
raise wizard.except_wizard(_('User Error'),_('There are no Analytic lines related to Account %s' % name))
return {}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':form, 'fields':fields, 'state':[('end','Cancel'),('print','Print')]},
},
'print': {
'actions': [_checklines],
'result': {'type':'print', 'report':'account.analytic.account.crossovered.analytic', 'state':'end'},
},
}
wizard_crossovered_analytic('wizard.crossovered.analytic')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: