|
@@ -1,14 +1,14 @@
|
|
|
function monthly_expenses(widget) {
|
|
|
"use strict";
|
|
|
|
|
|
- var model= openerp;
|
|
|
+ var model = openerp;
|
|
|
|
|
|
widget.MonthlyExpensesWidget = widget.Base.extend({
|
|
|
template: 'MonthlyExpenses',
|
|
|
- accountVoucher:[],
|
|
|
- accountInvoice:[],
|
|
|
- resCurrecy :[],
|
|
|
- resCompany:[],
|
|
|
+ accountVoucher: [],
|
|
|
+ accountInvoice: [],
|
|
|
+ resCurrecy: [],
|
|
|
+ resCompany: [],
|
|
|
|
|
|
events: {
|
|
|
'click a': 'showCustomers',
|
|
@@ -17,7 +17,7 @@ function monthly_expenses(widget) {
|
|
|
|
|
|
init: function (parent) {
|
|
|
this._super(parent, {
|
|
|
- width : 3,
|
|
|
+ width: 3,
|
|
|
height: 2
|
|
|
});
|
|
|
},
|
|
@@ -42,54 +42,54 @@ function monthly_expenses(widget) {
|
|
|
}).then(function (accountVoucher) {
|
|
|
self.accountVoucher = accountVoucher;
|
|
|
return self.fetchAccountInvoice(accountVoucher);
|
|
|
- }).then(function(accountInvoice){
|
|
|
+ }).then(function(accountInvoice) {
|
|
|
self.accountInvoice = accountInvoice;
|
|
|
return self.fetchResCompany();
|
|
|
- }).then(function(resCompany){
|
|
|
+ }).then(function(resCompany) {
|
|
|
self.resCompany = resCompany;
|
|
|
return self.fetchResCurrecy();
|
|
|
- }).then(function(resCurrecy){
|
|
|
+ }).then(function(resCurrecy) {
|
|
|
self.resCurrecy = resCurrecy;
|
|
|
return self.fetchReduceVoucher();
|
|
|
});
|
|
|
},
|
|
|
// voucher pagos a proveedor rango de fecha um mes
|
|
|
- fetchAccountVoucher: function(){
|
|
|
+ fetchAccountVoucher: function() {
|
|
|
var self = this;
|
|
|
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 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');
|
|
|
|
|
|
- accountVoucher.query(fields).filter(domain).all().then(function(results){
|
|
|
+ accountVoucher.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
|
});
|
|
|
|
|
|
return defer;
|
|
|
},
|
|
|
// invoice -> origin === false
|
|
|
- fetchAccountInvoice:function(voucher){
|
|
|
+ fetchAccountInvoice:function(voucher) {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
var number = _.map(voucher,function(map){return map.reference});
|
|
|
var fields = ['id','number','date_invoice','origin'];
|
|
|
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);
|
|
|
});
|
|
|
|
|
|
return defer;
|
|
|
},
|
|
|
//Comapnia
|
|
|
- fetchResCompany: function(){
|
|
|
+ fetchResCompany: function() {
|
|
|
var self = this;
|
|
|
var defer = $.Deferred();
|
|
|
- var fields =['id','name', 'currency_id'];
|
|
|
- var domain =[['id', '=', 1]];
|
|
|
+ var fields = ['id','name', 'currency_id'];
|
|
|
+ var domain = [['id', '=', 1]];
|
|
|
var resCompany = new model.web.Model('res.company');
|
|
|
|
|
|
resCompany.query(fields).filter(domain).all().then(function (results) {
|
|
@@ -102,11 +102,11 @@ function monthly_expenses(widget) {
|
|
|
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 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){
|
|
|
+ resCurrecy.query(fields).filter(domain).all().then(function(results) {
|
|
|
defer.resolve(results);
|
|
|
});
|
|
|
|
|
@@ -115,7 +115,7 @@ function monthly_expenses(widget) {
|
|
|
|
|
|
fetchReduceVoucher: function () {
|
|
|
var self = this
|
|
|
- var voucher=[];
|
|
|
+ var voucher = [];
|
|
|
var newVoucher = self.getVoucherInvoice();
|
|
|
var itemVoucher;
|
|
|
var currencyVoucher;
|
|
@@ -128,15 +128,16 @@ function monthly_expenses(widget) {
|
|
|
currencyVoucher = self.getCurrency(itemVoucher.payment_rate_currency_id[0]).shift();
|
|
|
|
|
|
if(!currencyVoucher){
|
|
|
- currencyVoucher={};
|
|
|
- currencyVoucher.rate=currencyBase.rate_silent;
|
|
|
+ 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) {
|
|
|
return map.amount_rate;
|
|
|
}), function (memo, num) {
|
|
@@ -152,18 +153,19 @@ function monthly_expenses(widget) {
|
|
|
getCurrency: function (id) {
|
|
|
var self = this;
|
|
|
return _.filter(self.resCurrecy,function (item) {
|
|
|
- return item.id === id
|
|
|
+ return item.id === id;
|
|
|
})
|
|
|
},
|
|
|
// Obtener los pagos de las factura sim origin
|
|
|
- getVoucherInvoice:function(){
|
|
|
+ getVoucherInvoice:function() {
|
|
|
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
|
|
|
showCustomers: function (e) {
|
|
@@ -172,20 +174,29 @@ function monthly_expenses(widget) {
|
|
|
model.web.notification.do_warn("Atención","Sin datos");
|
|
|
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 number = _.map(self.accountInvoice,function(map){return map.number});
|
|
|
+ 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;
|
|
|
+ });
|
|
|
|
|
|
this.do_action({
|
|
|
- name:"Listado de gastos del mes",
|
|
|
+ name: "Listado de gastos del mes",
|
|
|
type: 'ir.actions.act_window',
|
|
|
res_model: "account.voucher",
|
|
|
views: [[false, 'list'],[false,'form']],
|
|
|
target: 'new',
|
|
|
domain: [['type', '=', 'payment'],['state', '=', 'posted'],['date', '>=',desde],['date','<',hasta],['reference','in',number]],
|
|
|
context: {},
|
|
|
- flags: {'form': {'action_buttons': false, 'options': {'mode': 'view'}}},
|
|
|
+ flags: {
|
|
|
+ 'form': {
|
|
|
+ 'action_buttons': false,
|
|
|
+ 'options': {
|
|
|
+ 'mode': 'view'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
});
|
|
|
}
|
|
|
});
|