Exemple #1
0
 def decode(self, obj):
     if len(obj) == 1:
         tag, val = first(obj.items())
         info = self.tags.get(tag)
         if info:
             return info["decoder"](val)
     return obj
Exemple #2
0
def get_taxes_of_effective_rules(taxing_context, tax_rules):
    """
    Get taxes grouped by priority from effective tax rules.

    Effective tax rules is determined by first limiting the scope to the
    rules that match the given taxing context (see `TaxRule.match`) and
    then further limiting the matching rules by selecting only the rules
    in the highest numbered override group.

    The `Tax` objects in the effective rules will be grouped by the
    priority of the rules.  The tax groups are returned as list of tax
    lists.

    :type taxing_context: shoop.core.taxing.TaxingContext
    :param tax_rules:
      Tax rules to filter from.  These should be ordered desceding by
      override group and then ascending by priority.
    :type tax_rules: Iterable[TaxRule]
    :rtype: list[list[shoop.core.models.Tax]]
    """
    # Limit our scope to only matching rules
    matching_rules = (tax_rule for tax_rule in tax_rules
                      if tax_rule.matches(taxing_context))

    # Further limit our scope to the highest numbered override group
    grouped_by_override = groupby(matching_rules, attrgetter('override_group'))
    highest_override_group = first(grouped_by_override, (None, []))[1]

    # Group rules by priority
    grouped_rules = groupby(highest_override_group, attrgetter('priority'))
    tax_groups = [[rule.tax for rule in rules] for (_, rules) in grouped_rules]

    return tax_groups
Exemple #3
0
 def decode(self, obj):
     if len(obj) == 1:
         tag, val = first(obj.items())
         info = self.tags.get(tag)
         if info:
             return info["decoder"](val)
     return obj
Exemple #4
0
def _calculate_taxes(price, taxing_context, tax_class):
    customer_tax_group = taxing_context.customer_tax_group
    # Check tax exempt
    # TODO: Should this be done in some better way?
    if customer_tax_group and customer_tax_group.identifier == 'tax_exempt':
        return taxing.TaxedPrice(
            TaxfulPrice(price.amount), TaxlessPrice(price.amount), []
        )

    tax_rules = TaxRule.objects.filter(enabled=True, tax_classes=tax_class)
    if customer_tax_group:
        tax_rules = tax_rules.filter(customer_tax_groups=customer_tax_group)
    tax_rules = tax_rules.order_by("-priority")  # TODO: Do the Right Thing with priority
    taxes = [tax_rule for tax_rule in tax_rules if tax_rule.matches(taxing_context)]
    tax_rule = first(taxes)  # TODO: Do something better than just using the first tax!
    tax = getattr(tax_rule, "tax", None)
    return stacked_value_added_taxes(price, [tax] if tax else [])
Exemple #5
0
    def get_method_checkout_phase_object(self):
        """
        :rtype: shoop.front.checkout.CheckoutPhaseViewMixin|None
        """
        if hasattr(self, "_checkout_phase_object"):
            return self._checkout_phase_object

        meth = self.get_method()
        if not meth:
            return None
        phases = get_checkout_phases_for_service(self.checkout_process, meth)
        phase = first(phases)
        if not phase:
            return None
        phase = self.checkout_process.add_phase_attributes(phase, self)
        self._checkout_phase_object = phase
        return phase
Exemple #6
0
def _calculate_taxes(price, taxing_context, tax_class):
    customer_tax_group = taxing_context.customer_tax_group
    # Check tax exempt
    # TODO: Should this be done in some better way?
    if customer_tax_group and customer_tax_group.identifier == 'tax_exempt':
        return taxing.TaxedPrice(
            TaxfulPrice(price.amount), TaxlessPrice(price.amount), []
        )

    tax_rules = TaxRule.objects.filter(enabled=True, tax_classes=tax_class)
    if customer_tax_group:
        tax_rules = tax_rules.filter(customer_tax_groups=customer_tax_group)
    tax_rules = tax_rules.order_by("-priority")  # TODO: Do the Right Thing with priority
    taxes = [tax_rule for tax_rule in tax_rules if tax_rule.matches(taxing_context)]
    tax_rule = first(taxes)  # TODO: Do something better than just using the first tax!
    tax = getattr(tax_rule, "tax", None)
    return stacked_value_added_taxes(price, [tax] if tax else [])
