Procházet zdrojové kódy

[ADD] Impresión de estado de cuenta de Cliente por factura

adrielso před 5 roky
rodič
revize
71baa01f18
5 změnil soubory, kde provedl 307 přidání a 59 odebrání
  1. binární
      model/__init__.pyc
  2. 62 25
      model/account.py
  3. binární
      model/account.pyc
  4. 238 30
      static/src/js/main.js
  5. 7 4
      static/src/xml/view.xml

binární
model/__init__.pyc


+ 62 - 25
model/account.py

@@ -6,40 +6,77 @@ class AccountInvoice(models.Model):
 	_inherit = 'account.invoice'
 
 	@api.model
-	def getAccountInvoiceQuoteAnalysis(self,domain):
-		AccountInvoice = self.env['account.invoice'].search(domain)
-		AccountMoveLine = self.env['account.move.line'].search([('move_id','=',AccountInvoice.number),('debit','>',0)],order='date_maturity')
-		# i = len(AccountMoveLine)
-		i = 1
-		x = len(AccountMoveLine)
+	def getAccountInvoiceQuoteAnalysis(self,idInvoice):
 		values = []
-		# futbolistasTup.sort(key=lambda futbolista: futbolista[0])
-		# AccountMoveLine.sort(key=lambda futbolista: date_maturity)
-		# import web_pdb; web_pdb.set_trace()
-		for line in AccountMoveLine:
-			amount = 0
-			value = 0
+		''' Account Invoice '''
+		invoice = self.env['account.invoice'].browse(idInvoice)
+		if (not invoice):
+			return False
+
+		''' Move line'''
+		moveLines = self.env['account.move.line'].search([('invoice','=',invoice.id),('debit','>',0)], order='date_maturity')
+
+		quotaCont = 0
+		for moveLine in moveLines:
+			quotaCont += 1
+
 			state = 'No pagado'
-			if(line.reconcile_ref != False):
-				if(line.amount_residual == 0):
-					state = 'Pagado'
+			if(moveLine.reconcile_ref and moveLine.amount_residual == 0):
+				state = 'Pagado'
+			elif (moveLine.reconcile_ref and moveLine.amount_residual > 0):
+				state = 'Amortizado'
 
-				if(line.amount_residual > 0):
-					value = line.debit - line.amount_residual
-					state = 'Amortizado'
+			interest = self.env['account.interest.line'].browse(moveLine.interest_line_ids.id)
 
 			values.append({
-				'date': line.date_maturity,
-				'name': 'Cuota ' + str(i) + ' / ' + str(x),
-				'state': state,
-				'value': value,
-				'amount': line.debit,
-				'residual': line.amount_residual,
+				'dateMaturity' : moveLine.date_maturity,
+				'quotaNumber' : "%s/%s" %(quotaCont, len(moveLines)),
+				'amountQuota' : moveLine.debit,
+				'amountResidual' : moveLine.amount_residual,
+				'expiredDays' : interest.expired_days if(interest) else 0,
+				'amountInterest' : interest.amount_interest if(interest and interest.state == 'open') else 0,
+				'amountTotal' : (moveLine.amount_residual + interest.amount_interest) if(interest and interest.state == 'open') else moveLine.amount_residual,
+				'state' : state,
+				'value': moveLine.debit - moveLine.amount_residual,
 			})
-			i = i + 1
 
 		return values
 
+	@api.model
+	def getInvoiceAccountStatemnete(self, invoiceId):
+		return [{
+			'id': invoice.id,
+			'number': invoice.number,
+			'partner': {
+				'id' : invoice.partner_id.id,
+				'name' : invoice.partner_id.name,
+				'ruc' : invoice.partner_id.ruc or '',
+			},
+			'amountTotal': invoice.amount_total,
+			'amountResidual': invoice.residual,
+			'currency': {
+	            'thousandsSeparator': invoice.currency_id.thousands_separator,
+	            'decimalPlaces': invoice.currency_id.decimal_places,
+	            'decimalSeparator': invoice.currency_id.decimal_separator,
+	            'name': invoice.currency_id.local_name,
+	            'symbol ':invoice.currency_id.symbol,
+	        },
+			'company':{
+				'id': invoice.company_id.id,
+				'name': invoice.company_id.name,
+				'currencyCompany':{
+					'thousandsSeparator': invoice.company_id.currency_id.thousands_separator,
+ 	            	'decimalPlaces': invoice.company_id.currency_id.decimal_places,
+ 	            	'decimalSeparator': invoice.company_id.currency_id.decimal_separator,
+ 	            	'name': invoice.company_id.currency_id.local_name,
+ 	            	'symbol ':invoice.company_id.currency_id.symbol,
+				},
+				'logo': invoice.company_id.logo,
+			},
+
+
+		} for invoice in self.env['account.invoice'].browse(invoiceId)]
+
 class ResCurrrency(models.Model):
 	_inherit = 'res.currency'
 

