Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update logo, explicit PDF logic, creation date formatting
Tomasz Szymanski7332c7b46c13
diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 724d6d950a..de647ffb8b 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -343,6 +343,10 @@ def match_orders_with_new_user(user: User) -> None:def _chunk_products(products, product_limit):+ """Split products to list of chunks.++ Each chunk represents products per page, product_limit defines chunk size.+ """chunks = []for i in range(0, len(products), product_limit):limit = i + product_limit@@ -351,6 +355,11 @@ def _chunk_products(products, product_limit):def _get_page_count(products_first_page, rest_of_products):+ """Calculate number of PDF pages.++ Keep track of summary table that might be displayed on last page+ if product count is too big to include table on that page.+ """if not rest_of_products and len(products_first_page) == 4:return 2try:@@ -361,16 +370,23 @@ def _get_page_count(products_first_page, rest_of_products):def generate_invoice_pdf_for_order(invoice):- logo_path = static_finders.find("images/logo-light.svg")+ logo_path = static_finders.find("images/logo.svg")+ MAX_PRODUCTS_FIRST_PAGE = 4+ MAX_PRODUCTS_PER_PAGE = 13all_products = invoice.order.lines.all()- _product_limit = 3 if len(all_products) < 4 else 4+ _product_limit = (+ 3 if len(all_products) < MAX_PRODUCTS_FIRST_PAGE else MAX_PRODUCTS_FIRST_PAGE+ )products_first_page = all_products[:_product_limit]- rest_of_products = _chunk_products(all_products[_product_limit:], 13)+ rest_of_products = _chunk_products(+ all_products[_product_limit:], MAX_PRODUCTS_PER_PAGE+ )rendered_template = get_template("invoice.html").render({"invoice": invoice,+ "creation_date": invoice.created.strftime("%d %b %Y"),"order": invoice.order,"logo_path": f"file://{logo_path}","products_first_page": products_first_page,diff --git a/saleor/static/images/logo.svg b/saleor/static/images/logo.svgnew file mode 100644index 0000000000..21e0fe727d--- /dev/null+++ b/saleor/static/images/logo.svg@@ -0,0 +1 @@+<svg class="logo" width="93" height="32" fill="none" xmlns="http://www.w3.org/2000/svg"><mask id="a" maskUnits="userSpaceOnUse" x="0" y="1" width="93" height="31"><path fill-rule="evenodd" clip-rule="evenodd" d="M0 1.162h92.918V32H0V1.162z" fill="#fff"/></mask><g mask="url(#a)" fill-rule="evenodd" clip-rule="evenodd" fill="#28234A"><path d="M15.47 31.97c5.707 0 7.142-2.305 7.142-5.462 0-3.883-3.489-4.608-6.391-5.082-2.218-.379-3.229-.568-3.229-1.926 0-1.01.88-1.389 2.316-1.389 1.76 0 2.25.506 2.413 1.99l4.63-.695c-.391-3.188-2.184-4.798-6.913-4.798-5.185 0-7.01 2.083-7.01 5.397-.033 4.294 4.01 4.736 7.01 5.24 1.859.348 2.577.663 2.577 1.895 0 1.01-.62 1.452-2.479 1.452-2.054 0-2.674-.348-2.935-2.02l-4.5.662c.424 3.378 2.413 4.735 7.37 4.735zM30.395 28.498c-2.185 0-2.967-.474-2.967-2.052 0-1.42.782-1.989 3.13-1.989h2.348V26.1c0 1.578-.783 2.399-2.51 2.399zm-2.016 3.47c2.544 0 3.685-.82 4.5-2.02v1.8h4.598V20.32c0-3.82-1.467-5.745-6.554-5.745-4.924 0-6.653 1.39-7.337 4.799l4.565.694c.293-1.452.717-1.894 2.609-1.894 1.826 0 2.12.757 2.12 2.02v1.168h-2.153c-5.837 0-7.826 1.768-7.826 5.367 0 3.535 1.793 5.24 5.478 5.24zM38.647 31.75h4.696V7.393l-4.696 4.656v19.7zM49.09 21.46v-.853c0-1.483.685-2.494 2.739-2.494 1.989 0 2.641.853 2.641 2.494v.853h-5.38zm2.733 10.542c5.413 0 6.848-2.525 7.174-5.05l-4.467-.663c-.196 1.515-.49 2.304-2.707 2.304-2.25 0-2.74-1.105-2.74-2.557v-1.389h9.914v-3.03c0-4.23-1.663-7.04-7.174-7.04-5.446 0-7.304 2.842-7.304 6.44v4.546c0 3.504 1.89 6.44 7.304 6.44zM67.703 32.002c5.38 0 7.598-2.746 7.598-6.44v-4.545c0-3.756-2.217-6.44-7.598-6.44-5.38 0-7.533 2.684-7.533 6.44v4.546c0 3.693 2.12 6.44 7.533 6.44zm-.002-3.661c-1.891 0-2.836-.979-2.836-2.557v-4.861c0-1.61.945-2.589 2.837-2.589 1.89 0 2.902.979 2.902 2.588v4.862c0 1.578-1.011 2.557-2.903 2.557zM83.688 19.395H81.17v12.256h-4.696V19.395l4.588-4.655h7.212l-4.587 4.655z"/></g><path fill-rule="evenodd" clip-rule="evenodd" d="M21.217 0l-6.18 6.44h15.267L36.484 0H21.218z" fill="#13BEBB"/><path fill-rule="evenodd" clip-rule="evenodd" d="M8.018 2.24a.602.602 0 01.425-.176h20.08a.601.601 0 01.425 1.028l-5.79 5.773a.602.602 0 01-.425.176H2.653a.602.602 0 01-.425-1.028l5.79-5.773zm.674 1.027l-4.584 4.57h18.376l4.583-4.57H8.692z" fill="#28234A"/></svg>diff --git a/templates/invoice.html b/templates/invoice.htmlindex 00d35df981..96c72b3b5f 100644--- a/templates/invoice.html+++ b/templates/invoice.html@@ -193,7 +193,7 @@{% trans "Date:" context "Invoice PDF header" %}</span><br />- <span class="header-item">{{ invoice.created }}</span>+ <span class="header-item">{{ creation_date }}</span><br /><span class="header-category">{% trans "Amount:" context "Invoice PDF amount (price)" %}