|
@@ -1,14 +1,14 @@
|
|
function monthly_purchases(widget) {
|
|
function monthly_purchases(widget) {
|
|
"use strict";
|
|
"use strict";
|
|
|
|
|
|
- var model= openerp;
|
|
|
|
|
|
+ var model = openerp;
|
|
|
|
|
|
widget.MonthlyPurchasesWidget = widget.Base.extend({
|
|
widget.MonthlyPurchasesWidget = widget.Base.extend({
|
|
template: 'MonthlyPurchases',
|
|
template: 'MonthlyPurchases',
|
|
- accountVoucher:[],
|
|
|
|
- accountInvoice:[],
|
|
|
|
- resCurrecy :[],
|
|
|
|
- resCompany:[],
|
|
|
|
|
|
+ accountVoucher: [],
|
|
|
|
+ accountInvoice: [],
|
|
|
|
+ resCurrecy: [],
|
|
|
|
+ resCompany: [],
|
|
|
|
|
|
events: {
|
|
events: {
|
|
'click a': 'showCustomers',
|
|
'click a': 'showCustomers',
|
|
@@ -17,7 +17,7 @@ function monthly_purchases(widget) {
|
|
|
|
|
|
init: function (parent) {
|
|
init: function (parent) {
|
|
this._super(parent, {
|
|
this._super(parent, {
|
|
- width : 3,
|
|
|
|
|
|
+ width: 3,
|
|
height: 2
|
|
height: 2
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -27,7 +27,7 @@ function monthly_purchases(widget) {
|
|
self.fetchInitial();
|
|
self.fetchInitial();
|
|
},
|
|
},
|
|
|
|
|
|
- fetchInitial: function(){
|
|
|
|
|
|
+ fetchInitial: function() {
|
|
var self = this;
|
|
var self = this;
|
|
self.$el.find('#morosidad').block({
|
|
self.$el.find('#morosidad').block({
|
|
message: null,
|
|
message: null,
|
|
@@ -35,6 +35,7 @@ function monthly_purchases(widget) {
|
|
backgroundColor: '#FAFAFA'
|
|
backgroundColor: '#FAFAFA'
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
self.$el.find('.widget-content.widget-loading').css('display','flex');
|
|
|
|
|
|
self.fetchAccountVoucher().then(function (accountVoucher) {
|
|
self.fetchAccountVoucher().then(function (accountVoucher) {
|
|
@@ -42,54 +43,56 @@ function monthly_purchases(widget) {
|
|
}).then(function (accountVoucher) {
|
|
}).then(function (accountVoucher) {
|
|
self.accountVoucher = accountVoucher;
|
|
self.accountVoucher = accountVoucher;
|
|
return self.fetchAccountInvoice(accountVoucher);
|
|
return self.fetchAccountInvoice(accountVoucher);
|
|
- }).then(function(accountInvoice){
|
|
|
|
|
|
+ }).then(function(accountInvoice) {
|
|
self.accountInvoice = accountInvoice;
|
|
self.accountInvoice = accountInvoice;
|
|
return self.fetchResCompany();
|
|
return self.fetchResCompany();
|
|
- }).then(function(resCompany){
|
|
|
|
|
|
+ }).then(function(resCompany) {
|
|
self.resCompany = resCompany;
|
|
self.resCompany = resCompany;
|
|
return self.fetchResCurrecy();
|
|
return self.fetchResCurrecy();
|
|
- }).then(function(resCurrecy){
|
|
|
|
|
|
+ }).then(function(resCurrecy) {
|
|
self.resCurrecy = resCurrecy;
|
|
self.resCurrecy = resCurrecy;
|
|
return self.fetchReduceVoucher();
|
|
return self.fetchReduceVoucher();
|
|
});
|
|
});
|
|
},
|
|
},
|
|
// Account Voucher Pagos a facturas Proveedores
|
|
// Account Voucher Pagos a facturas Proveedores
|
|
- fetchAccountVoucher: function(){
|
|
|
|
|
|
+ fetchAccountVoucher: function() {
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
- var desde =moment().format('YYYY-MM-01');
|
|
|
|
- var hasta =moment().add(1,'months').format('YYYY-MM-01');
|
|
|
|
|
|
+ var desde = moment().format('YYYY-MM-01');
|
|
|
|
+ var hasta = moment().add(1,'months').format('YYYY-MM-01');
|
|
var fields = ['id', 'amount', 'currency_id', 'payment_rate_currency_id', 'reference'];
|
|
var fields = ['id', 'amount', 'currency_id', 'payment_rate_currency_id', 'reference'];
|
|
- var domain= [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta]];
|
|
|
|
|
|
+ var domain = [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta]];
|
|
var accountVoucher = new model.web.Model('account.voucher');
|
|
var accountVoucher = new model.web.Model('account.voucher');
|
|
|
|
|
|
- accountVoucher.query(fields).filter(domain).all().then(function(results){
|
|
|
|
|
|
+ accountVoucher.query(fields).filter(domain).all().then(function(results) {
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
});
|
|
});
|
|
|
|
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
// invoice
|
|
// invoice
|
|
- fetchAccountInvoice:function(voucher){
|
|
|
|
|
|
+ fetchAccountInvoice:function(voucher) {
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
- var number = _.map(voucher,function(map){return map.reference});
|
|
|
|
|
|
+ var number = _.map(voucher,function(map) {
|
|
|
|
+ return map.reference;
|
|
|
|
+ });
|
|
var fields = ['id','number','date_invoice','origin'];
|
|
var fields = ['id','number','date_invoice','origin'];
|
|
var domain = [['type', '=', 'in_invoice'],['origin', '!=', false ],['number', 'in', number]];
|
|
var domain = [['type', '=', 'in_invoice'],['origin', '!=', false ],['number', 'in', number]];
|
|
- var accountInvoice= new model.web.Model('account.invoice');
|
|
|
|
|
|
+ var accountInvoice = new model.web.Model('account.invoice');
|
|
|
|
|
|
- accountInvoice.query(fields).filter(domain).all().then(function(results){
|
|
|
|
|
|
+ accountInvoice.query(fields).filter(domain).all().then(function(results) {
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
});
|
|
});
|
|
|
|
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
//Comapnia
|
|
//Comapnia
|
|
- fetchResCompany: function(){
|
|
|
|
|
|
+ fetchResCompany: function() {
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
- var fields =['id','name', 'currency_id', 'logo'];
|
|
|
|
- var domain =[['id', '=', 1]];
|
|
|
|
|
|
+ var fields = ['id','name', 'currency_id', 'logo'];
|
|
|
|
+ var domain = [['id', '=', 1]];
|
|
var resCompany = new model.web.Model('res.company');
|
|
var resCompany = new model.web.Model('res.company');
|
|
|
|
|
|
resCompany.query(fields).filter(domain).all().then(function (results) {
|
|
resCompany.query(fields).filter(domain).all().then(function (results) {
|
|
@@ -99,14 +102,14 @@ function monthly_purchases(widget) {
|
|
return defer;
|
|
return defer;
|
|
},
|
|
},
|
|
// Res currecy
|
|
// Res currecy
|
|
- fetchResCurrecy : function(){
|
|
|
|
|
|
+ fetchResCurrecy : function() {
|
|
var self = this;
|
|
var self = this;
|
|
var defer = $.Deferred();
|
|
var defer = $.Deferred();
|
|
- var fields =['id','name', 'symbol', 'rate_silent', 'base', 'decimal_separator', 'decimal_places', 'thousands_separator', 'symbol_position'];
|
|
|
|
- var domain =[['active','=', true]];
|
|
|
|
|
|
+ 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');
|
|
var resCurrecy = new model.web.Model('res.currency');
|
|
|
|
|
|
- resCurrecy.query(fields).filter(domain).all().then(function(results){
|
|
|
|
|
|
+ resCurrecy.query(fields).filter(domain).all().then(function(results) {
|
|
defer.resolve(results);
|
|
defer.resolve(results);
|
|
});
|
|
});
|
|
|
|
|
|
@@ -115,7 +118,7 @@ function monthly_purchases(widget) {
|
|
|
|
|
|
fetchReduceVoucher: function () {
|
|
fetchReduceVoucher: function () {
|
|
var self = this
|
|
var self = this
|
|
- var voucher=[];
|
|
|
|
|
|
+ var voucher = [];
|
|
var newVoucher = self.getVoucherInvoice();
|
|
var newVoucher = self.getVoucherInvoice();
|
|
var itemVoucher;
|
|
var itemVoucher;
|
|
var currencyVoucher;
|
|
var currencyVoucher;
|
|
@@ -127,16 +130,17 @@ function monthly_purchases(widget) {
|
|
itemVoucher = newVoucher[i];
|
|
itemVoucher = newVoucher[i];
|
|
currencyVoucher = self.getCurrency(itemVoucher.payment_rate_currency_id[0]).shift();
|
|
currencyVoucher = self.getCurrency(itemVoucher.payment_rate_currency_id[0]).shift();
|
|
|
|
|
|
- if(!currencyVoucher){
|
|
|
|
- currencyVoucher={};
|
|
|
|
- currencyVoucher.rate=currencyBase.rate_silent;
|
|
|
|
|
|
+ if(!currencyVoucher) {
|
|
|
|
+ currencyVoucher = {};
|
|
|
|
+ currencyVoucher.rate = currencyBase.rate_silent;
|
|
}
|
|
}
|
|
- voucher.push({ ammount : itemVoucher.amount,
|
|
|
|
- amount_rate :(itemVoucher.amount* (currencyBase.rate_silent/currencyVoucher.rate_silent))
|
|
|
|
- });
|
|
|
|
|
|
+ voucher.push({
|
|
|
|
+ ammount: itemVoucher.amount,
|
|
|
|
+ amount_rate: (itemVoucher.amount* (currencyBase.rate_silent/currencyVoucher.rate_silent))
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
- if (voucher.length > 0){
|
|
|
|
|
|
+ if (voucher.length > 0) {
|
|
cat = _.reduce(_.map(voucher, function (map) {
|
|
cat = _.reduce(_.map(voucher, function (map) {
|
|
return map.amount_rate;
|
|
return map.amount_rate;
|
|
}), function (memo, num) {
|
|
}), function (memo, num) {
|
|
@@ -145,7 +149,7 @@ function monthly_purchases(widget) {
|
|
}
|
|
}
|
|
|
|
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
self.$el.find('.widget-content.widget-loading').css('display','none');
|
|
- self.$el.find('.widget-content').find('a').text(accounting.formatMoney(cat, currencyBase.symbol, currencyBase.decimal_places, currencyBase.thousands_separator, currencyBase.decimal_separator))
|
|
|
|
|
|
+ self.$el.find('.widget-content').find('a').text(accounting.formatMoney(cat, currencyBase.symbol, currencyBase.decimal_places, currencyBase.thousands_separator, currencyBase.decimal_separator));
|
|
self.$el.find('#morosidad').unblock();
|
|
self.$el.find('#morosidad').unblock();
|
|
},
|
|
},
|
|
// Obtener la moneda
|
|
// Obtener la moneda
|
|
@@ -156,14 +160,14 @@ function monthly_purchases(widget) {
|
|
})
|
|
})
|
|
},
|
|
},
|
|
// obtneer los pagos con origin
|
|
// obtneer los pagos con origin
|
|
- getVoucherInvoice:function(){
|
|
|
|
|
|
+ getVoucherInvoice:function() {
|
|
var self = this;
|
|
var self = this;
|
|
- var number = _.map(self.accountInvoice, function(map){
|
|
|
|
- return map.number;
|
|
|
|
- });
|
|
|
|
- return _.flatten(_.filter(self.accountVoucher,function(item){
|
|
|
|
- return _.contains(number,item.reference);
|
|
|
|
- }));
|
|
|
|
|
|
+ var number = _.map(self.accountInvoice, function(map) {
|
|
|
|
+ return map.number;
|
|
|
|
+ });
|
|
|
|
+ return _.flatten(_.filter(self.accountVoucher,function(item) {
|
|
|
|
+ return _.contains(number,item.reference);
|
|
|
|
+ }));
|
|
},
|
|
},
|
|
// modal
|
|
// modal
|
|
showCustomers: function (e) {
|
|
showCustomers: function (e) {
|
|
@@ -173,20 +177,27 @@ function monthly_purchases(widget) {
|
|
model.web.notification.do_warn("Atención","Sin datos");
|
|
model.web.notification.do_warn("Atención","Sin datos");
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- var hoy =moment().format('YYYY-MM-DD');
|
|
|
|
- var desde =moment().format('YYYY-MM-01');
|
|
|
|
- var hasta =moment().add(1,'months').format('YYYY-MM-01');
|
|
|
|
|
|
+ var hoy = moment().format('YYYY-MM-DD');
|
|
|
|
+ var desde = moment().format('YYYY-MM-01');
|
|
|
|
+ var hasta = moment().add(1,'months').format('YYYY-MM-01');
|
|
var number = _.map(self.accountInvoice,function(map){return map.number});
|
|
var number = _.map(self.accountInvoice,function(map){return map.number});
|
|
|
|
|
|
this.do_action({
|
|
this.do_action({
|
|
- name:"Listado de compras del mes",
|
|
|
|
|
|
+ name: "Listado de compras del mes",
|
|
type: 'ir.actions.act_window',
|
|
type: 'ir.actions.act_window',
|
|
res_model: "account.voucher",
|
|
res_model: "account.voucher",
|
|
views: [[false, 'list'],[false,'form']],
|
|
views: [[false, 'list'],[false,'form']],
|
|
target: 'new',
|
|
target: 'new',
|
|
domain: [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta],['reference','in',number]],
|
|
domain: [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta],['reference','in',number]],
|
|
context: {},
|
|
context: {},
|
|
- flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
|
|
|
+ flags: {
|
|
|
|
+ 'form': {
|
|
|
|
+ 'action_buttons': false,
|
|
|
|
+ 'options': {
|
|
|
|
+ 'mode': 'view'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|