(function() { openerp.widgetInstanceInterestInvoiceVerify = null; openerp.parentInstanceInterestInvoiceVerify = {}; var QWeb = openerp.web.qweb; var instanceWeb = openerp.web; openerp.VerifyInterestInvoice = openerp.Widget.extend({ id: undefined, buttons: undefined, /* init */ init: function(parent) { this._super(parent); this.buttons = parent.$buttons; }, /* Check state*/ checkState: function(id) { var self = this; self.id = id; if (self.id) self.fetchInitial(); }, /* Reload Page*/ reloadPage: function() { openerp.parentInstanceInterestInvoiceVerify.reload(); }, // /* Método inicial */ fetchInitial: function() { var self = this; self.fetchInvoice(self.id).then(function(accountInvoice){ return accountInvoice; }).then(function(accountInvoice) { self.accountInvoice = accountInvoice; if ((accountInvoice[0].state !== 'open') || (accountInvoice[0].type !=='out_invoice') || ((accountInvoice[0].state === 'open') && (accountInvoice[0].is_interest))){ return false; } self.verifyInterestPartner(accountInvoice[0].id).then(function(results) { return results; }).then(function(results){ instanceWeb.notification.do_warn("Atencion",results.message); return self.reloadPage(); }); }); }, fetchInvoice: function(id){ var invoice = new instanceWeb.Model('account.invoice'); var fields =['id', 'name', 'state', 'is_interest', 'type']; var domain=[['id', '=', id]] return invoice.query(fields).filter(domain).all(); }, /* Verificar interest */ verifyInterestPartner: function(id) { var bankStatement = new instanceWeb.Model('account.invoice'); return bankStatement.call('eiru_account_interest_verify_invoice',[id],{ context: new instanceWeb.CompoundContext() }); }, }); if (openerp.web && openerp.web.FormView) { openerp.web.FormView.include({ load_record: function(record) { this._super.apply(this, arguments); if (this.model !== 'account.invoice') return; openerp.parentInstanceInterestInvoiceVerify = this; if (openerp.widgetInstanceInterestInvoiceVerify) { if (openerp.widgetInstanceInterestInvoiceVerify.id === record.id){ openerp.widgetInstanceInterestInvoiceVerify.id = undefined; return } openerp.widgetInstanceInterestInvoiceVerify.checkState(record.id); return; } openerp.widgetInstanceInterestInvoiceVerify = new openerp.VerifyInterestInvoice(this); openerp.widgetInstanceInterestInvoiceVerify.checkState(record.id); } }); } })();