#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Modificar todo el formato QWeb de un pedido de venta / cotización.""" import os import sys 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('odootest26') baseid = 'sale.report_saleorder_document' viewname = 'report.saleorder.cotizacion_o_pedido_agofer' viewextid = 'agofer_view.cotizacion_o_pedido' viewmodel = 'ir.ui.view' repmodel = 'ir.actions.report' repextid = 'sale.action_report_saleorder' papmodel = 'report.paperformat' papextid = 'agofer_paper.factura_carta' vista_base = odoo.env[viewmodel].get(baseid) assert vista_base.name == 'report_saleorder_document' reporte = open(os.path.join(__location__, 'pedido_o_cotizacion_agofer.xml')).read() formato_carta = odoo.env['report.paperformat'].get('report.paperformat_us') destino_arch = """ {1} """.format(baseid,reporte) viewvalues = { 'active': True, 'arch': destino_arch, 'inherit_id': vista_base.id, 'mode': 'extension', 'name': viewname, 'priority': 15, 'type': 'qweb', } repvalues = { 'name': 'Cotización / Pedido de Venta', 'attachment': False, 'attachment_use': False, 'report_type': 'qweb-html', } try: destino_vista = odoo.env[viewmodel].get(viewextid) if destino_vista: destino_vista.write(viewvalues) else: destino_vista = odoo.env[viewmodel].create(viewvalues) destino_vista._set_external_id(viewextid) paper = odoo.env[papmodel].get(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' odoo.env[repmodel].get(repextid).write(repvalues) except: xt, xc, tb = sys.exc_info() xm = ''.join(odooly.format_exception(xt, xc, tb, chain=False)) print('### Error\n' + (xm.strip())) if __name__ == "__main__": use_local_resources() main()