- 
                Notifications
    
You must be signed in to change notification settings  - Fork 4
 
Open
Description
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_pricesMetadata
Metadata
Assignees
Labels
No labels