def test_create_quotation_has_quotation_id(service: RegisterReservationInOdoo, context: Context, house, reservation):
    context.house = house
    context.reservation = attr.evolve(reservation, quotation_id=123)
    context.api = Mock(create_quotation=Mock(side_effect=RuntimeError('ERR')))

    result = service.create_quotation(context)
    assert is_successful(result)

    context.api.create_quotation.assert_not_called()
def test_create_quotation_fail(service: RegisterReservationInOdoo, context: Context, house, reservation, user):
    context.house = house
    context.user = user
    context.reservation = attr.evolve(reservation, guest_contact_id=222, opportunity_id=333)
    context.api = Mock(create_quotation=Mock(return_value=Nothing))

    result = service.create_quotation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert result.failure().error.startswith('Error create Quotation for Reservation ID=')
def test_create_quotation_error(service: RegisterReservationInOdoo, context: Context, house, reservation, user):
    context.house = house
    context.user = user
    context.reservation = attr.evolve(reservation, guest_contact_id=222, opportunity_id=333)
    context.api = Mock(create_quotation=Mock(side_effect=RuntimeError('ERR')))

    result = service.create_quotation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'
def test_create_quotation_ok(
    service: RegisterReservationInOdoo, context: Context, house, reservation, room_type, user
):
    context.house = house
    context.user = user
    context.reservation = attr.evolve(reservation, guest_contact_id=222, opportunity_id=333)
    context.api = Mock(create_quotation=Mock(return_value=Some(123)))

    result = service.create_quotation(context)
    assert is_successful(result)
    assert result.unwrap().reservation.quotation_id == 123

    context.api.create_quotation.assert_called_once_with(
        {
            'partner_id': 222,
            'partner_invoice_id': 222,
            'partner_shipping_id': 222,
            'user_id': user.odoo_id,
            'currency_id': house.currency.odoo_id,
            'note': '',
            'company_id': house.odoo_id,
            'team_id': CrmTeams.SALES.value,
            'opportunity_id': 333,
            'report_grids': True,
            'origin': reservation.id,
            'client_order_ref': '',
        },
        [
            {
                'price_unit': '1120',
                'order_partner_id': 222,
                'discount': 0.,
                'product_id': room_type.id,
                'product_uom_qty': 1,
                'item_date': reservation.checkin.strftime(DATE_FORMAT),
            },
            {
                'price_unit': '1120',
                'order_partner_id': 222,
                'discount': 0.,
                'product_id': room_type.id,
                'product_uom_qty': 1,
                'item_date': (reservation.checkin + datetime.timedelta(days=1)).strftime(DATE_FORMAT),
            },
            {
                'price_unit': '1120',
                'order_partner_id': 222,
                'discount': 0.,
                'product_id': room_type.id,
                'product_uom_qty': 1,
                'item_date': (reservation.checkin + datetime.timedelta(days=2)).strftime(DATE_FORMAT),
            },
        ]
    )