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.

34 lines
1.3 KiB

  1. # Copyright (C) 2004-Today Apertoso NV (<http://www.apertoso.be>)
  2. # Copyright (C) 2016-Today: La Louve (<http://www.lalouve.net/>)
  3. # Copyright (C) 2019-Today: Druidoo (<https://www.druidoo.io>)
  4. # @author: Jos DE GRAEVE (<Jos.DeGraeve@apertoso.be>)
  5. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  6. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  7. from odoo import fields, models, exceptions, api, _
  8. class PosOrder(models.Model):
  9. _inherit = 'pos.order'
  10. @api.multi
  11. @api.depends('session_id.config_id.require_customer')
  12. def compute_require_customer(self):
  13. for order in self:
  14. order.require_customer = (
  15. order.session_id.config_id.require_customer == 'order')
  16. require_customer = fields.Boolean(
  17. compute='compute_require_customer', string='Require customer',
  18. help="True if a customer is required to begin the order.\n"
  19. "See the PoS Config to change this setting")
  20. @api.constrains('partner_id', 'require_customer')
  21. def _check_partner(self):
  22. for rec in self:
  23. if (
  24. rec.session_id.config_id.require_customer == 'order' and
  25. not rec.partner_id
  26. ):
  27. raise exceptions.ValidationError(_(
  28. 'Customer is required for this order and is missing.'))