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.

46 lines
1.8 KiB

  1. # Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import _, api, fields, models
  5. from odoo.exceptions import ValidationError
  6. class PosConfig(models.Model):
  7. _inherit = "pos.config"
  8. _PAYMENT_CHANGE_POLICY_SELECTION = [
  9. ('refund', "Refund and Resale"),
  10. ('update', "Update Payments"),
  11. ]
  12. payment_change_policy = fields.Selection(
  13. selection=_PAYMENT_CHANGE_POLICY_SELECTION,
  14. default="refund", required=True,
  15. help="Payment Change Policy when users want"
  16. " to change the payment lines of a given PoS Order.\n"
  17. "* 'Refund and Resale': Odoo will refund the current"
  18. " Pos Order to cancel it, and create a new PoS Order"
  19. " with the correct payment lines.\n"
  20. "* 'Update Payments': Odoo will change payment lines.\n\n"
  21. "Note : In some countries the 'Update Payments' Option"
  22. " is not allowed by law, because orders history shouldn't"
  23. " not be altered.")
  24. @api.constrains("payment_change_policy")
  25. def _check_payment_change_policy(self):
  26. # Check if certification module is installed
  27. # and if yes, if 'update payments' option is allowed
  28. module_states = self.env["ir.module.module"].sudo().search([
  29. ("name", "=", "l10n_fr_certification")]
  30. ).mapped("state")
  31. if "installed" not in module_states:
  32. return
  33. for config in self.filtered(
  34. lambda x: x.payment_change_policy == "update"
  35. ):
  36. if config.company_id._is_accounting_unalterable():
  37. raise ValidationError(_(
  38. "Unable to use the 'Update Payments' options"
  39. " for companies that have unalterable accounting."
  40. ))