Browse Source

[ADD] export global cooperator data to XLXS file

pull/1/head
houssine 6 years ago
parent
commit
5700c135f7
  1. 2
      easy_my_coop_export_xlsx/__init__.py
  2. 45
      easy_my_coop_export_xlsx/__openerp__.py
  3. 2
      easy_my_coop_export_xlsx/wizard/__init__.py
  4. 291
      easy_my_coop_export_xlsx/wizard/export_global_wizard.py
  5. 33
      easy_my_coop_export_xlsx/wizard/export_global_wizard.xml

2
easy_my_coop_export_xlsx/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf8 -*-
from . import wizard

45
easy_my_coop_export_xlsx/__openerp__.py

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018- Coop IT Easy SCRLfs.
#
# 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.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
##############################################################################
{
'name': 'Easy My Coop Export XLSX',
'summary': """
Generate a xlsx file with information on current state of subscription
request, cooperators and capital release request.
""",
'author': 'Houssine BAKKALI, <houssine@coopiteasy.be>',
'license': 'AGPL-3',
'version': '9.0.1.0',
'website': "www.coopiteasy.be",
'category': 'Cooperative Management',
'depends': [
'easy_my_coop',
],
'external_dependencies': {
'python': ['xlsxwriter'],
},
'data': [
# 'security/ir.model.access.csv',
'wizard/export_global_wizard.xml',
]
}

2
easy_my_coop_export_xlsx/wizard/__init__.py

@ -0,0 +1,2 @@
# -*- coding: utf8 -*-
from . import export_global_wizard

291
easy_my_coop_export_xlsx/wizard/export_global_wizard.py

