Просмотр исходного кода

[FIX] Corrección de cálculos para multi divisa Widget deudas atrasadas

adrielso 7 лет назад
Родитель
Сommit
dd70938eff
1 измененных файлов с 55 добавлено и 9 удалено
  1. 55 9
      static/src/js/widgets/expired_account_counters.js

+ 55 - 9
static/src/js/widgets/expired_account_counters.js

@@ -5,11 +5,12 @@ function expired_account_counters (widget) {
     var Qweb = openerp.web.qweb;
 
     widget.ExpiredAccountCountersWidget = widget.Base.extend({
-        template: 'ExpiredAccountCounters',
+        template : 'ExpiredAccountCounters',
         moveLine : [],
         resCompany : [],
-        resCurrecy :[],
-        modelId:[],
+        resCurrecy : [],
+        modelId : [],
+        accountInvoice : [],
 
         events: {
             'click a': 'showCustomers',
@@ -43,6 +44,9 @@ function expired_account_counters (widget) {
                 return moveLine;
             }).then(function (moveLine){
                 self.moveLine = moveLine;
+                return self.fetchInvoice(moveLine);
+            }).then(function(accountInvoice){
+                self.accountInvoice = accountInvoice;
                 return self.fetchResCompany();
             }).then(function (resCompany){
                 self.resCompany = resCompany;
@@ -73,7 +77,7 @@ function expired_account_counters (widget) {
             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'];
+            var field =['id', 'partner_id', 'amount_residual', 'credit', 'debit', 'date_maturity', 'invoice', 'ref', 'invoice', 'amount_residual_currency'];
             var domain=[['credit', '<=', 0],['date_maturity', '<', hoy]];
             var moveLine = new model.web.Model('account.move.line');
 
@@ -83,6 +87,22 @@ function expired_account_counters (widget) {
 
             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;
@@ -118,17 +138,43 @@ function expired_account_counters (widget) {
                 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 residual = 0;
-            var newMoveLine = [];
+            var newmoveLine = [];
+            var inteMove;
+            var residual =0;
+            var currencyInvoice;
             var company = self.resCompany.shift();
             var currencyBase = self.getCurrency(company.currency_id[0]).shift();
 
-            if (self.moveLine.length > 0){
-                residual = _.reduce(_.map(self.moveLine, function (map) {
-                    return map.amount_residual;
+            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;
                 });