Refactorizar generación de PDF

This commit is contained in:
Mauricio Baeza 2018-01-27 02:45:45 -06:00
parent cd8bd1ceeb
commit 776c90a467
4 changed files with 54 additions and 11 deletions

View File

@ -760,8 +760,29 @@ class LIBO(object):
self._sheet.copyRange(nc.getCellAddress(), source.getRangeAddress())
return
def _copy_paste_rows(self, cell, count):
dispatch = self._create_instance('com.sun.star.frame.DispatchHelper')
row = cell.getCellAddress().Row
source = self._sheet.getRows().getByIndex(row)
self._template.getCurrentController().select(source)
frame = self._template.getCurrentController().getFrame()
dispatch.executeDispatch(frame, '.uno:Copy', '', 0, ())
target = self._sheet.getCellRangeByPosition(0, row + 1, 0, row + count)
self._template.getCurrentController().select(target)
dispatch.executeDispatch(frame, '.uno:Paste', '', 0, ())
return
def _conceptos(self, data):
first = True
col1 = []
col2 = []
col3 = []
col4 = []
col5 = []
col6 = []
count = len(data)-1
for concepto in data:
key = concepto.get('noidentificacion', '')
description = concepto['descripcion']
@ -779,16 +800,36 @@ class LIBO(object):
cell_6 = self._set_cell('{importe}', importe, value=True)
if len(data) > 1:
row = cell_1.getCellAddress().Row + 1
self._sheet.getRows().insertByIndex(row, len(data)-1)
self._sheet.getRows().insertByIndex(row, count)
self._copy_paste_rows(cell_1, count)
row = cell_1.getCellAddress().Row
else:
self._copy_row(cell_1)
cell_1 = self._set_cell(v=key, cell=cell_1)
cell_2 = self._set_cell(v=description, cell=cell_2)
cell_3 = self._set_cell(v=unidad, cell=cell_3)
cell_4 = self._set_cell(v=cantidad, cell=cell_4, value=True)
cell_5 = self._set_cell(v=valor_unitario, cell=cell_5, value=True)
cell_6 = self._set_cell(v=importe, cell=cell_6, value=True)
col1.append((key,))
col2.append((description,))
col3.append((unidad,))
col4.append((float(cantidad),))
col5.append((float(valor_unitario),))
col6.append((float(importe),))
col = cell_1.getCellAddress().Column
target1 = self._sheet.getCellRangeByPosition(col, row+1, col, row+count)
col = cell_2.getCellAddress().Column
target2 = self._sheet.getCellRangeByPosition(col, row+1, col, row+count)
col = cell_3.getCellAddress().Column
target3 = self._sheet.getCellRangeByPosition(col, row+1, col, row+count)
col = cell_4.getCellAddress().Column
target4 = self._sheet.getCellRangeByPosition(col, row+1, col, row+count)
col = cell_5.getCellAddress().Column
target5 = self._sheet.getCellRangeByPosition(col, row+1, col, row+count)
col = cell_6.getCellAddress().Column
target6 = self._sheet.getCellRangeByPosition(col, row+1, col, row+count)
target1.setFormulaArray(tuple(col1))
target2.setDataArray(tuple(col2))
target3.setFormulaArray(tuple(col3))
target4.setDataArray(tuple(col4))
target5.setDataArray(tuple(col5))
target6.setDataArray(tuple(col6))
return
def _add_totales(self, data):

View File

@ -1592,7 +1592,8 @@ function generate_pdf(id){
function grid_preinvoices_click(id, e, node){
if(id.column == 'pdf'){
generate_pdf(id.row)
//~ generate_pdf(id.row)
window.open('/doc/pre/' + id, '_blank')
}else if(id.column == 'email'){
enviar_prefactura(id)
}

View File

@ -209,9 +209,10 @@ var multi_products = {
var app_products = {
id: "app_products",
id: 'app_products',
rows:[
{view: "template", id: "th_products", type: "header", template:"Administración de Productos" },
{view: 'template', id: 'th_products', type: 'header',
template: 'Administración de Productos y Servicios'},
multi_products
],
}