Skip to content

Commit

Permalink
Initial Commit - works with Tryton 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharoon Thomas committed Jul 27, 2012
0 parents commit 80a6dff
Show file tree
Hide file tree
Showing 8 changed files with 982 additions and 0 deletions.
29 changes: 29 additions & 0 deletions INSTALL
@@ -0,0 +1,29 @@
Installing trytond_csv_report
=============================

Prerequisites
-------------

* Python 2.6 or later (http://www.python.org/)
* trytond (http://www.tryton.org/)

Installation
------------

Once you've downloaded and unpacked the trytond_csv_report source
release, enter the directory where the archive was unpacked, and run:

python setup.py install

Note that you may need administrator/root privileges for this step, as
this command will by default attempt to install module to the Python
site-packages directory on your system.

For advanced options, please refer to the easy_install and/or the distutils
documentation:

http://peak.telecommunity.com/DevCenter/EasyInstall
http://docs.python.org/inst/inst.html

To use without installation, extract the archive into ``trytond/modules`` with
the directory name csv_report.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,10 @@
include INSTALL
include README
include TODO
include CHANGELOG
include COPYRIGHT
include LICENSE
include *.xml
include *.odt
include locale/*.po
include doc/*
10 changes: 10 additions & 0 deletions __init__.py
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""
__init__
A generic CSV Report engine
:copyright: (c) 2011 by Openlabs Technologies & Consulting (P) Limited
:license: GPLv3, see LICENSE for more details.
"""
from csv_report_engine import *
18 changes: 18 additions & 0 deletions __tryton__.py
@@ -0,0 +1,18 @@
# -*- coding: UTF-8 -*-
{
'name': 'CSV Report',
'description': '''CSV Report Engine''',
'version': '2.0.0.1',
'author': 'Openlabs Technologies & Consulting (P) LTD',
'email': 'info@openlabs.co.in',
'website': 'http://www.openlabs.co.in/',
'depends': [
'ir',
],
'xml': [
'csv_report_engine.xml',
],
'translation': [
],
}

127 changes: 127 additions & 0 deletions csv_report_engine.py
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-
"""
CSV Report Engine
:copyright: (c) 2011 by Openlabs Technologies & Consulting (P) Ltd.
:license: GPLv3, see LICENSE for more details.
"""
from datetime import date
from tempfile import NamedTemporaryFile
import base64

from trytond.wizard import Wizard
from trytond.model import fields, ModelView


class CSVReportEngine(ModelView):
"""CSV report Engine View
"""
_name = 'csv.report.engine'
_description = __doc__

def get_date(self, end=False):
"""Return the first and last date of current month
:param end: If True returns last day of month
:type end: Boolean
"""
date_obj = self.pool.get('ir.date')
today = date_obj.today()
if end:
return today
return date(today.year, today.month, 1)

def _get_reports(self):
"""Builds a list of tuples for the selection field based on the reports
that already exist.
Registering the profile
~~~~~~~~~~~~~~~~~~~~~~~
class CSVInventoryReport(Wizard):
_name = "csv.report.engine"
def report_inventory(self):
"Inventory Status Report"
return CSVInventoryReport
"""
reports = []
for attribute in dir(self):
if attribute.startswith('report_'):
reports.append((attribute, getattr(self, attribute).__doc__))
return reports

from_date = fields.Date('From Date')
to_date = fields.Date('To Date')
party = fields.Many2One('party.party', 'Party')
report = fields.Selection('_get_reports', 'Report', required=True)

def default_from_date(self):
return self.get_date()

def default_to_date(self):
return self.get_date(end=True)

CSVReportEngine()


class CSVEngineWizardViewResponse(ModelView):
"""This wizard displays the response of csv report
"""
_name = 'csv.report.wizard.response'
_description = 'CSV Engine Response Wizard View'

filename = fields.Char('Filename', readonly=True)
file = fields.Binary('Report Data', readonly=True)

CSVEngineWizardViewResponse()


class CSVEngineWizard(Wizard):
"""A wizard with two states where the first state uses the view above
and takes the data to generate the report
"""
_name = "csv.report.wizard"
_description = "CSV Report Engine"

states = {
'init': {
'actions': [],
'result': {
'type': 'form',
'object': 'csv.report.engine',
'state': [
('end', 'Cancel', 'tryton-cancel'),
('do_generate_report', 'Generate Report',
'tryton-ok', True),
],
},
},
'do_generate_report': {
'actions': ['generate_report'],
'result': {
'type': 'form',
'object': 'csv.report.wizard.response',
'state': [
('end', 'OK', 'tryton-ok'),
],
},
},
}

def generate_report(self, data):
"Generate the report by calling corresponding method"
csv_engine_obj = self.pool.get('csv.report.engine')
buffer = NamedTemporaryFile(delete=False)
getattr(csv_engine_obj, data['form']['report'])(data['form'], buffer)
buffer.close()

with open(buffer.name) as f:
content = f.read()

form = {}
form['file'] = base64.b64encode(content)
form['filename'] = '%s.csv' % (data['form']['report'])
return form

CSVEngineWizard()
56 changes: 56 additions & 0 deletions csv_report_engine.xml
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<tryton>
<data>

<menuitem name="CSV Reports"
id="csv_report"
sequence="50"/>

<!-- CSV Report Engine Wizard -->
<record model="ir.ui.view" id="csv_report_engine_form">
<field name="model">csv.report.engine</field>
<field name="type">form</field>
<field name="arch" type="xml">
<![CDATA[
<form string="CSV Report Engine">
<label name="from_date"/>
<field name="from_date"/>
<label name="to_date"/>
<field name="to_date"/>
<label name="party"/>
<field name="party"/>
<label name="report"/>
<field name="report"/>
</form>
]]>
</field>
</record>

<record model="ir.action.wizard" id="csv_report_wizard">
<field name="name">Generate CSV Report</field>
<field name="wiz_name">csv.report.wizard</field>
</record>

<menuitem name="CSV Report Engine"
parent="csv_report"
action="csv_report_wizard"
id="menu_csv_report_wizard"
sequence="20"/>

<record model="ir.ui.view" id="csv_report_wizard_response_view_form">
<field name="model">csv.report.wizard.response</field>
<field name="type">form</field>
<field name="arch" type="xml">
<![CDATA[
<form string="CSV Report Engine Response">
<field name="filename" colspan="4"/>
<label name="file"/>
<field name="file"/>
</form>
]]>
</field>
</record>

</data>
</tryton>

58 changes: 58 additions & 0 deletions setup.py
@@ -0,0 +1,58 @@
#!/usr/bin/env python

from setuptools import setup
import re

info = eval(open('__tryton__.py').read())
major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2)
major_version = int(major_version)
minor_version = int(minor_version)

requires = []
for dep in info.get('depends', []):
if not re.match(r'(ir|res|workflow|webdav)(\W|$)', dep):
requires.append('trytond_%s >= %s.%s, < %s.%s' %
(dep, major_version, minor_version, major_version,
minor_version + 1))
requires.append('trytond >= %s.%s, < %s.%s' %
(major_version, minor_version, major_version, minor_version + 1))

setup(name='trytond_csv_report',
version=info.get('version', '0.0.1'),
description=info.get('description', ''),
author=info.get('author', ''),
author_email=info.get('email', ''),
url=info.get('website', ''),
download_url="http://downloads.tryton.org/" + \
info.get('version', '0.0.1').rsplit('.', 1)[0] + '/',
package_dir={
'trytond.modules.csv_report': '.',
},
packages=[
'trytond.modules.csv_report',
],
package_data={
'trytond.modules.csv_report': info.get('xml', []) \
+ info.get('translation', []),
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Plugins',
'Intended Audience :: Developers',
'Intended Audience :: Financial and Insurance Industry',
'Intended Audience :: Legal Industry',
'Intended Audience :: Manufacturing',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Office/Business',
],
license='GPL-3',
install_requires=requires,
zip_safe=False,
entry_points="""
[trytond.modules]
barrel = trytond.modules.csv_report
""",
)

0 comments on commit 80a6dff

Please sign in to comment.