Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basket line shows warning about price change since adding to basket in wrong currency #8

Open
dismine opened this issue Sep 18, 2020 · 0 comments

Comments

@dismine
Copy link

dismine commented Sep 18, 2020

Hi,

I have found uncovered case. When add a product to a basket and then change its price next time you open a basket you will see a warning about changing in price. The price will be in the wrong currency. This happens because the method get_warning doesn't take into account the line currency and asummes it always default.

The solution is to override the method and pass correct currency.

# apps/basket/models.py

class Line(AbstractLine):
    def get_warning(self):
        """
        Return a warning message about this basket line if one is applicable

        This could be things like the price has changed
        """
        if isinstance(self.purchase_info.availability, Unavailable):
            msg = "'%(product)s' is no longer available"
            return _(msg) % {'product': self.product.get_title()}

        if not self.price_incl_tax:
            return
        if not self.purchase_info.price.is_tax_known:
            return

        # Compare current price to price when added to basket
        current_price_incl_tax = self.purchase_info.price.incl_tax
        if current_price_incl_tax != self.price_incl_tax:
            product_prices = {
                'product': self.product.get_title(),
                'old_price': currency(self.price_incl_tax, self.price_currency),  # pass the line price currency
                'new_price': currency(current_price_incl_tax, self.price_currency)  # pass the line price currency
            }
            if current_price_incl_tax > self.price_incl_tax:
                warning = _("The price of '%(product)s' has increased from"
                            " %(old_price)s to %(new_price)s since you added"
                            " it to your basket")
                return warning % product_prices
            else:
                warning = _("The price of '%(product)s' has decreased from"
                            " %(old_price)s to %(new_price)s since you added"
                            " it to your basket")
                return warning % product_prices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant