pos_edit_payment_method/models/pos_order.py
2026-05-21 09:41:38 +07:00

34 lines
1.4 KiB
Python

from odoo import models, fields, api
class PosOrder(models.Model):
_inherit = 'pos.order'
is_payment_editable = fields.Boolean(
compute='_compute_is_payment_editable',
string='Is Payment Editable'
)
@api.depends('session_id.state', 'state', 'account_move', 'payment_ids.account_move_id.state')
def _compute_is_payment_editable(self):
is_manager = self.env.user.has_group('point_of_sale.group_pos_manager')
for order in self:
# Only POS Managers can edit
if not is_manager:
order.is_payment_editable = False
# 1. POS session must not be closed
elif order.session_id.state == 'closed':
order.is_payment_editable = False
# 2. POS order state must not be done or cancel
elif order.state in ('done', 'cancel'):
order.is_payment_editable = False
# 3. Order must not have a posted invoice
elif order.account_move and order.account_move.state == 'posted':
order.is_payment_editable = False
else:
# 4. None of the payments must have a posted accounting journal entry (account_move_id)
is_any_payment_posted = any(
p.account_move_id and p.account_move_id.state == 'posted'
for p in order.payment_ids
)
order.is_payment_editable = not is_any_payment_posted