You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB

  1. # Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
  2. # @author: Julien WESTE
  3. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import _, api, fields, models
  6. from odoo.exceptions import Warning as UserError
  7. class AccountInvoice(models.Model):
  8. _inherit = 'account.invoice'
  9. pos_pending_payment = fields.Boolean(
  10. string='PoS - Pending Payment', readonly=True,
  11. oldname='forbid_payment',
  12. help="Indicates an invoice for which there are pending payments in the"
  13. " Point of Sale. \nThe invoice will be marked as paid when the session"
  14. " will be closed.")
  15. # Overload Section
  16. @api.multi
  17. def action_cancel(self):
  18. self._check_pos_pending_payment()
  19. return super(AccountInvoice, self).action_cancel()
  20. @api.multi
  21. def _get_outstanding_info_JSON(self):
  22. self.ensure_one()
  23. if self.pos_pending_payment:
  24. return
  25. else:
  26. return super()._get_outstanding_info_JSON()
  27. @api.multi
  28. def _check_pos_pending_payment(self):
  29. invoices = self.filtered(lambda x: x.pos_pending_payment)
  30. if invoices:
  31. raise UserError(_(
  32. "You can not realize this action on the invoice(s) %s because"
  33. " there are pending payments in the Point of Sale.") % (
  34. ', '.join(invoices.mapped('name'))))