diff --git a/cor_custom/controllers/controllers.py b/cor_custom/controllers/controllers.py index a8a213a..c07c902 100755 --- a/cor_custom/controllers/controllers.py +++ b/cor_custom/controllers/controllers.py @@ -1,21 +1,34 @@ # -*- coding: utf-8 -*- -# from odoo import http +import io +from odoo.tools import image_process, topological_sort, html_escape, pycompat, ustr, apply_inheritance_specs, lazy_property, float_repr +from odoo.addons.web.controllers.main import ExportXlsxWriter, ExportFormat, ExcelExport +from odoo.exceptions import AccessError, UserError, AccessDenied +from odoo.tools.translate import _ +from odoo.tools.misc import str2bool, xlsxwriter, file_open +from odoo import api, http, SUPERUSER_ID, _ +from odoo.tests import common, tagged -# class CorCustom(http.Controller): -# @http.route('/cor_custom/cor_custom/', auth='public') -# def index(self, **kw): -# return "Hello, world" +class CustomExportXlsxWriter(ExportXlsxWriter): #http.Controller + + def __custom_init__(self, field_names, row_count=0): + self.field_names = field_names + self.output = io.BytesIO() + self.workbook = xlsxwriter.Workbook(self.output, {'in_memory': True}) + self.base_style = self.workbook.add_format({'text_wrap': True}) + self.header_style = self.workbook.add_format({'bold': True}) + self.header_bold_style = self.workbook.add_format({'text_wrap': True, 'bold': True, 'bg_color': '#e9ecef'}) + self.date_style = self.workbook.add_format({'text_wrap': True, 'num_format': 'dd/mm/yyyy'}) + self.datetime_style = self.workbook.add_format({'text_wrap': True, 'num_format': 'dd/mm/yyyy hh:mm:ss'}) + self.worksheet = self.workbook.add_worksheet() + self.value = False + + if row_count > self.worksheet.xls_rowmax: + raise UserError( + _('There are too many rows (%s rows, limit: %s) to export as Excel 2007-2013 (.xlsx) format. Consider splitting the export.') % ( + row_count, self.worksheet.xls_rowmax)) + + + ExportXlsxWriter.__init__ = __custom_init__ -# @http.route('/cor_custom/cor_custom/objects/', auth='public') -# def list(self, **kw): -# return http.request.render('cor_custom.listing', { -# 'root': '/cor_custom/cor_custom', -# 'objects': http.request.env['cor_custom.cor_custom'].search([]), -# }) -# @http.route('/cor_custom/cor_custom/objects//', auth='public') -# def object(self, obj, **kw): -# return http.request.render('cor_custom.object', { -# 'object': obj -# }) diff --git a/cor_custom/views/project_view.xml b/cor_custom/views/project_view.xml index 2f3713f..90f1eb4 100755 --- a/cor_custom/views/project_view.xml +++ b/cor_custom/views/project_view.xml @@ -6,6 +6,12 @@ project.project + +
+
+