Skip to content

Instantly share code, notes, and snippets.

Created March 7, 2018 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/e8cce44d3b59ce22ec9826c9e9f9de10 to your computer and use it in GitHub Desktop.
Save anonymous/e8cce44d3b59ce22ec9826c9e9f9de10 to your computer and use it in GitHub Desktop.
ReportPOS
# -*- coding: utf-8 -*-
import datetime
import cStringIO
import base64
import xlwt
from pytz import timezone
from odoo import models, fields, api
class InventoryExcelExtended(models.Model):
_name = "excel.extended"
excel_file = fields.Binary('Reporte Excel')
file_name = fields.Char('Excel File', size=64)
class ReportPosOrder(models.TransientModel):
_name = "report.pos.order.xls"
_description = u"Reporte ordenes pos xls"
date_from = fields.Datetime('Fecha Desde', readonly=False, required=True)
date_to = fields.Datetime('Fecha Hasta', readonly=False, required=True)
@api.multi
def print_excel_report(self):
filename = u'ReporteVentasPOS.xls'
workbook = xlwt.Workbook(encoding='utf-8', style_compression=2)
worksheet = workbook.add_sheet('Ventas POS')
style = xlwt.easyxf('font:height 200, bold True, name Arial; align: horiz center, vert center;borders: top medium,right medium,bottom medium,left medium')
style0 = xlwt.easyxf('font: name Times New Roman, color-index black, bold on')
fila = 5
for obj in self:
worksheet.write_merge(0, 2, 0, 17, str(self.env.user.company_id.name), style)
worksheet.write(3, 8, str(datetime.datetime.now(timezone('America/Guayaquil'))), style0)
worksheet.write(4, 6, obj.date_from + "-" + obj.date_to, style0)
order = self.env['pos.order'].search([
('date_order', '>=', obj.date_from),
('date_order', '<=', obj.date_to),
])
journals_pos = self.env['account.journal'].search([
('journal_user', '=', True),
])
fila = fila + 1
if order:
worksheet.write(fila, 0, 'Sesión', style0)
worksheet.write(fila, 1, 'Num Orden', style0)
worksheet.write(fila, 2, 'Num. Factura', style0)
worksheet.write(fila, 3, 'Fecha', style0)
worksheet.write(fila, 4, 'Vendedor', style0)
worksheet.write(fila, 5, 'Punto de Venta', style0)
worksheet.write(fila, 6, 'Ced/RUC Cliente', style0)
worksheet.write(fila, 7, 'Cliente', style0)
worksheet.write(fila, 8, 'Base 12%', style0)
worksheet.write(fila, 9, 'Base 0%', style0)
worksheet.write(fila, 10, 'Impuesto', style0)
worksheet.write(fila, 11, 'Retención', style0)
worksheet.write(fila, 12, 'Total', style0)
cfp = 13
for journals in journals_pos:
worksheet.write(fila, cfp, journals.name, style0)
cfp = cfp + 1
for op in order:
fila = fila + 1
worksheet.write(fila, 0, op.session_id.name, style0)
worksheet.write(fila, 1, op.name, style0)
worksheet.write(fila, 2, op.invoice_number, style0)
worksheet.write(fila, 3, op.date_order, style0)
worksheet.write(fila, 4, op.user_id.name, style0)
worksheet.write(fila, 5, op.sale_journal.name, style0)
worksheet.write(fila, 6, op.partner_id.identifier, style0)
worksheet.write(fila, 7, op.partner_id.name, style0)
worksheet.write(fila, 8, op.invoice_id.amount_vat, style0)
worksheet.write(fila, 9, op.invoice_id.amount_vat_cero, style0)
worksheet.write(fila, 10, op.invoice_id.amount_tax, style0)
worksheet.write(fila, 11, op.invoice_id.amount_tax_retention, style0)
worksheet.write(fila, 12, op.invoice_id.amount_total, style0)
caux = 13
for jou_aux in journals_pos:
for jop in op.statement_ids:
if jou_aux.id == jop.journal_id.id:
worksheet.write(fila, caux, jop.amount, style0)
caux = caux + 1
fp = cStringIO.StringIO()
workbook.save(fp)
dataxls = {
'excel_file': base64.encodestring(fp.getvalue()),
'file_name': filename
}
export_id = self.env['excel.extended'].create(dataxls)
fp.close()
return{
'view_mode': 'form',
'res_id': export_id.id,
'res_model': 'excel.extended',
'view_type': 'form',
'type': 'ir.actions.act_window',
'context': None,
'target': 'new',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment