import logging _logger = logging.getLogger('poynt_process') Batch = env['poynt.settlement.batch'].sudo() batches = Batch.search([('state', '=', 'draft')], order='transaction_date asc') print(f'Processing {len(batches)} batches', flush=True) total_paid = 0 total_errors = 0 processed = 0 for batch in batches: payable = batch.line_ids.filtered( lambda l: l.partner_id and l.action == 'SALE' and l.state == 'matched' and not l.payment_id ) if not payable: processed += 1 continue try: batch.action_create_payments() paid = len(batch.line_ids.filtered(lambda l: l.state == 'paid')) errs = len(batch.line_ids.filtered(lambda l: l.state == 'error')) total_paid += paid total_errors += errs except Exception as e: total_errors += len(payable) if total_errors <= 5: print(f' Batch {batch.name} error: {e}', flush=True) processed += 1 if processed % 30 == 0: env.cr.commit() print(f' Progress: {processed}/{len(batches)}, paid={total_paid}, errors={total_errors}', flush=True) env.cr.commit() print(f'\nDONE:', flush=True) print(f' Batches processed: {processed}', flush=True) print(f' Payments created: {total_paid}', flush=True) print(f' Errors: {total_errors}', flush=True) # Final state for state in ['draft', 'matched', 'reconciled', 'error']: cnt = Batch.search_count([('state', '=', state)]) if cnt: print(f' Batches {state}: {cnt}', flush=True)