Browse Source

Impresión de pagaré para Imperio

sebas 3 years ago
commit
b8f456d570
10 changed files with 344 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 2 0
      __init__.py
  3. 22 0
      __openerp__.py
  4. 113 0
      models.py
  5. BIN
      static/description/icon.png
  6. 4 0
      static/src/css/style.css
  7. 166 0
      static/src/js/main.js
  8. 8 0
      static/src/xml/main.xml
  9. 18 0
      views/account_invoice_view.xml
  10. 10 0
      views/template.xml

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+import models

+ 22 - 0
__openerp__.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+{
+    'name' : 'Impresion de pagare Imperio',
+    'version' : '1.0',
+    'description' : """
+Este módulo Permite realizar impresión del pagare del Imperio
+    """,
+    'author' : 'Eiru',
+    'category' : 'Service',
+    'depends' : [
+        'account',
+        'eiru_num2word',
+        'partner_extra_data_crifin',
+    ],
+    'data' : [
+        'views/template.xml',
+        'views/account_invoice_view.xml'
+    ],
+    'qweb' : ['static/src/xml/*.xml',],
+    'installable' : True,
+    'auto_install' : False,
+}

+ 113 - 0
models.py

@@ -0,0 +1,113 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api
+
+class AccountInvoice(models.Model):
+	_inherit = 'account.invoice'
+
+	@api.model
+	def getAccountInvoicePagare(self,domain):
+		AccountInvoice = self.env['account.invoice'].search(domain)
+		values = []
+		for invoice in AccountInvoice:
+			values.append({
+                # ID
+				'id': invoice.id,
+                'number': invoice.number,
+                'origin': invoice.origin,
+                'date_invoice': invoice.date_invoice or "",
+                'user_name': invoice.user_id.name,
+                'amount_untaxed': invoice.amount_untaxed,
+                'amount_tax': invoice.amount_untaxed,
+                'amount_total': invoice.amount_total,
+				'date_due': invoice.date_due or "",
+
+                # PARTNER INFO
+				'partner_id':[{
+					'id': invoice.partner_id.id,
+					'name': invoice.partner_id.name or "",
+					'ruc': invoice.partner_id.ruc or "",
+					'address': invoice.partner_id.street or "",
+					'city': invoice.partner_id.city or "",
+					'barrio': invoice.partner_id.street2 or "",
+					'email': invoice.partner_id.email,
+					'estado_civil': invoice.partner_id.estado_civil or "",
+	                'phone': invoice.partner_id.phone,
+	                'mobile': invoice.partner_id.mobile,
+					'name_deudor': invoice.partner_id.name_deudor or "",
+					'cin_deudor': invoice.partner_id.cin_deudor or "",
+					'tel_deudor': invoice.partner_id.tel_deudor or "",
+					'dir_deudor': invoice.partner_id.dir_deudor or "",
+				}],
+                # COMPANY INFO
+				'company_id': [{
+					'id':invoice.user_id.company_id.id,
+	                'name': invoice.user_id.company_id.name,
+	                'logo': invoice.user_id.company_id.logo,
+	                'phone': invoice.user_id.company_id.phone,
+				}],
+				# CURRENCY INFO
+				'currency_id':[{
+					'id': invoice.currency_id.id,
+					'name': invoice.currency_id.name,
+					'symbol': invoice.currency_id.symbol,
+					'thousands_separator': invoice.currency_id.thousands_separator,
+					'decimal_separator': invoice.currency_id.decimal_separator,
+					'decimal_places': invoice.currency_id.decimal_places,
+					'symbol_position': invoice.currency_id.symbol,
+				}],
+			})
+
+		return values
+
+	# @api.model
+	# def getAccountInvoicePagareQuota(self,domain):
+	# 	AccountInvoice = self.env['account.invoice'].search(domain)
+	# 	AccountMoveLine = self.env['account.move.line'].search([('move_id','=',AccountInvoice.number),('debit','>',0),('date_maturity','!=', False)],order='date_maturity')
+	#
+	# 	i = 1
+	# 	x = len(AccountMoveLine)
+	# 	values = []
+	#
+	# 	for line in AccountMoveLine:
+	# 		amount = 0
+	# 		value = 0
+	# 		state = 'No pagado'
+	# 		if(line.reconcile_ref != False):
+	# 			if(line.amount_residual == 0):
+	# 				state = 'Pagado'
+	#
+	# 			if(line.amount_residual > 0):
+	# 				value = line.debit - line.amount_residual
+	# 				state = 'Amortizado'
+	#
+	# 		values.append({
+	# 			'date': line.date_maturity,
+	# 			'name': 'Cuota ' + str(i) + ' / ' + str(x),
+	# 			'state': state,
+	# 			'value': value,
+	# 			'amount': line.debit,
+	# 			'residual': line.amount_residual,
+	# 			'tot_cuota': str(x),
+	# 		})
+	# 		i = i + 1
+	#
+	# 	return values
+
+class AccountInvoiceLine(models.Model):
+	_inherit = 'account.invoice.line'
+
+	@api.model
+	def getAccountInvoiceLinePagare(self,domain):
+		AccountInvoiceLine = self.env['account.invoice.line'].search(domain)
+		values = []
+		for line in AccountInvoiceLine:
+			values.append({
+				'id': line.id,
+                'name': line.name,
+                'quantity': line.quantity,
+                'price_unit': line.price_unit,
+                'price_subtotal': line.price_subtotal,
+			})
+
+		return values

BIN
static/description/icon.png


+ 4 - 0
static/src/css/style.css

@@ -0,0 +1,4 @@
+.pagare_button_box {
+    width: auto;
+    float: left;
+}

+ 166 - 0
static/src/js/main.js

@@ -0,0 +1,166 @@
+openerp.pagare_imperio = function (instance, local) {
+    local.widgetInstance = null;
+    local.parentInstance = null;
+
+    local.PagareImperioWidget = instance.Widget.extend({
+        template : "pagare_imperio.PagareImperio",
+        jsonDoc:[],
+
+        init:function(parent){
+            this._super(parent);
+        },
+
+        updateId : function(id){
+            var self = this;
+            self.id=id;
+        },
+
+        start: function () {
+            var self = this;
+            this.$el.click(function (e) {
+                self.fecthInitial();
+            });
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                if(dato == true && typeof dato == 'boolean'){
+                    valor=" ";
+                }else{
+                    valor=dato;
+                }
+            }
+            return valor;
+        },
+
+        fecthInitial: function(){
+            var id= openerp.webclient._current_state.id;
+            var self = this;
+            self.fetchAccountInvoice(id).then(function(AccountInvoice){
+                return AccountInvoice;
+            }).then(function(AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchAccountInvoiceLine();
+            }).then(function(AccountInvoiceLine){
+                self.AccountInvoiceLine = AccountInvoiceLine;
+                return self.drawPDF();
+            });
+            return false;
+        },
+
+        fetchAccountInvoice: function(id){
+            var domain=[['id','=', id]];
+            var AccountInvoice = new instance.web.Model('account.invoice');
+            return AccountInvoice.call('getAccountInvoicePagare',[domain], {
+                context: new instance.web.CompoundContext()
+            });
+        },
+
+        fetchAccountInvoiceLine: function () {
+            var self = this;
+            var invoice_ids = _.flatten(_.map(self.AccountInvoice,function(map){
+                return map.id;
+            }));
+            var domain=[['invoice_id','in',invoice_ids]];
+            var AccountInvoiceLine = new instance.web.Model('account.invoice.line');
+            return AccountInvoiceLine.call('getAccountInvoiceLinePagare',[domain], {
+                context: new instance.web.CompoundContext()
+            });
+        },
+
+        drawPDF:function(){
+            var self = this;
+            var AccountInvoice = self.AccountInvoice;
+            var CurrencyBase = self.AccountInvoice[0].currency_id[0];
+            var docItem = [];
+            var docQuotaItem = [];
+            var getColumns = [];
+            var getColumnsQuota = [];
+
+            var pdfDoc = new jsPDF("p","mm","a4");
+
+
+            pdfDoc.addImage("data:image/png;base64," + AccountInvoice[0].company_id[0].logo, 'png', 10, 10, 50, 30);
+            pdfDoc.setFontSize(16);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text(80,25,'PAGARE A LA ORDEN');
+
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.rect(10, 45, 95, 7, 'S');
+            pdfDoc.text(12,50,'Número de Operación: ' + AccountInvoice[0].origin);
+            pdfDoc.rect(105, 45, 95, 7, 'S');
+            pdfDoc.text(110,50,'Fecha de Operación: ' + moment(AccountInvoice[0].date_invoice).format('DD/MM/YYYY'));
+            pdfDoc.rect(10, 55, 95, 7, 'S');
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(12,60,'Monto a pagar: ' + accounting.formatMoney(AccountInvoice[0].amount_total,CurrencyBase.symbol,CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator));
+            pdfDoc.rect(105, 55, 95, 7, 'S');
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('normal');
+            // _.each(self.AccountInvoiceQuota, function(item){
+            //     varfecha=item.date;
+            // });
+            pdfDoc.text(110,60,'Vencimiento: ' + moment(AccountInvoice[0].date_due).format('DD/MM/YYYY'));
+            var total_in_letters = instance.web.num2word(AccountInvoice[0].amount_total);
+            pdfDoc.rect(10, 65, pdfDoc.internal.pageSize.getWidth() - 15 , 16,'S');
+            pdfDoc.setFontSize(11);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(12,70,'Pagaré a la orden de la empresa FERRETERIA IMPERIO.');
+            pdfDoc.setFontSize(10.5);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(12,75,'La suma de Guaraníes: ' );
+            pdfDoc.setFontSize(10.5);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(12,79, total_in_letters);
+            pdfDoc.rect(10, 81, pdfDoc.internal.pageSize.getWidth() - 15 , 60,'S');
+            pdfDoc.setFontSize(11);
+            pdfDoc.setFontStyle('normal');
+            var paragraph="Por igual valor recibido en _______________________ a mi (nuestra) entera satisfacción. Queda expresamente convenido que la falta de pago de este pagaré me (nos) constituirá en mora automáticamente, sin necesidad de interpelación judicial o extrajudicial alguna, devengando durante el tiempo de la mora un interés moratorio del 3 % mensual por el simple retardo sin que esto implique prórroga del plazo de la obligación. Asimismo me (nos) obligamos a pagar cualquier gasto en que incurra el acreedor con relación a este préstamo, en caso de que el mismo sea reclamado por la vía judicial o extrajudicial. El simple vencimiento establecerá mora, autorizando la inclusión de nombre personal o Razón Social que represento, a la base de datos de Informconf y/o Equifax Paraguay S.A., conforme a lo establecido en la Ley 1682/2001 y su modificatoria 1969/2002, como también para que se pueda proveer la información a terceros interesados. A los efectos legales y procesales nos sometemos a la jurisdicción de los Tribunales de Salto de Guairá y renunciando a cualquier otra que pudiera corresponder las partes constituyen domicilio real y especial en los lugares señalados en el presente documento.";
+            pdfDoc.text(paragraph,12,87,{maxWidth:188,align:'justify'});
+
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text(10,165,'DEUDOR');
+            pdfDoc.text(120,165,'CO-DEUDOR');
+
+            pdfDoc.setFontSize(9);
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(40);
+            pdfDoc.text(10,175,'Nombre y Apellido: ' + AccountInvoice[0].partner_id[0].name);
+            pdfDoc.text(120,175,'Nombre y Apellido:' + AccountInvoice[0].partner_id[0].name_deudor);
+            pdfDoc.text(10,180,'RUC / DNI: ' + self.valorNull(AccountInvoice[0].partner_id[0].ruc));
+            pdfDoc.text(120,180,'RUC / DNI:' + AccountInvoice[0].partner_id[0].cin_deudor);
+            pdfDoc.text(10,185,'Domicilio: ' + self.valorNull(AccountInvoice[0].partner_id[0].address));
+            pdfDoc.text(120,185,'Domicilio:' + AccountInvoice[0].partner_id[0].dir_deudor);
+            pdfDoc.text(10,195,'Telefono: ' + self.valorNull(AccountInvoice[0].partner_id[0].phone));
+            pdfDoc.text(120,195,'Telefono:');
+            pdfDoc.text(10,200,'Celular: ' + self.valorNull(AccountInvoice[0].partner_id[0].mobile));
+            pdfDoc.text(120,200,'Celular:' + AccountInvoice[0].partner_id[0].tel_deudor);
+            pdfDoc.text(10,210,'Firma: ');
+            pdfDoc.text(120,210,'Firma:');
+
+            pdfDoc.save('pagare.pdf');
+        },
+    });
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_form: function (record) {
+                this._super.apply(this, arguments);
+                if (this.model !== 'account.invoice') return;
+                local.parentInstance = this;
+                if (local.widgetInstance) {
+                    local.widgetInstance.updateId(record.id);
+                }
+                local.widgetInstance = new local.PagareImperioWidget(this);
+                var elemento = this.$el.find('.oe_form').find('.pagare_button_box');
+                local.widgetInstance.appendTo(elemento);
+                local.widgetInstance.updateId(record.id);
+            }
+        });
+    }
+};

+ 8 - 0
static/src/xml/main.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="pagare_imperio.PagareImperio">
+        <button class="print_pagare_imperio oe_button oe_form_button oe_highlight">
+            <div> Imprimir Pagare</div>
+        </button>
+    </t>
+</template>

+ 18 - 0
views/account_invoice_view.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record model="ir.ui.view" id="account_invoice_button">
+            <field name="name">account.invoice.button</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_form"/>
+            <field name="arch" type="xml">
+				<xpath expr="//button[@name='invoice_print']" position="replace">
+					<div class="pagare_button_box" attrs="{'invisible': [('state','not in',['open','paid'])]}"></div>
+				</xpath>
+				<xpath expr="//button[@name='action_invoice_sent']" position="attributes">
+					<attribute name="invisible">1</attribute>
+				</xpath>
+            </field>
+        </record>
+	</data>
+</openerp>

+ 10 - 0
views/template.xml

@@ -0,0 +1,10 @@
+<openerp>
+    <data>
+        <template id="pagare_imperio.assets_backend" name="pagare_imperio_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <link rel="stylesheet" href="/pagare_imperio/static/src/css/style.css"/>
+                <script type="text/javascript" src="/pagare_imperio/static/src/js/main.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>