Exemple #7
0
    def get_method_checkout_phase_object(self):
        """
        :rtype: shoop.front.checkout.CheckoutPhaseViewMixin|None
        """
        if hasattr(self, "_checkout_phase_object"):
            return self._checkout_phase_object

        method = self.get_method()
        if not method:
            return None
        phases = get_checkout_phases_for_service(self.checkout_process, method)
        phase = first(phases)
        if not phase:
            return None
        phase = self.checkout_process.add_phase_attributes(phase, self)
        self._checkout_phase_object = phase
        return phase
Exemple #8
0
    def get_context_data(self, **kwargs):
        context = super(AddonUploadConfirmView, self).get_context_data(**kwargs)

        with zipfile.ZipFile(self.get_addon_path()) as zf:
            context["filenames"] = sorted(zf.namelist())
            pkg_info_path = first(filename for filename in context["filenames"] if filename.endswith("PKG-INFO"))
            if pkg_info_path:
                context["pkg_info"] = zf.read(pkg_info_path).decode("UTF-8", "replace")

        context["toolbar"] = Toolbar([
            PostActionButton(
                icon="fa fa-download",
                form_id="install_form",
                text=_("Install Addon"),
                extra_css_class="btn-success",
            )
        ])
        return context
Exemple #9
0
    def get_context_data(self, **kwargs):
        context = super(AddonUploadConfirmView,
                        self).get_context_data(**kwargs)

        with zipfile.ZipFile(self.get_addon_path()) as zf:
            context["filenames"] = sorted(zf.namelist())
            pkg_info_path = first(filename for filename in context["filenames"]
                                  if filename.endswith("PKG-INFO"))
            if pkg_info_path:
                context["pkg_info"] = zf.read(pkg_info_path).decode(
                    "UTF-8", "replace")

        context["toolbar"] = Toolbar([
            PostActionButton(
                icon="fa fa-download",
                form_id="install_form",
                text=_("Install Addon"),
                extra_css_class="btn-success",
            )
        ])
        return context
Exemple #10
0
def get_taxes_of_effective_rules(taxing_context, tax_rules):
    """
    Get taxes grouped by priority from effective tax rules.

    Effective tax rules is determined by first limiting the scope to the
    rules that match the given taxing context (see `TaxRule.match`) and
    then further limiting the matching rules by selecting only the rules
    in the highest numbered override group.

    The `Tax` objects in the effective rules will be grouped by the
    priority of the rules.  The tax groups are returned as list of tax
    lists.

    :type taxing_context: shoop.core.taxing.TaxingContext
    :param tax_rules:
      Tax rules to filter from.  These should be ordered desceding by
      override group and then ascending by priority.
    :type tax_rules: Iterable[TaxRule]
    :rtype: list[list[shoop.core.models.Tax]]
    """
    # Limit our scope to only matching rules
    matching_rules = (
        tax_rule for tax_rule in tax_rules
        if tax_rule.matches(taxing_context))

    # Further limit our scope to the highest numbered override group
    grouped_by_override = groupby(matching_rules, attrgetter('override_group'))
    highest_override_group = first(grouped_by_override, (None, []))[1]

    # Group rules by priority
    grouped_rules = groupby(highest_override_group, attrgetter('priority'))
    tax_groups = [
        [rule.tax for rule in rules]
        for (_, rules) in grouped_rules]

    return tax_groups
Exemple #11
0
 def get_selected_reload_method(self):
     return first(rm for rm in self.reload_methods if rm.identifier == self.cleaned_data["reload_method"])
Exemple #12
0
 def get_selected_reload_method(self):
     return first(rm for rm in self.reload_methods
                  if rm.identifier == self.cleaned_data["reload_method"])
Exemple #13
0
 def get_by_object(self, obj):
     return first(fi for fi in self.values() if isinstance(obj, fi.model))
Exemple #14
0
 def get_by_object(self, obj):
     return first(
         fi for fi in self.values() if isinstance(obj, fi.model))