diff --git a/addons/dine360_online_orders/models/pos_order.py b/addons/dine360_online_orders/models/pos_order.py index 7fa6131..4ce57bf 100644 --- a/addons/dine360_online_orders/models/pos_order.py +++ b/addons/dine360_online_orders/models/pos_order.py @@ -45,12 +45,17 @@ class PosOrder(models.Model): self.ensure_one() 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 self.is_online_order and self.sale_order_id and self.sale_order_id.payment_option == 'online_gateway': + # If it's an online order with an online payment, mark as paid in POS to avoid confusion + 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) 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) - # We prioritize methods linked to the current POS config payment_method = self._get_online_payment_method() if payment_method: diff --git a/addons/dine360_online_orders/models/sale_order.py b/addons/dine360_online_orders/models/sale_order.py index 65bed73..cde5157 100644 --- a/addons/dine360_online_orders/models/sale_order.py +++ b/addons/dine360_online_orders/models/sale_order.py @@ -112,11 +112,19 @@ class SaleOrderOnline(models.Model): # Link back to sale order sale_order.write({'pos_order_id': pos_order.id}) - # If paid online via gateway, record payment in POS immediately - if sale_order.payment_option == 'online_gateway' and sale_order.amount_total > 0: + # Check if order is already paid online (e.g. Stripe, PayPal, etc.) + # 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() 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({ 'amount': sale_order.amount_total, 'payment_date': fields.Datetime.now(), @@ -124,7 +132,12 @@ class SaleOrderOnline(models.Model): 'pos_order_id': pos_order.id, }) # 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() + # 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 for line in pos_order.lines: