123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- openerp.eiru_invoice_status_change = function(instance, local) {
- local.widgetInstance = null;
- local.parentInstance = null;
- local.EiruInvoiceStatusChangeWidget = instance.Widget.extend({
- id: undefined,
- init: function(parent) {
- this._super(parent);
- },
- /**
- * [checkState]
- */
- checkState: function(id) {
- var self = this;
- self.id = id;
- if (id)
- self.fectchInitial();
- },
- /**
- * [fectchInitial]
- */
- fectchInitial: function() {
- var self = this;
- self.fectchInvoice(self.id).then(function(accountInvoice) {
- return accountInvoice;
- }).then(function(accountInvoice) {
- if (!accountInvoice.length)
- return false
- return self.updateInvoiceState(accountInvoice.shift());
- }).then(function(update){
- if (update)
- return self.reloadPage()
- })
- },
- /**
- * [fectchInvoice]
- */
- fectchInvoice: function(id) {
- var invoice = new instance.web.Model('account.invoice');
- var fields = ['id','name','residual', 'state'];
- var domain = [['id', '=', id],['state', 'in', ['open', 'paid']]];
- return invoice.query(fields).filter(domain).all();
- },
- /**
- * [updateInvoiceState]
- */
- updateInvoiceState: function(invoice) {
- if (invoice.residual <= 0 && invoice.state === 'paid')
- return
- if (invoice.residual > 0 && invoice.state === 'open')
- return
- var invoiceUpdate = new instance.web.Model('account.invoice');
- return invoiceUpdate.call('update_invoice_state',[invoice.id], {
- context: new instance.web.CompoundContext()
- })
- },
- /**
- * [reloadPage]
- */
- reloadPage: function() {
- local.parentInstance.reload();
- },
- });
- 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.checkState(record.id);
- return
- }
- local.widgetInstance = new local.EiruInvoiceStatusChangeWidget(this);
- local.widgetInstance.checkState(record.id);
- }
- });
- }
- }
|