Browse Source

commit inicial

Rodney Elpidio Enciso Arias 6 years ago
commit
4d3af69e4e

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from model import account

BIN
__init__.pyc


+ 19 - 0
__openerp__.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+{
+    'name' : 'Análisis de cuotas.',
+    'version' : '1.0',
+    'description' : """
+    """,
+    'author' : 'Eiru',
+    'category' : 'account',
+    'depends' : [
+        'account',
+    ],
+    'data' : [
+        'views/template.xml',
+        'views/account_invoice_view.xml',
+    ],
+    'qweb' : ['static/src/xml/*.xml',],
+    'installable' : True,
+    'auto_install' : False,
+}

+ 0 - 0
model/__init__.py


BIN
model/__init__.pyc


+ 55 - 0
model/account.py

@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api
+
+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)])
+		i = len(AccountMoveLine)
+		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,
+			})
+			i = i - 1
+
+		return values
+
+class ResCurrrency(models.Model):
+	_inherit = 'res.currency'
+
+	@api.model
+	def getResCurrencyQuoteAnalysis(self,domain):
+		ResCurrency = self.env['res.currency'].search(domain)
+		values = []
+		for currency in ResCurrency:
+			values.append({
+				'symbol': currency.symbol,
+				'decimal_separator': currency.decimal_separator,
+				'decimal_places': currency.decimal_places,
+				'thousands_separator': currency.thousands_separator,
+				'symbol_position': currency.symbol_position,
+			})
+
+		return values

BIN
model/account.pyc


BIN
static/description/icon.png


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

@@ -0,0 +1,107 @@
+openerp.eiru_quota_analysis = function (instance, local) {
+    local.widgetInstance = null;
+    local.parentInstance = null;
+    var model = openerp;
+    local.EiruQuotaAnalysisWidget = instance.Widget.extend({
+        template : "eiru_quota_analysis.EiruQuotaAnalysis",
+        checkQuota: function(id) {
+            var self = this;
+            self.id = id;
+            if (id)
+                self.Initial();
+        },
+        start: function () {
+            var self = this;
+            var table = $('#quota_table');
+            table.bootstrapTable({data : self.rowsData});
+        },
+        Initial: function(){
+            var self = this;
+            var id = openerp.webclient._current_state.id;
+            self.fetchAccountInvoice(id).then(function (AccountInvoice){
+                return AccountInvoice;
+            }).then(function(AccountInvoice){
+                self.AccountInvoice = AccountInvoice;
+                return self.fetchResCurrency();
+            }).then(function(ResCurrency){
+                self.ResCurrency = ResCurrency;
+                return self.build();
+            });
+            return;
+        },
+        fetchAccountInvoice: function (id){
+            var self = this;
+            var domain = [
+                ['id','=',id],
+            ];
+            var AccountInvoice = new model.web.Model('account.invoice');
+            return AccountInvoice.call('getAccountInvoiceQuoteAnalysis',[domain], {
+                context: new model.web.CompoundContext()
+            });
+        },
+        fetchResCurrency: function (){
+            var self = this;
+            var domain = [
+                ['base','=',true],
+            ];
+            var ResCurrency = new model.web.Model('res.currency');
+            return ResCurrency.call('getResCurrencyQuoteAnalysis',[domain], {
+                context: new model.web.CompoundContext()
+            });
+        },
+        build: function(){
+            var self = this;
+            var data = [];
+            var state = '';
+            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')
+                if(item.state != 'Pagado'){
+                    if(item.date < moment().format('YYYY-MM-DD')){
+                        date = moment(item.date,'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),
+                });
+            });
+            self.loadTable(data);
+        },
+        loadTable:function(rowsTable){
+            var self = this;
+            self.rowsData = rowsTable;
+            var table = $('#quota_table');
+            table.bootstrapTable('load', rowsTable);
+        }
+    });
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_record: function (record) {
+                this._super.apply(this, arguments);
+                if (this.model !== 'account.invoice')
+                    return;
+
+                local.parentInstance = this;
+                if (local.widgetInstance) {
+                    local.widgetInstance.checkQuota(record.id);
+                    return
+                }
+                local.widgetInstance = new local.EiruQuotaAnalysisWidget(this);
+                var elemento = this.$el.find('.oe_form_sheet.oe_form_sheet_width');
+                elemento =  elemento.find('.quota_box');
+                local.widgetInstance.appendTo(elemento);
+                local.widgetInstance.checkQuota(record.id);
+            }
+        });
+    }
+}

+ 23 - 0
static/src/xml/view.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiru_quota_analysis.EiruQuotaAnalysis">
+        <br/>
+        <div class="eiru-quota-table">
+            <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="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>
+        </div>
+    </t>
+</template>

+ 17 - 0
views/account_invoice_view.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record id="account_invoice_quota_view" model="ir.ui.view">
+            <field name="name">account.invoice.quota.view</field>
+            <field name="model">account.invoice</field>
+            <field name="inherit_id" ref="account.invoice_form"/>
+            <field name="arch" type="xml">
+				<xpath expr="//notebook/page[@string='Payments']" position="after">
+                    <page string="Cuotas" groups="base.group_user" attrs="{'invisible': [('state','not in',('open'))]}">
+						<div class="quota_box"></div>
+                    </page>
+				</xpath>
+            </field>
+        </record>
+	</data>
+</openerp>

+ 9 - 0
views/template.xml

@@ -0,0 +1,9 @@
+<openerp>
+    <data>
+        <template id="eiru_quota_analysis.assets_backend" name="eiru_quota_analysis_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/eiru_quota_analysis/static/src/js/main.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>