|
@@ -0,0 +1,287 @@
|
|
|
|
+function expired_account_counters (widget) {
|
|
|
|
+ "use strict";
|
|
|
|
+
|
|
|
|
+ var model = openerp;
|
|
|
|
+ var Qweb = openerp.web.qweb;
|
|
|
|
+
|
|
|
|
+ widget.ExpiredAccountCountersWidget = widget.Base.extend({
|
|
|
|
+ template: 'ExpiredAccountCounters',
|
|
|
|
+ moveLine: [],
|
|
|
|
+ resCompany: [],
|
|
|
|
+ resCurrecy: [],
|
|
|
|
+ modelId: [],
|
|
|
|
+ accountInvoice: [],
|
|
|
|
+ module_list: ['point_of_sale'],
|
|
|
|
+ newModule: [],
|
|
|
|
+
|
|
|
|
+ events: {
|
|
|
|
+ 'click a': 'showCustomers',
|
|
|
|
+ 'click h2': 'showCustomers',
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ init: function (parent) {
|
|
|
|
+ var self = this;
|
|
|
|
+ this._super(parent, {
|
|
|
|
+ width: 3,
|
|
|
|
+ height: 2,
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ start: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ self.fetchInitial();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // Consulta Inicial
|
|
|
|
+ fetchInitial: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ self.$el.find('.grid-stack-item-content dashboard').block({
|
|
|
|
+ message: null,
|
|
|
|
+ overlayCSS: {
|
|
|
|
+ backgroundColor: '#FAFAFA'
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
|
|
+ self.fecthIrModuleModule().then(function(modules){
|
|
|
|
+ self.modules = modules;
|
|
|
|
+ return modules;
|
|
|
|
+ }).then(function(modules){
|
|
|
|
+ return self.fetchMoveLine()
|
|
|
|
+ }).then(function (moveLine) {
|
|
|
|
+ return moveLine;
|
|
|
|
+ }).then(function (moveLine) {
|
|
|
|
+ self.moveLine = _.filter(moveLine, function(item) {
|
|
|
|
+ return item.amount_residual > 0;
|
|
|
|
+ });
|
|
|
|
+ return self.fetchInvoice(moveLine);
|
|
|
|
+ }).then(function(accountInvoice) {
|
|
|
|
+ self.accountInvoice = accountInvoice;
|
|
|
|
+ return self.fetchResCompany();
|
|
|
|
+ }).then(function (resCompany) {
|
|
|
|
+ self.resCompany = resCompany;
|
|
|
|
+ return self.fetchResCurrecy();
|
|
|
|
+ }).then(function (resCurrecy) {
|
|
|
|
+ self.resCurrecy = resCurrecy;
|
|
|
|
+ return self.fetchGetModelId();
|
|
|
|
+ }).then(function(modelId) {
|
|
|
|
+ self.modelId= modelId;
|
|
|
|
+ return self.fetchReduceMoveLine();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // Verificar Modelos Instalados
|
|
|
|
+ fecthIrModuleModule: function(){
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['name','id'];
|
|
|
|
+ var domain=[['state','=','installed'],['name','in',self.module_list]];
|
|
|
|
+ var irModule = new model.web.Model('ir.module.module');
|
|
|
|
+ irModule.query(fields).filter(domain).all().then(function(results){
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ })
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // getModelId
|
|
|
|
+ fetchGetModelId: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var irModelData = new model.web.Model('ir.model.data');
|
|
|
|
+ var getObtjectReference = irModelData.get_func('get_object_reference');
|
|
|
|
+
|
|
|
|
+ this.alive(getObtjectReference('account', 'invoice_form')).then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+ // Move line
|
|
|
|
+ fetchMoveLine: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var hoy = moment().format('YYYY-MM-DD');
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var field = ['id', 'partner_id', 'amount_residual', 'credit', 'debit', 'date_maturity', 'invoice', 'ref', 'invoice', 'amount_residual_currency','state'];
|
|
|
|
+ var domain = [['credit', '<=', 0], ['date_maturity', '<', hoy]];
|
|
|
|
+ var moveLine = new model.web.Model('account.move.line');
|
|
|
|
+
|
|
|
|
+ moveLine.query(field).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+ // invoice
|
|
|
|
+ fetchInvoice: function(moveline) {
|
|
|
|
+ var self = this ;
|
|
|
|
+ var defer = $.Deferred()
|
|
|
|
+ var ref = _.map(moveline, function(map) {
|
|
|
|
+ return map.invoice[0];
|
|
|
|
+ });
|
|
|
|
+ var fields = ['id', 'currency_id', 'number', 'currency_id'];
|
|
|
|
+ var domain = [['id', 'in', ref]];
|
|
|
|
+ var accountInvoice = new model.web.Model('account.invoice');
|
|
|
|
+ accountInvoice.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+ //Comapnia
|
|
|
|
+ fetchResCompany: function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['id','name', 'currency_id', 'logo'];
|
|
|
|
+ var domain = [['id', '=', 1]];
|
|
|
|
+ var resCompanyIds = new model.web.Model('res.company');
|
|
|
|
+
|
|
|
|
+ resCompanyIds.query(fields).filter(domain).all().then(function (results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+ // Res currecy
|
|
|
|
+ fetchResCurrecy : function() {
|
|
|
|
+ var self = this;
|
|
|
|
+ var defer = $.Deferred();
|
|
|
|
+ var fields = ['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
|
+ var domain = [['active','=', true]];
|
|
|
|
+ var resCurrecy = new model.web.Model('res.currency');
|
|
|
|
+
|
|
|
|
+ resCurrecy.query(fields).filter(domain).all().then(function(results) {
|
|
|
|
+ defer.resolve(results);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return defer;
|
|
|
|
+ },
|
|
|
|
+ // Obtener moneda
|
|
|
|
+ getCurrency: function (id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ return _.filter(self.resCurrecy,function (item) {
|
|
|
|
+ return item.id === id;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ // Moneda de la factura
|
|
|
|
+ getInvoiceCurrency: function(id) {
|
|
|
|
+ var self = this;
|
|
|
|
+ var currency_invoice = _.filter(self.accountInvoice, function(filter) {
|
|
|
|
+ return filter.id === id;
|
|
|
|
+ }).shift();
|
|
|
|
+ return self.getCurrency(currency_invoice.currency_id[0]);
|
|
|
|
+ },
|
|
|
|
+ // Reduce Move line
|
|
|
|
+ fetchReduceMoveLine: function () {
|
|
|
|
+ var self = this;
|
|
|
|
+ var newmoveLine = [];
|
|
|
|
+ var inteMove;
|
|
|
|
+ var residual = 0;
|
|
|
|
+ var currencyInvoice;
|
|
|
|
+ var company = self.resCompany.shift();
|
|
|
|
+ var currencyBase = self.getCurrency(company.currency_id[0]).shift();
|
|
|
|
+
|
|
|
|
+ for (var i = 0; i < self.moveLine.length; i++) {
|
|
|
|
+ inteMove = self.moveLine[i];
|
|
|
|
+
|
|
|
|
+ currencyInvoice = self.getInvoiceCurrency(inteMove.invoice[0]).shift();
|
|
|
|
+
|
|
|
|
+ if(!currencyInvoice) {
|
|
|
|
+ currencyInvoice = {};
|
|
|
|
+ currencyInvoice.rate=currencyBase.rate_silent;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ newmoveLine.push({
|
|
|
|
+ amount_residual: inteMove.amount_residual,
|
|
|
|
+ amount_residual_currency: (inteMove.amount_residual_currency * (currencyBase.rate_silent / currencyInvoice.rate_silent))
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (newmoveLine.length > 0) {
|
|
|
|
+ residual = _.reduce(_.map(newmoveLine, function (map) {
|
|
|
|
+ return map.amount_residual_currency;
|
|
|
|
+ }), function (memo, num) {
|
|
|
|
+ return memo + num;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
|
|
+ self.$el.find('.widget-content').find('a').text(accounting.formatMoney(residual, currencyBase.symbol, currencyBase.decimal_places, currencyBase.thousands_separator, currencyBase.decimal_separator));
|
|
|
|
+ self.$el.find('.grid-stack-item-content dashboard').unblock();
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ showCustomers: function (e) {
|
|
|
|
+ var self = this;
|
|
|
|
+ if (self.moveLine <=0) {
|
|
|
|
+ model.web.notification.do_warn("Atención","Sin datos");
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var moneda = self.resCurrecy.shift();
|
|
|
|
+ var newmoveLine = self.moveLine;
|
|
|
|
+ var titleData = [
|
|
|
|
+ {
|
|
|
|
+ title: "Deudas atrasadas"
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
|
|
+ var headerModal = [
|
|
|
|
+ {
|
|
|
|
+ title: "id"
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: "Cliente"
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: "Numero de Factura"
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: "Vencimiento"
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: "Monto "
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ var modal = Qweb.render('ExpiredAccountCountersModal', {
|
|
|
|
+ data: newmoveLine,
|
|
|
|
+ dataThead: headerModal,
|
|
|
|
+ modalTitle: titleData
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $('.openerp_webclient_container').after(modal);
|
|
|
|
+ $('.expired-account-modal').modal()
|
|
|
|
+ $('.expired-account-modal').on('hidden.bs.modal', function (e) {
|
|
|
|
+ self.removeModal(e);
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ var contenido = $('.expired-account-modal').find('.table-tbody');
|
|
|
|
+ contenido.click(function (e) {
|
|
|
|
+ $(contenido).find('tr').removeClass('table-row-select');
|
|
|
|
+ $(e.target).closest('tr').addClass('table-row-select');
|
|
|
|
+ var chirdren_id =$(e.target).closest('tr').children()[0].textContent;
|
|
|
|
+ self.renderForm(chirdren_id);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ // Remover <Modal></Modal>
|
|
|
|
+ removeModal: function (e) {
|
|
|
|
+ $('.expired-account-modal').remove();
|
|
|
|
+ $('.modal-backdrop').remove();
|
|
|
|
+ },
|
|
|
|
+ // Llamar form
|
|
|
|
+ renderForm: function(id){
|
|
|
|
+ var self = this;
|
|
|
|
+ id = parseInt(id);
|
|
|
|
+
|
|
|
|
+ this.do_action({
|
|
|
|
+ type: "ir.actions.act_window",
|
|
|
|
+ res_model: "account.invoice",
|
|
|
|
+ views: [[self.modelId[1], 'form']],
|
|
|
|
+ target: 'current',
|
|
|
|
+ domain: [['id', '=', id]],
|
|
|
|
+ context: {},
|
|
|
|
+ res_id: id,
|
|
|
|
+ }).then(function() {
|
|
|
|
+ self.removeModal();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|