Changeset - bd39609a3d1b
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 years ago 2021-09-25 14:26:20
lance@edbob.org
Add `render_price()` method for products handler

so that it can be invoked from multiple web views
1 file changed with 29 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/products.py
Show inline comments
 
@@ -59,6 +59,35 @@ class ProductsHandler(GenericHandler):
 
        if upc:
 
            return pod.get_image_url(self.config, upc)
 

	
 
    def render_price(self, price, html=False, **kwargs):
 
        """
 
        Render the given ``price`` object as text.
 

	
 
        :returns: String containing the rendered price, or ``None`` if
 
           nothing was applicable.
 
        """
 
        if price.price is not None and price.pack_price is not None:
 
            if price.multiple > 1:
 
                return "{} / {}  ({} / {})".format(
 
                    self.app.render_currency(price.price),
 
                    price.multiple,
 
                    self.app.render_currency(price.pack_price),
 
                    price.pack_multiple)
 
            return "{}  ({} / {})".format(
 
                self.app.render_currency(price.price),
 
                self.app.render_currency(price.pack_price),
 
                price.pack_multiple)
 
        if price.price is not None:
 
            if price.multiple is not None and price.multiple > 1:
 
                return "{} / {}".format(
 
                    self.app.render_currency(price.price),
 
                    price.multiple)
 
            return self.app.render_currency(price.price)
 
        if price.pack_price is not None:
 
            return "{} / {}".format(
 
                self.app.render_currency(price.pack_price),
 
                price.pack_multiple)
 

	
 
    def get_uom_sil_codes(self, session, uppercase=False, **kwargs):
 
        """
 
        This should return a dict, keys of which are UOM abbreviation strings,
0 comments (0 inline, 0 general)