コード例 #1
0
ファイル: tagged_json.py プロジェクト: jaywink/shoop
 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
コード例 #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
コード例 #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
コード例 #4
0
ファイル: module.py プロジェクト: charn/shoop
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 [])
コード例 #5
0
ファイル: methods.py プロジェクト: MUDASSARHASHMI/shoop
    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
コード例 #6
0
ファイル: module.py プロジェクト: sidaga/shoop
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 [])
コード例 #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
コード例 #8
0
ファイル: upload.py プロジェクト: 00WhengWheng/shuup
    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
コード例 #9
0
ファイル: upload.py プロジェクト: sidaga/shoop
    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
コード例 #10
0
ファイル: module.py プロジェクト: menchester5/shoop
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
コード例 #11
0
ファイル: reload.py プロジェクト: DemOneEh/shoop
 def get_selected_reload_method(self):
     return first(rm for rm in self.reload_methods if rm.identifier == self.cleaned_data["reload_method"])
コード例 #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"])
コード例 #13
0
 def get_by_object(self, obj):
     return first(fi for fi in self.values() if isinstance(obj, fi.model))
コード例 #14
0
ファイル: _edit.py プロジェクト: 00WhengWheng/shuup
 def get_by_object(self, obj):
     return first(
         fi for fi in self.values() if isinstance(obj, fi.model))