@ -0,0 +1,291 @@
# -*- encoding: utf-8 -*-
from openerp import fields, models, api
import time
from cStringIO import StringIO
import base64
import xlsxwriter
HEADER = [
'Num. Coop',
'Numero de registre national',
'Nom',
'Email',
'Banque',
'Mobile',
'Adresse',
'Rue',
'Code Postal',
'Ville',
'Pays',
'Nombre de part total',
'Montant total des parts',
'Numero de demande',
'Statut',
'Demande de liberation de capital',
'Communication',
'Nombre de part',
'Montant',
'Reception du paiement',
'Date de la souscription'
]
HEADER2 = [
'Date de la souscription',
'Nom',
'Type',
'Nombre de part',
'Montant',
'Statut',
'Numero de registre national',
'Email',
'Mobile',
'Adresse',
'Code Postal',
'Ville',
'Pays',
]
class export_global_report(models.TransientModel):
_name = 'export.global.report'
name = fields.Char('Name')
def write_header(self, worksheet, headers):
i = 0
for header in headers:
worksheet.write(0, i, header)
i += 1
return True
@api.multi
def export_global_report_xlsx(self):
partner_obj = self.env['res.partner']
invoice_obj = self.env['account.invoice']
subscription_obj = self.env['subscription.request']
file_data = StringIO()
workbook = xlsxwriter.Workbook(file_data)
worksheet1 = workbook.add_worksheet()
self.write_header(worksheet1, HEADER)
cooperators = partner_obj.search([('cooperator', '=', True),
('member', '=', True)])
j = 1
for coop in cooperators:
i = 0
worksheet1.write(j, i, coop.cooperator_register_number)
i += 1
worksheet1.write(j, i, coop.national_register_number)
i += 1
worksheet1.write(j, i, coop.name)
i += 1
worksheet1.write(j, i, coop.email)
i += 1
acc_number = ""
if coop.bank_ids:
acc_number = coop.bank_ids[0].acc_number
worksheet1.write(j, i, acc_number)
i += 1
worksheet1.write(j, i, coop.phone)
i += 1
address = coop.street + ' ' + coop.zip + ' ' \
+ coop.city + ' ' + coop.country_id.name
worksheet1.write(j, i, address)
i += 1
worksheet1.write(j, i, coop.street)
i += 1
worksheet1.write(j, i, int(coop.zip))
i += 1
worksheet1.write(j, i, coop.city)
i += 1
worksheet1.write(j, i, coop.country_id.name)
i += 1
worksheet1.write(j, i, coop.number_of_share)
i += 1
worksheet1.write(j, i, coop.total_value)
invoice_ids = invoice_obj.search([('release_capital_request', '=', True),
('partner_id', '=', coop.id)])
j += 1
for invoice in invoice_ids:
i = 11
worksheet1.write(j, i, invoice.number)
i += 1
worksheet1.write(j, i, invoice.state)
i += 1
worksheet1.write(j, i, invoice.date_invoice)
i += 1
worksheet1.write(j, i, invoice.reference)
i += 1
for line in invoice.invoice_line_ids:
worksheet1.write(j, i, line.quantity)
i += 1
worksheet1.write(j, i, line.price_subtotal)
i += 1
if invoice.payment_ids:
worksheet1.write(j, i, invoice.payment_ids[0].date)
i += 1
if invoice.subscription_request:
ind = len(invoice.subscription_request)-1
worksheet1.write(j, i, invoice.subscription_request[ind].date)
j += 1
sub_requests = subscription_obj.search([('state', 'in',
['draft', 'waiting']),
('partner_id', '=', coop.id)
])
for sub_request in sub_requests:
i = 11
worksheet1.write(j, i, dict(subscription_obj._columns['type'].selection).get(sub_request.type,False))
i += 1
worksheet1.write(j, i, sub_request.state)
i += 3
quantity = int(sub_request.ordered_parts)
worksheet1.write(j, i, quantity)
i += 1
amount = quantity * 250
worksheet1.write(j, i, amount)
i += 2
worksheet1.write(j, i, sub_request.date)
j += 1
worksheet1bis = workbook.add_worksheet()
self.write_header(worksheet1bis, HEADER)
cooperators = partner_obj.search([('cooperator', '=', True),
('member', '=', False)])
j = 1
for coop in cooperators:
i = 0
worksheet1bis.write(j, i, coop.cooperator_register_number)
i += 1
worksheet1bis.write(j, i, coop.national_register_number)
i += 1
worksheet1bis.write(j, i, coop.name)
i += 1
worksheet1bis.write(j, i, coop.email)
i += 1
worksheet1bis.write(j, i, coop.phone)
i += 1
worksheet1bis.write(j, i, coop.street)
i += 1
worksheet1bis.write(j, i, int(coop.zip))
i += 1
worksheet1bis.write(j, i, coop.city)
i += 1
worksheet1bis.write(j, i, coop.country_id.name)
i += 1
worksheet1bis.write(j, i, coop.number_of_share)
i += 1
worksheet1bis.write(j, i, coop.total_value)
invoice_ids = invoice_obj.search([('release_capital_request', '=', True),
('partner_id', '=', coop.id)])
j += 1
for invoice in invoice_ids:
i = 11
worksheet1bis.write(j, i, invoice.number)
i += 1
worksheet1bis.write(j, i, invoice.state)
i += 1
worksheet1bis.write(j, i, invoice.date_invoice)
i += 1
worksheet1bis.write(j, i, invoice.reference)
i += 1
for line in invoice.invoice_line_ids:
worksheet1bis.write(j, i, line.quantity)
i += 1
worksheet1bis.write(j, i, line.price_subtotal)
i += 1
if invoice.payment_ids:
worksheet1bis.write(j, i, invoice.payment_ids[0].date)
i += 1
if invoice.subscription_request:
ind = len(invoice.subscription_request)-1
worksheet1bis.write(j, i, invoice.subscription_request[ind].date)
j += 1
sub_requests = subscription_obj.search([('state', 'in',
['draft', 'waiting']),
('partner_id', '=', coop.id)
])
for sub_request in sub_requests:
i = 11
worksheet1bis.write(j, i, dict(subscription_obj._columns['type'].selection).get(sub_request.type,False))
i += 1
worksheet1bis.write(j, i, sub_request.state)
i += 3
quantity = int(sub_request.ordered_parts)
worksheet1bis.write(j, i, quantity)
i += 1
amount = quantity * 250
worksheet1bis.write(j, i, amount)
i += 2
worksheet1bis.write(j, i, sub_request.sync_date)
j += 1
worksheet2 = workbook.add_worksheet()
self.write_header(worksheet2, HEADER2)
sub_requests = subscription_obj.search([('state', 'in',
['draft', 'waiting']),
])
j = 1
for sub_request in sub_requests:
i = 0
worksheet2.write(j, i, sub_request.date)
i += 1
worksheet2.write(j, i, sub_request.name)
i += 1
sub_type_sel = subscription_obj._columns['type'].selection
worksheet2.write(j, i, dict(sub_type_sel).get(sub_request.type, False))
i += 1
quantity = int(sub_request.ordered_parts)
worksheet2.write(j, i, quantity)
i += 1
amount = quantity * 250
worksheet2.write(j, i, amount)
i += 1
worksheet2.write(j, i, sub_request.state)
i += 1
worksheet2.write(j, i, sub_request.no_registre)
i += 1
worksheet2.write(j, i, sub_request.email)
i += 1
worksheet2.write(j, i, sub_request.phone)
i += 1
worksheet2.write(j, i, sub_request.address)
i += 1
worksheet2.write(j, i, sub_request.city)
i += 1
worksheet2.write(j, i, int(sub_request.zip_code))
i += 1
worksheet2.write(j, i, sub_request.country_id.name)
j += 1
workbook.close()
file_data.seek(0)
data = base64.encodestring(file_data.read())
attachment_id = self.env['ir.attachment'].create({
'name': "Global export" + time.strftime('%Y-%m-%d %H:%M')
+ ".xlsx",
'datas': data,
'datas_fname': 'Global_export.xlsx',
'res_model': 'export.global.report',
},)
# Prepare your download URL
download_url = '/web/content/' + str(attachment_id.id) + '?download=True'
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
return {
"type": "ir.actions.act_url",
"url": str(base_url) + str(download_url),
"target": "new",
}

33
easy_my_coop_export_xlsx/wizard/export_global_wizard.xml

@ -0,0 +1,33 @@
<?xml version="1.0" ?>
<openerp>
<data>
<record id="view_export_global_report_wizard" model="ir.ui.view">
<field name="name">export.global.report.wizard.form</field>
<field name="model">export.global.report</field>
<field name="arch" type="xml">
<form string="Reporting" version="7.0">
<separator string="Global report export"/>
<footer>
<button name="export_global_report_xlsx" string="Export" type="object" default_focus="1" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_export_global_report_wizard" model="ir.actions.act_window">
<field name="name">Export gloabal report</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">export.global.report</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_export_global_report_wizard"/>
<field name="target">new</field>
<field name="multi">True</field>
</record>
<menuitem id="menu_export_global_report_wizard" name="Global report export" parent="easy_my_coop.menu_easy_my_coop_main_reporting" action="action_export_global_report_wizard" sequence="10"/>
</data>
</openerp>
Loading…
Cancel
Save