fix_views_14_extended/account.move-agofer_invoice_format.py

110 lines
3.3 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Modifica el formato QWeb de facturas y devoluciones."""
import os
import sys
import base64
import odooly
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 main():
odooly.Client._config_file = os.path.expanduser('~/.config/odooly.ini')
odoo = odooly.Client.from_config('Odoo14_Production')
#odoo = odooly.Client.from_config('odootest27')
"""Desactivar manualmente la vista:
* sale_stock.report_invoice_document_inherit_sale_stock
"""
views = odoo.env['ir.ui.view']
baseid = 'account.report_invoice_document'
viewname = 'report.invoice.factura_o_devolucion_agofer'
viewextid = 'agofer_view.factura_o_devolucion'
reports = odoo.env['ir.actions.report']
repextid = 'account.account_invoices'
papers = odoo.env['report.paperformat']
papextid = 'agofer_paper.factura_carta'
papextid_base = 'base.paperformat_us'
attachments = odoo.env['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-pdf',
}
papvalues = {
'name': 'Tamaño carta para factura',
'dpi': 90,
'format': 'Letter',
'header_line': False,
'header_spacing': 33,
'margin_bottom': 27,
'margin_left': 7,
'margin_right': 7,
'margin_top': 43,
'orientation': 'Portrait',
'page_height': 0,
'page_width': 0,
}
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.env['res.document.type'].get(cc_extid).name = 'CC'
reports.get(repextid).write(repvalues)
if __name__ == "__main__":
use_local_resources()
main()