from pathlib import Path


def test_opportunity_odoo_panel_has_manual_sale_link_form():
    text = Path('app/admin_ui/pages/opportunities.py').read_text()
    assert '/odoo/link-sale' in text
    assert 'sale_ref' in text
    assert 'Registar venda Odoo' in text
    assert 'PREPARE_ORDER' in text
    assert "action_code = 'PREPARE_ORDER'" in text


def test_cockpit_prepare_order_is_real_form_not_anchor_only():
    text = Path('app/admin_dashboard.py').read_text()
    assert 'action_code == "PREPARE_ORDER"' in text
    assert '/odoo/link-sale' in text
    assert 'Venda Odoo ex.: S00308' in text


def test_operation_service_closes_prepare_order_and_syncs_odoo():
    text = Path('app/operation_service.py').read_text()
    assert 'ClientFlow prepare-order task cleanup failed' in text
    assert "action_code = 'PREPARE_ORDER'" in text
    assert 'sync_opportunity_odoo_status' in text
