[ADD,MOD] account_report : indicator with pdf wizard converted to osv memory wizard

bzr revid: vir@tinyerp.com-20100503065345-av92d15yn9r4s25u
This commit is contained in:
Vir (Open ERP) 2010-05-03 12:23:45 +05:30
parent 02e4a8227a
commit 31e9ce9fe4
6 changed files with 155 additions and 111 deletions

View File

@ -38,6 +38,7 @@
'account_report.xml',
'account_wizard.xml',
'wizard/account_report_print_indicators_view.xml',
'wizard/account_report_print_indicators_with_pdf_view.xml',
],
'demo_xml': [],
'installable': True,

View File

@ -4,7 +4,7 @@
<!-- <wizard id="wizard_print_indicators" name="print.indicators" string="Print Indicators"/>-->
<!-- <menuitem action="wizard_print_indicators" type="wizard" parent="account_report.menu_action_account_report_tree_view" id="menu_wizard_print_indicators"/>-->
<wizard id="wizard_indicators_with_pdf" model="account.report.report" name="print.indicators.pdf" string="Indicators in PDF" keyword="client_action_multi" />
<!-- <wizard id="wizard_indicators_with_pdf" model="account.report.report" name="print.indicators.pdf" string="Indicators in PDF" keyword="client_action_multi" />-->
<!--<menuitem action="wizard_indicators_with_pdf" type="wizard" parent="account_report.menu_action_account_report_tree_view" id="menu_wizard_print_indicators_with_pdf"/>-->
</data>
</openerp>

View File

@ -20,6 +20,6 @@
##############################################################################
import account_report_print_indicators
import wizard_print_indicators_with_pdf
import account_report_print_indicators_with_pdf
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,107 @@
# -*- 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 mx.DateTime import *
import os
import base64
import StringIO
from osv import fields, osv
import tools
import pooler
from report.render import render
from report.interface import report_int
class account_report_print_indicators_with_pdf(osv.osv_memory):
_name = "account.report.print.indicators.with.pdf"
_description = "Print Indicators"
_columns = {
'file': fields.binary('Select a PDF File', filters='*.pdf', required=True),
}
def check_report(self, cr, uid, ids, context=None):
datas = {}
if context is None:
context = {}
data = self.read(cr, uid, ids)[0]
datas = {
'ids': context.get('active_ids',[]),
'model': 'account.report.report',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'print.indicator.pdf',
'datas': datas,
}
account_report_print_indicators_with_pdf()
class external_pdf(render):
def __init__(self, pdf):
render.__init__(self)
self.pdf = pdf
self.output_type='pdf'
def _render(self):
return self.pdf
class report_custom(report_int):
def create(self, cr, uid, ids, data, context={}):
pool = pooler.get_pool(cr.dbname)
obj_indicator = pool.get('account.report.report')
code_ids = obj_indicator.browse(cr,uid,context['active_id'])
self.list={}
def find_child(obj):
self.list[obj.code]=str(obj.amount)
if obj.child_ids:
for child in obj.child_ids:
find_child(child)
return True
find_child(code_ids)
file_contents=base64.decodestring(data['form']['file'])
fp = StringIO.StringIO(file_contents)
infile = open(tools.config['addons_path']+"/test.pdf", 'wb')
infile.write(fp.read())
infile.close()
obj_user=pool.get('res.users').browse(cr,uid,uid)
self.list['printing_user']=str(obj_user.name)
self.list['company_name']=(obj_user.company_id.name)
self.list['company_country']=obj_user.company_id.partner_id.country
self.list['company_vat']=obj_user.company_id.partner_id.vat
self.list['printing_time']=time.strftime('%H:%M:%S')
self.list['printing_date']=time.strftime('%D')
tools.pdf_utils.fill_pdf(tools.config['addons_path']+"/test.pdf",'/tmp/output.pdf',self.list)
self.obj = external_pdf(file('/tmp/output.pdf').read())
self.obj.render()
return (self.obj.pdf, 'pdf')
report_custom('report.print.indicator.pdf')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="account_report_print_indicators_with_pdf_view" model="ir.ui.view">
<field name="name">account.report.print.indicators.with.pdf.form</field>
<field name="model">account.report.print.indicators.with.pdf</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Print Indicators with PDF">
<label string="Select the PDF file on which Indicators will be printed."/>
<newline/>
<field name="file" colspan="4"/>
<separator colspan="4" string=""/>
<group colspan="4" col="6">
<label string ="" colspan="2"/>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="check_report" string="Print" type="object" icon="gtk-print" default_focus="1"/>
</group>
</form>
</field>
</record>
<record id="action_account_report_print_indicators_with_pdf" model="ir.actions.act_window">
<field name="name">Indicators in PDF</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.report.print.indicators.with.pdf</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="account_report_print_indicators_with_pdf_view"/>
<field name="target">new</field>
</record>
<record model="ir.values" id="account_report_print_indicators_with_pdf_values">
<field name="model_id" ref="account_report.model_account_report_report" />
<field name="object" eval="1" />
<field name="name">Indicators in PDF</field>
<field name="key2">client_print_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_account_report_print_indicators_with_pdf'))" />
<field name="key">action</field>
<field name="model">account.report.report</field>
</record>
</data>
</openerp>

View File

@ -1,109 +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 pooler
import time
import datetime
import sys
from mx.DateTime import *
import tools
from report.render import render
from report.interface import report_int
import os
import base64
import StringIO
form = '''<?xml version="1.0"?>
<form string="Print Indicators with PDF">
<label string="Select the PDF file on which Indicators will be printed."/>
<newline/>
<field name="file" colspan="4"/>
</form>'''
fields = {
'file': {'string':'Select a PDF File', 'type':'binary','required':True,'filters':'*.pdf'},
}
class external_pdf(render):
def __init__(self, pdf):
render.__init__(self)
self.pdf = pdf
self.output_type='pdf'
def _render(self):
return self.pdf
class report_custom(report_int):
def create(self, cr, uid, ids, data, context={}):
pool = pooler.get_pool(cr.dbname)
obj_indicator = pool.get('account.report.report')
code_ids = obj_indicator.browse(cr,uid,data['id'])
self.list={}
def find_child(obj):
self.list[obj.code]=str(obj.amount)
if obj.child_ids:
for child in obj.child_ids:
find_child(child)
return True
find_child(code_ids)
file_contents=base64.decodestring(data['form']['file'])
fp = StringIO.StringIO(file_contents)
infile = open(tools.config['addons_path']+"/test.pdf", 'wb')
infile.write(fp.read())
infile.close()
obj_user=pool.get('res.users').browse(cr,uid,uid)
self.list['printing_user']=obj_user.name
self.list['company_name']=obj_user.company_id.name
self.list['company_country']=obj_user.company_id.partner_id.country
self.list['company_vat']=obj_user.company_id.partner_id.vat
self.list['printing_time']=time.strftime('%H:%M:%S')
self.list['printing_date']=time.strftime('%D')
tools.pdf_utils.fill_pdf(tools.config['addons_path']+"/test.pdf",'/tmp/output.pdf',self.list)
self.obj = external_pdf(file('/tmp/output.pdf').read())
self.obj.render()
return (self.obj.pdf, 'pdf')
report_custom('report.print.indicator.pdf')
class wizard_print_indicators_with_pdf(wizard.interface):
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':form, 'fields':fields, 'state':[('end','Cancel'),('print','Print')]}
},
'print': {
'actions':[],
'result' :{'type':'print','report':'print.indicator.pdf', 'state':'end'}
}
}
wizard_print_indicators_with_pdf('print.indicators.pdf')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: