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.

102 lines
3.9 KiB

  1. # © 2014-2016 Aurélien DUMAINE
  2. # © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import _, api, fields, models
  5. from odoo.exceptions import ValidationError
  6. class PosConfig(models.Model):
  7. _inherit = "pos.config"
  8. _CUSTOMER_DISPLAY_FORMAT_SELECTION = [
  9. ("2_20", "2 Lines of 20 Characters"),
  10. ]
  11. iface_customer_display = fields.Boolean(
  12. string="LED Customer Display",
  13. help="Display data on the customer display"
  14. )
  15. customer_display_format = fields.Selection(
  16. selection=_CUSTOMER_DISPLAY_FORMAT_SELECTION,
  17. string="Customer Display Format",
  18. default="2_20", required=True)
  19. customer_display_line_length = fields.Integer(
  20. string="Line Length",
  21. compute="_compute_customer_display_line_length",
  22. store=True,
  23. help="Length of the LEDs lines of the customer display",
  24. )
  25. customer_display_msg_next_l1 = fields.Char(
  26. string="Next Customer (Line 1)",
  27. default=lambda x: x._default_customer_display_msg("next_l1"),
  28. help="First line of the message on the customer display which is "
  29. "displayed after starting POS and also after validation of an order",
  30. )
  31. customer_display_msg_next_l2 = fields.Char(
  32. string="Next Customer (Line 2)",
  33. default=lambda x: x._default_customer_display_msg("next_l2"),
  34. help="Second line of the message on the customer display which is "
  35. "displayed after starting POS and also after validation of an order",
  36. )
  37. customer_display_msg_closed_l1 = fields.Char(
  38. string="PoS Closed (Line 1)",
  39. default=lambda x: x._default_customer_display_msg("closed_l1"),
  40. help="First line of the message on the customer display which "
  41. "is displayed when POS is closed",
  42. )
  43. customer_display_msg_closed_l2 = fields.Char(
  44. string="PoS Closed (Line 2)",
  45. default=lambda x: x._default_customer_display_msg("closed_l1"),
  46. help="Second line of the message on the customer display which "
  47. "is displayed when POS is closed",
  48. )
  49. @api.model
  50. def _default_customer_display_msg(self, line):
  51. if line == "next_l1":
  52. return _("Point of Sale Open")
  53. elif line == "next_l2":
  54. return _("Welcome!")
  55. elif line == "closed_l1":
  56. return _("Point of Sale Closed")
  57. elif line == "closed_l2":
  58. return _("See you soon!")
  59. @api.depends("customer_display_format")
  60. def _compute_customer_display_line_length(self):
  61. for config in self:
  62. config.customer_display_line_length = int(
  63. config.customer_display_format.split("_")[1])
  64. @api.constrains(
  65. "iface_customer_display",
  66. "customer_display_format",
  67. "customer_display_msg_next_l1",
  68. "customer_display_msg_next_l2",
  69. "customer_display_msg_closed_l1",
  70. "customer_display_msg_closed_l2",
  71. )
  72. def _check_customer_display_length(self):
  73. for config in self.filtered(lambda x: x.customer_display_line_length):
  74. maxsize = config.customer_display_line_length
  75. fields_to_check = [
  76. x for x in self._fields.keys()
  77. if 'customer_display_msg_' in x
  78. ]
  79. for field_name in fields_to_check:
  80. value = getattr(config, field_name)
  81. if value and len(value) > maxsize:
  82. raise ValidationError(
  83. _(
  84. "The message for customer display '%s' is too "
  85. "long: it has %d chars whereas the maximum "
  86. "is %d chars."
  87. )
  88. % (
  89. self._fields[field_name].string,
  90. len(value),
  91. maxsize)
  92. )