verify_interest_invoice.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function() {
  2. openerp.widgetInstanceInterestInvoiceVerify = null;
  3. openerp.parentInstanceInterestInvoiceVerify = {};
  4. var QWeb = openerp.web.qweb;
  5. var instanceWeb = openerp.web;
  6. openerp.VerifyInterestInvoice = openerp.Widget.extend({
  7. id: undefined,
  8. buttons: undefined,
  9. /* init */
  10. init: function(parent) {
  11. this._super(parent);
  12. this.buttons = parent.$buttons;
  13. },
  14. /* Check state*/
  15. checkState: function(id) {
  16. var self = this;
  17. self.id = id;
  18. if (self.id)
  19. self.fetchInitial();
  20. },
  21. /* Reload Page*/
  22. reloadPage: function() {
  23. openerp.parentInstanceInterestInvoiceVerify.reload();
  24. },
  25. // /* Método inicial */
  26. fetchInitial: function() {
  27. var self = this;
  28. self.fetchInvoice(self.id).then(function(accountInvoice){
  29. return accountInvoice;
  30. }).then(function(accountInvoice) {
  31. self.accountInvoice = accountInvoice;
  32. if ((accountInvoice[0].state !== 'open') || (accountInvoice[0].type !=='out_invoice') || ((accountInvoice[0].state === 'open') && (accountInvoice[0].is_interest))){
  33. return false;
  34. }
  35. self.verifyInterestPartner(accountInvoice[0].id).then(function(results) {
  36. return results;
  37. }).then(function(results){
  38. instanceWeb.notification.do_warn("Atencion",results.message);
  39. return self.reloadPage();
  40. });
  41. });
  42. },
  43. fetchInvoice: function(id){
  44. var invoice = new instanceWeb.Model('account.invoice');
  45. var fields =['id', 'name', 'state', 'is_interest', 'type'];
  46. var domain=[['id', '=', id]]
  47. return invoice.query(fields).filter(domain).all();
  48. },
  49. /* Verificar interest */
  50. verifyInterestPartner: function(id) {
  51. var bankStatement = new instanceWeb.Model('account.invoice');
  52. return bankStatement.call('eiru_account_interest_verify_invoice',[id],{
  53. context: new instanceWeb.CompoundContext()
  54. });
  55. },
  56. });
  57. if (openerp.web && openerp.web.FormView) {
  58. openerp.web.FormView.include({
  59. load_record: function(record) {
  60. this._super.apply(this, arguments);
  61. if (this.model !== 'account.invoice')
  62. return;
  63. openerp.parentInstanceInterestInvoiceVerify = this;
  64. if (openerp.widgetInstanceInterestInvoiceVerify) {
  65. if (openerp.widgetInstanceInterestInvoiceVerify.id === record.id){
  66. openerp.widgetInstanceInterestInvoiceVerify.id = undefined;
  67. return
  68. }
  69. openerp.widgetInstanceInterestInvoiceVerify.checkState(record.id);
  70. return;
  71. }
  72. openerp.widgetInstanceInterestInvoiceVerify = new openerp.VerifyInterestInvoice(this);
  73. openerp.widgetInstanceInterestInvoiceVerify.checkState(record.id);
  74. }
  75. });
  76. }
  77. })();