Exemple #1
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Convert to dict to easier take config elements
        configuration = {
            item["name"]: item["value"]
            for item in self.configuration
        }

        origin_country = configuration["origin_country"] or ""
        origin_country = countries.alpha2(origin_country.strip())

        countries_from_origin = configuration[
            "countries_to_calculate_taxes_from_origin"]
        countries_from_origin = countries_from_origin or ""
        countries_from_origin = [
            countries.alpha2(c.strip())
            for c in countries_from_origin.split(",")
        ]
        countries_from_origin = list(filter(None, countries_from_origin))

        excluded_countries = configuration["excluded_countries"] or ""
        excluded_countries = [
            countries.alpha2(c.strip()) for c in excluded_countries.split(",")
        ]
        excluded_countries = list(filter(None, excluded_countries))

        self.config = VatlayerConfiguration(
            access_key=configuration["Access key"],
            origin_country=origin_country,
            excluded_countries=excluded_countries,
            countries_from_origin=countries_from_origin,
        )
        self._cached_taxes = {}
Exemple #2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Convert to dict to easier take config elements
        configuration = {item["name"]: item["value"] for item in self.configuration}

        if from_country := configuration["from_country"]:
            from_country = countries.alpha2(from_country.strip())
Exemple #3
0
def populate_proxy_weights(apps, schema_editor):
    db_alias = schema_editor.connection.alias

    # Update countries region Pacific -> Pacific Islands
    CountryRegion = apps.get_model("forms", "CountryRegion")
    CountryRegion.objects.using(db_alias).filter(region="Pacific").update(
        region="Pacific Islands")

    # Update weights to proxy weights pending finalization
    Weights = apps.get_model("reports", "Weights")
    for item in COUNTRY_WEIGHTS:
        country_alpha3 = item.pop("Country")
        country = countries.alpha2(country_alpha3)
        for media_type, weight in item.items():
            Weights.objects.using(db_alias).update_or_create(
                country=country,
                media_type=media_type,
                defaults={"weight": weight})
Exemple #4
0
def update_or_create_weights_from_gsheetweights(instance=None,
                                                created=None,
                                                row_data=None,
                                                **kwargs):
    try:
        country = countries.alpha2(row_data["Country"])
        print_weight = row_data["Print"]
        radio_weight = row_data["Radio"]
        television_weight = row_data["Television"]
        internet_weight = row_data["Internet"]
        twitter_weight = row_data["Twitter"]
        Weights.objects.update_or_create(country=country,
                                         media_type="Print",
                                         defaults={"weight": print_weight})
        Weights.objects.update_or_create(country=country,
                                         media_type="Radio",
                                         defaults={"weight": radio_weight})
        Weights.objects.update_or_create(
            country=country,
            media_type="Television",
            defaults={"weight": television_weight},
        )
        Weights.objects.update_or_create(country=country,
                                         media_type="Internet",
                                         defaults={"weight": internet_weight})
        Weights.objects.update_or_create(country=country,
                                         media_type="Twitter",
                                         defaults={"weight": twitter_weight})
        instance.country = country
        instance.print_weight = print_weight
        instance.radio_weight = radio_weight
        instance.tv_weight = television_weight
        instance.internet_weight = internet_weight
        instance.twitter_weight = twitter_weight
        instance.save()
    except (ObjectDoesNotExist, KeyError):
        pass
Exemple #5
0
 def test_alpha2(self):
     self.assertEqual(countries.alpha2('NZ'), 'NZ')
     self.assertEqual(countries.alpha2('nZ'), 'NZ')
     self.assertEqual(countries.alpha2('Nzl'), 'NZ')
     self.assertEqual(countries.alpha2(554), 'NZ')
     self.assertEqual(countries.alpha2('554'), 'NZ')
 def test_alpha2_override(self):
     with self.settings(COUNTRIES_OVERRIDE={'AU': None}):
         self.assertEqual(countries.alpha2('AU'), '')
 def test_alpha2(self):
     self.assertEqual(countries.alpha2('NZ'), 'NZ')
     self.assertEqual(countries.alpha2('nZ'), 'NZ')
     self.assertEqual(countries.alpha2('Nzl'), 'NZ')
     self.assertEqual(countries.alpha2(554), 'NZ')
     self.assertEqual(countries.alpha2('554'), 'NZ')
 def test_alpha2_override_new(self):
     with self.settings(COUNTRIES_OVERRIDE={"XX": "Neverland"}):
         self.assertEqual(countries.alpha2("XX"), "XX")
Exemple #9
0
def territory_country(territory_code):
    """Return the country associated to a territory code."""
    territory = TERRITORIES.get(territory_code, territory_code)
    return countries.alpha2(territory) or UNKNOWN_COUNTRY_CODE
Exemple #10
0
 def __str__(self):
     # Use translations of django-countries
     country_alpha2 = countries.alpha2(self.code)
     return dict(countries).get(country_alpha2, self.name)
 def test_alpha2(self):
     self.assertEqual(countries.alpha2("NZ"), "NZ")
     self.assertEqual(countries.alpha2("nZ"), "NZ")
     self.assertEqual(countries.alpha2("Nzl"), "NZ")
     self.assertEqual(countries.alpha2(554), "NZ")
     self.assertEqual(countries.alpha2("554"), "NZ")
 def test_alpha2_override_new(self):
     with self.settings(COUNTRIES_OVERRIDE={"XX": "Neverland"}):
         self.assertEqual(countries.alpha2("XX"), "XX")
 def test_alpha2_override(self):
     with self.settings(COUNTRIES_OVERRIDE={"AU": None}):
         self.assertEqual(countries.alpha2("AU"), "")
 def test_alpha2_invalid(self):
     self.assertEqual(countries.alpha2("XX"), "")
 def test_alpha2_invalid(self):
     self.assertEqual(countries.alpha2("XX"), "")
 def test_alpha2_override(self):
     with self.settings(COUNTRIES_OVERRIDE={"AU": None}):
         self.assertEqual(countries.alpha2("AU"), "")
Exemple #17
0
 def test_alpha2_invalid(self):
     self.assertEqual(countries.alpha2('XX'), '')
 def test_alpha2(self):
     self.assertEqual(countries.alpha2("NZ"), "NZ")
     self.assertEqual(countries.alpha2("nZ"), "NZ")
     self.assertEqual(countries.alpha2("Nzl"), "NZ")
     self.assertEqual(countries.alpha2(554), "NZ")
     self.assertEqual(countries.alpha2("554"), "NZ")
Exemple #19
0
 def test_alpha2_override(self):
     with self.settings(COUNTRIES_OVERRIDE={'AU': None}):
         self.assertEqual(countries.alpha2('AU'), '')
 def test_alpha2_invalid(self):
     self.assertEqual(countries.alpha2('XX'), '')
Exemple #21
0
 def test_alpha2_override_new(self):
     with self.settings(COUNTRIES_OVERRIDE={'XX': 'Neverland'}):
         self.assertEqual(countries.alpha2('XX'), 'XX')
 def test_alpha2_override_new(self):
     with self.settings(COUNTRIES_OVERRIDE={'XX': 'Neverland'}):
         self.assertEqual(countries.alpha2('XX'), 'XX')
Exemple #23
0
def territory_country(territory_code):
    """Return the country associated to a territory code."""
    territory = TERRITORIES.get(territory_code, territory_code)
    return countries.alpha2(territory) or UNKNOWN_COUNTRY_CODE