24 lines
958 B
Python
24 lines
958 B
Python
from odoo import models, fields, api, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
class PosPayment(models.Model):
|
|
_inherit = 'pos.payment'
|
|
|
|
def write(self, vals):
|
|
if 'payment_method_id' in vals:
|
|
# Check if current user is not a POS Manager
|
|
if not self.env.user.has_group('point_of_sale.group_pos_manager'):
|
|
raise ValidationError(_(
|
|
"Only POS Managers are allowed to edit payment methods."
|
|
))
|
|
|
|
for payment in self:
|
|
# Enforce the validation rules
|
|
if not payment.pos_order_id.is_payment_editable:
|
|
raise ValidationError(_(
|
|
"You cannot edit the payment method because the POS session is closed "
|
|
"or the accounting journal has already been posted."
|
|
))
|
|
|
|
return super(PosPayment, self).write(vals)
|