binární
model/account.pyc


+ 238 - 30
static/src/js/main.js

@@ -2,10 +2,14 @@ openerp.eiru_quota_analysis = function (instance, local) {
     local.widgetInstance = null;
     local.parentInstance = null;
     var model = openerp;
+    var instanceWeb = openerp.web;
 
     local.EiruQuotaAnalysisWidget = instance.Widget.extend({
         template : "eiru_quota_analysis.EiruQuotaAnalysis",
         id: undefined,
+        AccountInvoice: [],
+        ResCurrency: [],
+        invoiceState : [],
 
         init: function(parent) {
             this._super(parent);
@@ -20,18 +24,10 @@ openerp.eiru_quota_analysis = function (instance, local) {
             /* Click Imprimir */
             bottomPrint = this.$el.find('.button-quota-print');
             bottomPrint.click(function(){
-                    console.log("Porrrra");
-            });
-        },
-        /*
-        start: function() {
-            var self = this;
-
-            this.$el.click(function(){
-                self.fectchInitial()
+                    self.initialPrint();
             });
             self.buttons.click(function(e) {
-                E (Editar)
+                // E (Editar)
                 if (e.target.accessKey === 'E')
                     self.$el.css('display','none');
                 // S (Guarrdar)
@@ -45,14 +41,7 @@ openerp.eiru_quota_analysis = function (instance, local) {
                     self.$el.css('display','none');
             });
         },
-        */
 
-        /*
-        checkQuota: function(id) {
-            var self = this;
-            self.Initial();
-        },
-        */
        /* */
         updateId : function(id){
             var self = this;
@@ -73,16 +62,17 @@ openerp.eiru_quota_analysis = function (instance, local) {
             });
             return;
         },
+
+        /* GET Quota invoice */
         fetchAccountInvoice: function (){
             var self = this;
-            var domain = [
-                ['id','=',self.id],
-            ];
             var AccountInvoice = new model.web.Model('account.invoice');
-            return AccountInvoice.call('getAccountInvoiceQuoteAnalysis',[domain], {
+            return AccountInvoice.call('getAccountInvoiceQuoteAnalysis',[self.id], {
                 context: new model.web.CompoundContext()
             });
         },
+
+        /* CURRENCY */
         fetchResCurrency: function (){
             var self = this;
             var domain = [
@@ -93,6 +83,8 @@ openerp.eiru_quota_analysis = function (instance, local) {
                 context: new model.web.CompoundContext()
             });
         },
+
+        /* Generar Table */
         build: function(){
             var self = this;
             var data = [];
@@ -100,33 +92,249 @@ openerp.eiru_quota_analysis = function (instance, local) {
             var date = '';
             var CurrencyBase = self.ResCurrency[0];
             _.each(self.AccountInvoice, function(item){
+
                 if(item.state == 'Amortizado'){
                     state = item.state + ' ( ' + accounting.formatMoney(item.value, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator) + ' )';
                 }else{
                     state = item.state;
                 }
-                date = moment(item.date).format('DD/MM/YYYY');
+
+                date = moment(item.dateMaturity).format('DD/MM/YYYY');
                 if(item.state != 'Pagado'){
-                    if(item.date < moment().format('YYYY-MM-DD')){
-                        date = moment(item.date,'YYYY-MM-DD').format('DD/MM/YYYY') + ' (vencido) ';
+                    if(item.dateMaturity < moment().format('YYYY-MM-DD')){
+                        date = moment(item.dateMaturity,'YYYY-MM-DD').format('DD/MM/YYYY') + ' (vencido) ';
                     }
                 }
                 data.push({
-                    'date': date,
-                    'name': item.name,
-                    'state': state,
-                    'amount': accounting.formatMoney(item.amount, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
-                    'residual': accounting.formatMoney(item.residual, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    'dateMaturity': date,
+                    'quotaNumber': item.quotaNumber,
+                    'amountQuota': accounting.formatMoney(item.amountQuota, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    'amountResidual': accounting.formatMoney(item.amountResidual, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    'expiredDays': item.expiredDays,
+                    'amountInterest': accounting.formatMoney(item.amountInterest, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    'amountTotal': accounting.formatMoney(item.amountTotal, '', CurrencyBase.decimal_places, CurrencyBase.thousands_separator, CurrencyBase.decimal_separator),
+                    'state': state
                 });
             });
             self.loadTable(data);
         },
+
+        /* Load Table */
         loadTable:function(rowsTable){
             var self = this;
             self.rowsData = rowsTable;
             var table = $('#quota_table');
             table.bootstrapTable('load', rowsTable);
-        }
+        },
+
+
+        /*---------------------------
+        |        IMPRIMIR           |
+        --------------------------*/
+        /*INIT PRINT*/
+        initialPrint: function() {
+            var self = this;
+
+            self.fetchInvoiceState().then(function(invoiceState){
+                return invoiceState
+            }).then(function(invoiceState){
+                self.invoiceState = invoiceState
+                return self.printCustomerAccountStatement();
+            });
+        },
+        /* GET Quota invoice */
+        fetchInvoiceState: function (){
+            var self = this;
+            var invoice = new model.web.Model('account.invoice');
+            return invoice.call('getInvoiceAccountStatemnete',[self.id], {
+                context: new model.web.CompoundContext()
+            });
+        },
+        /* Get interets total */
+        getInterestLines: function() {
+            var self = this;
+            var total = 0;
+            _.each(self.AccountInvoice, function(item){
+                total += item.amountInterest;
+            });
+            return  total;
+        },
+        filterLineQuota: function(currency) {
+            self = this;
+            var data = [];
+
+            _.each(self.AccountInvoice, function(item){
+                //
+                var state = item.state;
+                if(item.state == 'Amortizado'){
+                    state = item.state + ' ('+instanceWeb.formatCurrency(item.value, currency)+' )';
+                }
+
+                date = moment(item.dateMaturity).format('DD/MM/YYYY');
+
+                if(item.state != 'Pagado') {
+                    if(item.dateMaturity < moment().format('YYYY-MM-DD')) {
+                        date = moment(item.dateMaturity,'YYYY-MM-DD').format('DD/MM/YYYY') +' (vencido)';
+                    }
+                }
+
+                data.push({
+                    'dateMaturity': date,
+                    'quotaNumber': item.quotaNumber,
+                    'amountQuota': instanceWeb.formatCurrency(item.amountQuota, currency),
+                    'amountResidual': instanceWeb.formatCurrency(item.amountResidual, currency),
+                    'expiredDays': item.expiredDays,
+                    'amountInterest': instanceWeb.formatCurrency(item.amountInterest, currency),
+                    'amountTotal': instanceWeb.formatCurrency(item.amountTotal, currency),
+                    'state': state
+                });
+            });
+            return data
+        },
+        /*PRINT*/
+        printCustomerAccountStatement: function() {
+            var self = this;
+            var pdfDoc = new jsPDF();
+            var y = 15;
+            var space = 7;
+            var invoice = self.invoiceState.shift();
+            var currency = invoice.currency;
+            console.log(currency.name);
+            var company = invoice.company;
+            var interest = self.getInterestLines();
+            var lineQuota  =self.filterLineQuota(currency);
+            var base64Img = 'data:image/png;base64,' + company.logo;
+
+            /********************
+            |       LOGO        |
+            ********************/
+            pdfDoc.addImage(base64Img, 'png', 7, 2, 0, 15);
+            /********************
+            |       FECHA       |
+            ********************/
+            pdfDoc.setFontSize(10);
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(40)
+            pdfDoc.text(pdfDoc.internal.pageSize.getWidth() - 35, 8, moment().format('DD/MM/YYYY'));
+            /********************
+            |       TITLE       |
+            ********************/
+            pdfDoc.setFontSize('18');
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(105,y, pdfDoc.splitTextToSize('Estado de cuenta' , 180) , null, null, 'center');
+            pdfDoc.setFontSize('12');
+            /************************
+            |       Clientes        |
+            ************************/
+            y += 10;
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(10,y,'Cliente :');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(28,y, invoice.partner.name);
+            /********************************
+            |           RUC                 |
+            ********************************/
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(110,y, 'RUC:');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(125, y,invoice.partner.ruc);
+            /************************
+            |       Factura         |
+            ************************/
+            y += space;
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(10,y, 'Factura :');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(30,y, invoice.number);
+            /********************
+            |       MONEDA      |
+            ********************/
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(110,y, 'Moneda:');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(130,y, currency.name);
+            /*****************************
+            |       Amount TOTAL         |
+            ****************************/
+            y += space;
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(10,y, 'Total Factura:');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(40, y, instanceWeb.formatCurrency(invoice.amountTotal, currency));
+            /********************************
+            |       Amount Residual         |
+            ********************************/
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(110,y, 'Residual:');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(231, 76, 60);
+            pdfDoc.text(132, y, instanceWeb.formatCurrency(invoice.amountResidual, currency));
+
+            /******************************
+            |       Amount Interes        |
+            ******************************/
+            y += space;
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.setTextColor(0, 0, 0);
+            pdfDoc.text(10,y, 'Interés Calculado:');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.text(50, y, instanceWeb.formatCurrency(interest, currency));
+            /*****************************************
+            |       Amount Residual +Interes         |
+            *****************************************/
+            pdfDoc.setFontStyle('bold');
+            pdfDoc.text(110,y, 'Residual + Interés:');
+            pdfDoc.setFontStyle('normal');
+            pdfDoc.setTextColor(231, 76, 60);
+            pdfDoc.text(150, y, instanceWeb.formatCurrency((invoice.amountResidual+interest), currency));
+
+            /*********************
+            |        Table       |
+            **********************/
+            var getColumns = [
+                {'title' : 'Vencimiento', 'dataKey' : 'dateMaturity'},
+                {'title' : 'Nº Cuota', 'dataKey' : 'quotaNumber'},
+                {'title' : 'Cuota', 'dataKey' : 'amountQuota'},
+                {'title' : 'Pendiente', 'dataKey' : 'amountResidual'},
+                {'title' : 'Días atrasado', 'dataKey' : 'expiredDays'},
+                {'title' : 'Interés', 'dataKey' : 'amountInterest'},
+                {'title' : 'Total', 'dataKey' : 'amountTotal'},
+                {'title' : 'Estado', 'dataKey' : 'state'},
+            ]
+            rowsPdf = lineQuota;
+
+            pdfDoc.autoTable(getColumns,rowsPdf, {
+                body: rowsPdf,
+                theme: 'grid',
+                startY: 50,
+                styles: {
+                    overflow: 'linebreak',
+                    columnWidth: 'auto',
+                    fontSize: 8,
+                },
+                columnStyles: {
+                    dateMaturity : {columnWidth: 25, halign:'center'},
+                    quotaNumber: {columnWidth: 20, halign:'center'},
+                    amountQuota: {halign:'right'},
+                    amountResidual : {halign:'right'},
+                    expiredDays : {columnWidth: 25, halign:'center'},
+                    amountInterest : {halign:'right'},
+                    amountTotal : {halign:'right'},
+                    state : {columnWidth: 20, halign:'center'},
+                },
+                headerStyles: {
+                    fillColor: [76, 133, 248],
+                    fontSize: 9
+                },
+                margin: {
+                    top: 20,
+                    horizontal: 7,
+                    bottom: 40
+                },
+            });
+
+            pdfDoc.save('Estado_financiero.pdf');
+        },
     });
 
     if (instance.web && instance.web.FormView) {

+ 7 - 4
static/src/xml/view.xml

@@ -12,11 +12,14 @@
             <table id="quota_table" data-toggle="table" data-classes="table table-condensed" data-undefined-text=" ">
                 <thead style="background:none;">
                     <tr>
-                        <th data-field="date" data-align="left">Fecha de vencimiento</th>
-                        <th data-field="name" data-align="left">Descripción</th>
+                        <th data-field="dateMaturity" data-align="left">Vencimiento</th>
+                        <th data-field="quotaNumber" data-align="left">Nº Cuota</th>
+                        <th data-field="amountQuota" data-align="right">Cuota</th>
+                        <th data-field="amountResidual" data-align="right">Pendiente</th>
+                        <th data-field="expiredDays" data-align="center">Días atrasado</th>
+                        <th data-field="amountInterest" data-align="right">Interés</th>
+                        <th data-field="amountTotal" data-align="right">Tota</th>
                         <th data-field="state" data-align="left">Estado</th>
-                        <th data-field="amount" data-align="right">Valor de la cuota</th>
-                        <th data-field="residual" data-align="right">Saldo de la cuota</th>
                     </tr>
                 </thead>
             </table>