implement online order integration between website sales and POS with automated payment and KDS status synchronization

This commit is contained in:
Alaguraj0361 2026-04-10 18:19:43 +05:30
parent 3bc6298559
commit f23b06f571
2 changed files with 24 additions and 6 deletions

View File

@ -45,12 +45,17 @@ class PosOrder(models.Model):
self.ensure_one() self.ensure_one()
self.write({'online_order_status': 'confirmed'}) self.write({'online_order_status': 'confirmed'})
# If it's an online order with an online payment option, mark as paid in POS to avoid confusion # If it's an online order with an online payment, mark as paid in POS to avoid confusion
if self.is_online_order and self.sale_order_id and self.sale_order_id.payment_option == 'online_gateway': is_paid_online = self.sale_order_id.payment_option == 'online_gateway'
if not is_paid_online and self.sale_order_id:
successful_txs = self.sale_order_id.transaction_ids.filtered(lambda tx: tx.state in ['authorized', 'done'])
if successful_txs and sum(successful_txs.mapped('amount')) >= self.sale_order_id.amount_total:
is_paid_online = True
if self.is_online_order and self.sale_order_id and is_paid_online:
# Check if it needs payment (not yet paid in POS) # Check if it needs payment (not yet paid in POS)
if self.state == 'draft' and self.amount_total > 0 and self.amount_paid < self.amount_total: if self.state == 'draft' and self.amount_total > 0 and self.amount_paid < self.amount_total:
# Find a suitable payment method (Online Payment or Stripe) # Find a suitable payment method (Online Payment or Stripe)
# We prioritize methods linked to the current POS config
payment_method = self._get_online_payment_method() payment_method = self._get_online_payment_method()
if payment_method: if payment_method:

View File

@ -112,11 +112,19 @@ class SaleOrderOnline(models.Model):
# Link back to sale order # Link back to sale order
sale_order.write({'pos_order_id': pos_order.id}) sale_order.write({'pos_order_id': pos_order.id})
# If paid online via gateway, record payment in POS immediately # Check if order is already paid online (e.g. Stripe, PayPal, etc.)
if sale_order.payment_option == 'online_gateway' and sale_order.amount_total > 0: # We check both the custom payment_option and Odoo's standard transactions
is_paid_online = sale_order.payment_option == 'online_gateway'
if not is_paid_online:
# Check for successful transactions (authorize or done)
successful_txs = sale_order.transaction_ids.filtered(lambda tx: tx.state in ['authorized', 'done'])
if successful_txs and sum(successful_txs.mapped('amount')) >= sale_order.amount_total:
is_paid_online = True
if is_paid_online and sale_order.amount_total > 0:
payment_method = pos_order._get_online_payment_method() payment_method = pos_order._get_online_payment_method()
if payment_method: if payment_method:
_logger.info("Recording online payment for POS order %s from Sale Order %s", pos_order.name, sale_order.name) _logger.info("Recording confirmed online payment for POS order %s from Sale Order %s", pos_order.name, sale_order.name)
pos_order.env['pos.payment'].create({ pos_order.env['pos.payment'].create({
'amount': sale_order.amount_total, 'amount': sale_order.amount_total,
'payment_date': fields.Datetime.now(), 'payment_date': fields.Datetime.now(),
@ -124,7 +132,12 @@ class SaleOrderOnline(models.Model):
'pos_order_id': pos_order.id, 'pos_order_id': pos_order.id,
}) })
# Process as paid so the state changes and payment button disappears # Process as paid so the state changes and payment button disappears
# We use a delayed call or ensure state is updated
pos_order.action_pos_order_paid() pos_order.action_pos_order_paid()
# Also set the online status to confirmed since it's paid
pos_order.write({'online_order_status': 'confirmed'})
else:
_logger.warning("No suitable POS Payment Method for paid online order %s", pos_order.name)
# Set all lines to a "hold" state - they will go to KDS only when cashier confirms # Set all lines to a "hold" state - they will go to KDS only when cashier confirms
for line in pos_order.lines: for line in pos_order.lines: