LaOsaCoop/Odoo16#14 migration pos_customer_required
This commit is contained in:
parent
b062c383d5
commit
08fca37c6d
27 changed files with 1438 additions and 0 deletions
4
pos_customer_required/models/__init__.py
Normal file
4
pos_customer_required/models/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from . import pos_config
|
||||
from . import pos_order
|
||||
from . import pos_make_payment
|
||||
from . import res_config_setting
|
||||
24
pos_customer_required/models/pos_config.py
Normal file
24
pos_customer_required/models/pos_config.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Copyright 2004 apertoso NV - Jos DE GRAEVE <Jos.DeGraeve@apertoso.be>
|
||||
# Copyright 2016 La Louve - Sylvain LE GAL <https://twitter.com/legalsylvain>
|
||||
# Copyright 2019 Druidoo - (https://www.druidoo.io)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PosConfig(models.Model):
|
||||
_inherit = "pos.config"
|
||||
|
||||
require_customer = fields.Selection(
|
||||
[
|
||||
("no", "Optional"),
|
||||
("payment", "Required before paying"),
|
||||
("order", "Required before starting the order"),
|
||||
],
|
||||
string="Require Customer",
|
||||
default="no",
|
||||
help="Require customer for orders in this point of sale:\n"
|
||||
"* 'Optional' (customer is optional);\n"
|
||||
"* 'Required before paying';\n"
|
||||
"* 'Required before starting the order';",
|
||||
)
|
||||
29
pos_customer_required/models/pos_make_payment.py
Normal file
29
pos_customer_required/models/pos_make_payment.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright 2016 La Louve - Sylvain LE GAL <https://twitter.com/legalsylvain>
|
||||
# Copyright 2019 Druidoo - (https://www.druidoo.io)
|
||||
# Copyright 2022 NuoBiT - Eric Antones <eantones@nuobit.com>
|
||||
# Copyright 2022 NuoBiT - Kilian Niubo <kniubo@nuobit.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class PosMakePayment(models.TransientModel):
|
||||
_inherit = "pos.make.payment"
|
||||
|
||||
def check(self):
|
||||
# Load current order
|
||||
order_obj = self.env["pos.order"]
|
||||
order = order_obj.browse(self.env.context.get("active_id", False))
|
||||
|
||||
# Check if control is required
|
||||
if not order.partner_id and order.session_id.config_id.require_customer != "no":
|
||||
raise UserError(
|
||||
_(
|
||||
"An anonymous order cannot be confirmed.\n"
|
||||
"Please select a customer for this order."
|
||||
)
|
||||
)
|
||||
|
||||
return super(PosMakePayment, self).check()
|
||||
22
pos_customer_required/models/pos_order.py
Normal file
22
pos_customer_required/models/pos_order.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Copyright 2004 apertoso NV - Jos DE GRAEVE <Jos.DeGraeve@apertoso.be>
|
||||
# Copyright 2016 La Louve - Sylvain LE GAL <https://twitter.com/legalsylvain>
|
||||
# Copyright 2019 Druidoo - (https://www.druidoo.io)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo import _, api, exceptions, fields, models
|
||||
|
||||
|
||||
class PosOrder(models.Model):
|
||||
_inherit = "pos.order"
|
||||
|
||||
require_customer = fields.Selection(
|
||||
related="session_id.config_id.require_customer",
|
||||
)
|
||||
|
||||
@api.constrains("partner_id", "session_id")
|
||||
def _check_partner(self):
|
||||
for rec in self:
|
||||
if rec.require_customer != "no" and not rec.partner_id:
|
||||
raise exceptions.ValidationError(
|
||||
_("Customer is required for this order and is missing.")
|
||||
)
|
||||
11
pos_customer_required/models/res_config_setting.py
Normal file
11
pos_customer_required/models/res_config_setting.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
require_customer = fields.Selection(
|
||||
related="pos_config_id.require_customer",
|
||||
readonly=False,
|
||||
help="Require customer in Point of Sale",
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue