#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Verificar estado de orden después de cancelar """ import odoo def verify_order_state(cr): """Verificar que el estado de la orden cambia correctamente""" env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) # Buscar datos necesarios patient = env['res.partner'].search([('is_patient', '=', True)], limit=1) analysis = env['product.product'].search([('is_analysis', '=', True)], limit=1) # Crear orden simple order = env['sale.order'].create({ 'partner_id': patient.id, 'is_lab_request': True, 'order_line': [(0, 0, { 'product_id': analysis.id, 'product_uom_qty': 1.0 })] }) print(f"Orden creada: {order.name}") print(f"Estado inicial: {order.state}") # Confirmar order.action_confirm() print(f"Estado después de confirmar: {order.state}") # Cancelar order.action_cancel() print(f"Estado después de cancelar: {order.state}") # Verificar nuevamente order_check = env['sale.order'].browse(order.id) print(f"Estado verificado nuevamente: {order_check.state}") if __name__ == '__main__': db_name = 'lims_demo' try: registry = odoo.modules.registry.Registry(db_name) with registry.cursor() as cr: verify_order_state(cr) except Exception as e: print(f"Error: {e}")