[DEL] Removes obsolete script

This commit is contained in:
Jorge Enrique Gómez Gómez 2022-04-05 22:54:51 -05:00
parent afe03ae962
commit 8823032a48

View File

@ -1,176 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Modifica el formato QWeb de facturas y devoluciones."""
import os
import sys
import base64
import erppeek
def stringifyImage(archivo):
"""Convierte archivo en el mismo directorio a una cadena en base64."""
with open(os.path.join(__location__, archivo), 'rb') as f:
img = base64.b64encode(f.read()).decode('ascii')
return img
def use_local_resources():
"""Facilita usar recursos en el mismo directorio del script."""
global __location__
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
def replace_extid(objeto, modelo, nuevo_extid):
"""Reemplaza el id externo de un objeto."""
if objeto._external_id == nuevo_extid:
return
id_extid = odoo.model('ir.model.data').get(
[('model', '=', modelo), ('res_id', '=', objeto.id)])
if id_extid:
try:
id_extid.unlink()
except:
xt, xc, tb = sys.exc_info()
xm = ''.join(erppeek.format_exception(xt, xc, tb, chain=False))
print('### Error\n' + (xm.strip()))
try:
objeto._set_external_id(nuevo_extid)
print('{} (#{}) -> {}'.format(objeto.name, objeto.id, nuevo_extid))
except:
xt, xc, tb = sys.exc_info()
xm = ''.join(erppeek.format_exception(xt, xc, tb, chain=False))
print('### Error\n' + (xm.strip()))
return
def main():
odoo = erppeek.Client.from_config('Odoo14_6c60')
context = {'lang':'es_CO'}
"""Por ahora, desactivar (manualmente)
account_extended.report_invoice_document_agofer.
"""
views = odoo.model('ir.ui.view')
baseid = 'account.report_invoice_document'
viewname = 'report.invoice.factura_o_devolucion_agofer'
viewextid = 'agofer_view.factura_o_devolucion'
reports = odoo.model('ir.actions.report')
repextid = 'account.account_invoices'
papers = odoo.model('report.paperformat')
papextid = 'agofer_paper.factura_carta'
papextid_base = 'base.paperformat_us'
attachments = odoo.model('ir.attachment')
attextid_ff = 'agofer_adjunto.firma_factura'
attextid_iw = 'agofer_adjunto.icono_whatsapp'
vista_base = views.get(baseid)
assert vista_base.name == 'report_invoice_document'
reporte = open(os.path.join(__location__,
'factura_o_devolucion_v14.xml')).read()
formato_carta = papers.get(papextid_base)
destino_arch = """<?xml version="1.0"?>
<data name="{}" inherit_id="{}">
<xpath expr="//t[@t-name='account.report_invoice_document']" position="replace">
{}
</xpath>
</data>
""".format(viewname,baseid,reporte)
viewvalues = {
'active': True,
'inherit_id': vista_base.id,
'mode': 'extension',
'name': viewname,
'priority': 15,
'type': 'qweb',
}
repvalues = {
'name': 'Factura/Devolución',
'attachment': False,
'attachment_use': False,
'report_type': 'qweb-html',
}
papvalues = {
'name': 'Tamaño carta para factura',
'dpi': 120,
'format': 'Letter',
'header_line': False,
'header_spacing': 33,
'margin_bottom': 17,
'margin_left': 7,
'margin_right': 7,
'margin_top': 43,
'orientation': 'Portrait',
'page_height': 0,
'page_width': 0,
}
attvalues_ff = {
'datas': stringifyImage('firma_factura.png'),
'store_fname': 'firma_factura.png',
'db_datas': False,
'description': False,
'index_content': 'image',
'mimetype': 'image/png',
'name': 'firma_factura.png',
'res_id': 0,
'res_model': 'ir.ui.view',
'type': 'binary',
}
attvalues_iw = {
'datas': stringifyImage('WhatsApp_Number.png'),
'store_fname': 'WhatsApp_Number.png',
'db_datas': False,
'description': False,
'index_content': 'image',
'mimetype': 'image/png',
'name': 'WhatsApp_Number.png',
'res_id': 0,
'res_model': 'ir.ui.view',
'type': 'binary',
}
adjunto_ff = attachments.get(attextid_ff)
if adjunto_ff:
adjunto_ff.write(attvalues_ff)
else:
adjunto_ff = attachments.create(attvalues_ff)
adjunto_ff._set_external_id(attextid_ff)
#destino_arch = destino_arch.replace('firmaurl', adjunto_ff.website_url)
viewvalues['arch'] = destino_arch
adjunto_iw = attachments.get(attextid_iw)
if adjunto_iw:
adjunto_iw.write(attvalues_iw)
else:
adjunto_iw = attachments.create(attvalues_iw)
adjunto_iw._set_external_id(attextid_iw)
viewvalues['arch'] = destino_arch
destino_vista = views.get(viewextid)
if destino_vista:
destino_vista.write(viewvalues)
else:
destino_vista = views.create(viewvalues)
destino_vista._set_external_id(viewextid)
paper = papers.get(papextid)
if paper:
paper.write(papvalues)
else:
paper = papers.create(papvalues)
paper._set_external_id(papextid)
repvalues['paperformat_id'] = paper.id
# Asegurarse que el nombre de la Cedula de Ciudadania este abreviado:
# cc_extid = 'partner_extended_co.partner_co_document_type_CC'
# odoo.model('res.document.type').get(cc_extid).name = 'CC'
reports.get(repextid).write(repvalues)
if __name__ == "__main__":
use_local_resources()
main()