eiru_invoice_status_change.py 751 B

123456789101112131415161718192021222324252627
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models
  3. class InvoiceChangeStatus(models.Model):
  4. _inherit = 'account.invoice'
  5. @api.model
  6. def update_invoice_state(self, ids):
  7. updateInvoice = None
  8. invoiceState = None
  9. accountInvoice = self.env['account.invoice'].browse(ids)
  10. if (not accountInvoice):
  11. return
  12. if (accountInvoice.residual > 0 and accountInvoice.state == 'paid'):
  13. invoiceState = 'open'
  14. if (accountInvoice.residual <= 0 and accountInvoice.state == 'open'):
  15. invoiceState = 'paid'
  16. if (invoiceState):
  17. updateInvoice = accountInvoice.write({'state': invoiceState})
  18. return True if (updateInvoice) else False