Exemple #1
0
    def create_document(self):
        # Create the document
        my_document = Document(self)

        my_document.check_for_quotas()

        # Create the measures table
        my_document.get_duties("preferences")
        tariff_data = my_document.print_tariffs()

        # Create the quotas table
        my_document.get_duties("quotas")
        my_document.get_quota_order_numbers()
        my_document.get_quota_balances()
        my_document.get_quota_measures()
        my_document.get_quota_definitions()
        quota_data = my_document.print_quotas()

        context_data = {
            'AGREEMENT_NAME': self.agreement.agreement_name,
            'VERSION': self.agreement.version,
            'AGREEMENT_DATE': self.agreement.agreement_date_long,
            'AGREEMENT_DATE_SHORT': self.agreement.agreement_date_short,
            'COUNTRY_NAME': self.agreement.country_name,
            **tariff_data,
            **quota_data,
        }

        # Personalise and write the document
        my_document.create_document(context_data)
        update_document_status(self.agreement, DocumentStatus.AVAILABLE)
def test_get_quota_definitions_when_has_quotas(
    mock_execute_sql,
    has_quotas,
    called_execute_sql,
):
    mock_execute_sql.return_value = []
    application = mock.MagicMock(country_name='spain',
                                 execute_sql=mock_execute_sql)
    document = Document(application)
    document.has_quotas = has_quotas
    document.q = []
    document.quota_order_number_list = []
    document.get_quota_definitions()
    assert mock_execute_sql.called is called_execute_sql
def test_get_quota_definitions(quota_order_number_id, add_balance,
                               expected_quota_order_number_sid,
                               expected_definition):
    geographical_area_id = '1011'
    country_profile = 'spain'

    quota_order_number = QuotaOrderNumberFactory(
        id=quota_order_number_id,
        quota_order_number_sid=str(quota_order_number_id))
    if not quota_order_number_id.startswith('094'):
        QuotaDefinitionFactory(
            quota_order_number_id=quota_order_number.id,
            quota_order_number_sid=quota_order_number.quota_order_number_sid,
            initial_volume=2000,
            volume=3000,
            measurement_unit_code='')

    AgreementFactory(country_name=country_profile.capitalize(),
                     slug=country_profile,
                     country_codes=[geographical_area_id])
    application = Application(country_profile=country_profile)

    document = Document(application)
    document.has_quotas = True

    if add_balance:
        qb = get_quota_balance(
            quota_order_number_id=quota_order_number.quota_order_number_id,
            y1_balance=6000,
        )
        document.balance_dict[quota_order_number.quota_order_number_id] = qb

    document.q = [quota_order_number.quota_order_number_id]
    qon = QuotaOrderNumber(quota_order_number.quota_order_number_id)
    assert document.quota_definition_list == []
    document.quota_order_number_list = [qon]
    document.get_quota_definitions()
    assert len(qon.quota_definition_list) == 1
    assert qon.quota_definition_list[0].quota_order_number_id == str(
        quota_order_number_id)
    assert len(document.quota_definition_list) == 1
    assert_object(document.quota_definition_list[0], expected_definition)