コード例 #1
0
    def articles(self):
        """Returns list of dictionary of order articles

        :rtype: list
        """
        res = []
        utility = getUtility(IUnicodeUtility)
        shopping_site = IShoppingSite(self.context)
        vat_adapter = IVATAdapter(self.context)
        for item in self.get_content_listing(IOrderArticle):
            obj = item.getObject()
            order_article_adapter = IOrderArticleAdapter(obj)
            gross_subtotal = order_article_adapter.gross_subtotal()
            items = {
                'description': utility.safe_unicode(item.Description()),
                'gross': item.gross,
                'gross_subtotal': gross_subtotal,
                'locale_gross_subtotal': shopping_site.format_money(gross_subtotal),
                'image_url': None,
                'obj': obj,
                'quantity': item.quantity,
                'sku': item.sku,
                'title': utility.safe_unicode(item.Title()),
                'url': None,
                'vat_rate': vat_adapter.percent(item.vat_rate),
                'id': item.getId(),
            }
            orig_article = shopping_site.get_object(IArticle, path=shopping_site.portal_path(), UID=item.getId())
            if orig_article:
                items['url'] = orig_article.absolute_url()
                items['image_url'] = IArticleAdapter(orig_article).image_url(size='mini')
            res.append(items)
        return res
コード例 #2
0
 def test_gross_subtotal(self):
     context = self.create_content("collective.cart.core.OrderArticle")
     context.gross = self.money("20.00")
     context.quantity = 2
     adapter = IOrderArticleAdapter(context)
     self.assertEqual(adapter.gross_subtotal(), self.money("40.00"))