|
@@ -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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|