def test_add_delivery_fee_if_producer_delivers_items(order, order_items, seller, logistics_user, traidoo_region): order.recalculate_items_delivery_fee() html = (factories.ProducerInvoiceFactory( order=order, region=traidoo_region, seller=seller).compose().render_html()) assert "Lieferung von" in html
def test_vat_amount_added_to_invoice_sum(order, order_items, seller, logistics_user, traidoo_region): document = factories.ProducerInvoiceFactory(order=order, region=traidoo_region, seller=seller).compose() html = document.render_html() html = BeautifulSoup(html, features="html.parser") vat_amount_cells = html.find_all(attrs={"class": "sum-vat-amount"}) # TODO: do not use static values, calculate vat assert "28,88" in vat_amount_cells[0].text
def test_merge_same_products( buyer, traidoo_region, products, delivery_address, delivery_options, seller, logistics_user, ): order = Order(buyer=buyer, region=traidoo_region) order.save() order.recalculate_items_delivery_fee() order_items = [ OrderItem( product=products[0], quantity=5, order=order, delivery_address=delivery_address, delivery_option=delivery_options[0], latest_delivery_date=(timezone.now().date() + datetime.timedelta(days=3)), ), OrderItem( product=products[0], quantity=5, order=order, delivery_address=delivery_address, delivery_option=delivery_options[0], latest_delivery_date=(timezone.now().date() + datetime.timedelta(days=2)), ), OrderItem( product=products[0], quantity=5, order=order, delivery_address=delivery_address, delivery_option=delivery_options[0], latest_delivery_date=(timezone.now().date() + datetime.timedelta(days=1)), ), ] [items.save() for items in order_items] order.recalculate_items_delivery_fee() factory = factories.ProducerInvoiceFactory( order=order, seller=seller, region=traidoo_region ) assert len(factory._items) == 1 assert factory._items[0].product == products[0] assert factory._items[0].quantity == 15 assert factory._items[0].product_snapshot == order_items[0].product_snapshot assert factory._items[0].order == order assert factory._items[0].delivery_address == order_items[0].delivery_address assert factory._items[0].delivery_option == order_items[0].delivery_option assert factory._items[0].latest_delivery_date == order_items[0].latest_delivery_date
def test_producer_invoice( order, order_items, traidoo_region, container_types, delivery_address, delivery_options, logistics_user, seller, buyer, products, ): other_seller = baker.make_recipe("users.user") products[1].seller = other_seller products[1].save() factory = factories.ProducerInvoiceFactory( order, seller=seller, region=traidoo_region ) document = factory.compose() document.save() assert document.seller == factories.ProducerInvoiceFactory.as_dict(seller) assert document.buyer == factories.ProducerInvoiceFactory.as_company(buyer) assert len(document.lines) == 2 assert document.order_id == order.id assert document.lines[0] == { "amount": 3.0, "category": "Produkte", "count": 3.0, "name": products[0].name, "number": products[0].id, "organic_control_body": seller.organic_control_body, "price": 10.6, "producer": seller.company_name, "seller_user_id": seller.id, "unit": products[0].unit, "vat_rate": products[0].vat, } assert document.lines[1] == { "amount": 1, "category": "Pfand", "count": 3.0, "name": "Isolierbox", "number": container_types[0].id, "price": 3.2, "producer": "", "seller_user_id": seller.id, "unit": "Stück", "vat_rate": 19.0, }
def invoices(order: Order, sellers: List[User]): documents = [] # Add platform invoice for a buyer only if he is not a cooperative # member if not order.buyer.is_cooperative_member: documents.append( factories.BuyerPlatformInvoiceFactory( order, region=order.buyer.region).compose()) if order.has_central_logistics_deliveries: regions = { order_item.product.region for order_item in order.items.select_related( "product__region").filter( delivery_option__id=DeliveryOption.CENTRAL_LOGISTICS). distinct() } for region in regions: documents.append( factories.LogisticsInvoiceFactory(order, region=region).compose()) if settings.FEATURES["routes"] and order.has_third_party_deliveries: logger.debug("Generating invoice for a supplier.") regions = { order_item.product.region for order_item in order.items.select_related( "product__region").filter( job__user__isnull=False).distinct() } for region in regions: for document in factories.ThirdPartyLogisticsInvoiceFactory( order, region=region).compose(): documents.append(document) for seller in sellers: documents.extend([ factories.ProducerInvoiceFactory(order, region=seller.region, seller=seller).compose(), factories.PlatformInvoiceFactory(order, region=seller.region, seller=seller).compose(), ]) return documents
def test_added_deposit_costs(order, order_items, seller, logistics_user, traidoo_region): html = (factories.ProducerInvoiceFactory( order=order, region=traidoo_region, seller=seller).compose().render_html()) with codecs.open("producer_invoice.html", "w", encoding="utf-8") as out_file: out_file.write(html) html = BeautifulSoup(html, features="html.parser") table = html.find("table") table.prettify() row = table.find("td", text="Pfand").parent.find_next_siblings()[0] cells = row.find_all("td") deposit_line = ( cells[1].strong.text, # container name cells[5].text.strip(), # deposit cells[4].text.split("x")[0].strip(), # count cells[6].text, # total price, cells[3].text, # vat rate ) assert deposit_line == ( "Isolierbox", f"{CURRENT_CURRENCY_SYMBOL} 3,20 / Stück", "5", f"{CURRENT_CURRENCY_SYMBOL} 16,00", "19,00%", ) deposits_total = html.find( "div", text="Summe Pfand Netto").find_next_sibling().text assert deposits_total == f"{CURRENT_CURRENCY_SYMBOL} 16,00" price_total = (html.find( "strong", text="Endsumme").parent.find_next_sibling().text.strip()) assert (price_total == f"{CURRENT_CURRENCY_SYMBOL} 180,88" ) # deposit cost should be included in total
def test_pay_oldest_order_first( mangopay_bank_alias_payin, order, api_client, order_confirmation, buyer, traidoo_region, products, delivery_address, delivery_options, ): new_order = baker.make( Order, buyer=buyer, region=traidoo_region, earliest_delivery_date=timezone.make_aware(datetime.datetime.today()), ) product = products[0] product.amount = 10 product.save() baker.make( OrderItem, product=product, quantity=1, order=new_order, delivery_address=delivery_address, delivery_option=delivery_options[0], latest_delivery_date=timezone.now().date() + datetime.timedelta(days=3), ) factories.PlatformInvoiceFactory( new_order, traidoo_region, product.seller ).compose().save() new_order_confirmation = factories.OrderConfirmationBuyerFactory( new_order, traidoo_region ).compose() new_order_confirmation.save() new_order.total_price = new_order_confirmation.price_gross new_order.save() factories.ProducerInvoiceFactory( new_order, traidoo_region, product.seller ).compose().save() mangopay_bank_alias_payin.return_value.get_wallet.side_effect = [ # first order check if we can afford to pay { "Currency": "EUR", "Id": "buyer-wallet-1", "Description": "Default", "Balance": {"Currency": "EUR", "Amount": 943191}, }, # second order { "Currency": "EUR", "Id": "buyer-wallet-1", "Description": "Default", "Balance": {"Currency": "EUR", "Amount": 0}, }, # final call to check if there's anything left in wallet { "Currency": "EUR", "Id": "buyer-wallet-1", "Description": "Default", "Balance": {"Currency": "EUR", "Amount": 0}, }, ] api_client.get( reverse("webhook"), data={"RessourceId": "payin-1", "EventType": "PAYIN_NORMAL_SUCCEEDED"}, ) order.refresh_from_db() assert order.is_paid assert not new_order.is_paid
def producer_invoice(order, seller, logistics_user, order_items): invoice = factories.ProducerInvoiceFactory( order, seller=seller, region=traidoo_region ).compose() invoice.save() yield invoice