def test_include_deposit_cost_in_order_confirmation_buyer( products, container_types, order_items, order, seller, logistics_user, platform_user, traidoo_region, ): products[1].container_type = container_types[1] products[1].save() order_items[1].product_snapshot = order_items[1].product.create_snapshot() order_items[1].save() document = factories.OrderConfirmationBuyerFactory( order=order, region=traidoo_region).compose() html = BeautifulSoup(document.render_html(), features="html.parser") table = html.find("table") deposit_rows = table.find("td", text="Pfand").parent.find_next_siblings()[:2] deposit_lines = set() for row in deposit_rows: cells = row.find_all("td") deposit_lines.add(( 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_lines == { ( "Greenbox", f"{CURRENT_CURRENCY_SYMBOL} 3,20 / Stück", "2", f"{CURRENT_CURRENCY_SYMBOL} 6,40", "19,00%", ), ( "Isolierbox", f"{CURRENT_CURRENCY_SYMBOL} 3,20 / Stück", "3", f"{CURRENT_CURRENCY_SYMBOL} 9,60", "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("div", text="Gesamt (Brutto)").find_next_sibling().text assert (price_total == f"{CURRENT_CURRENCY_SYMBOL} 180,88" ) # deposit cost should be included in total
def test_calculation_with_buyer_platform_invoice(order, order_items, producer_invoice, logistics_invoice, platform_invoice, traidoo_region, buyer): buyer.is_cooperative_member = False buyer.save() order_confirmation = factories.OrderConfirmationBuyerFactory( order, traidoo_region).compose() order_confirmation.save() buyer_platform_invoice = factories.BuyerPlatformInvoiceFactory( order, traidoo_region).compose() buyer_platform_invoice.save() assert sufficient_wallet_balance_for_order( order.id, buyer.id, { "Balance": { "Amount": 18088 } # this is value of unpaid invoices excluding buyer platform invoice }) is False assert sufficient_wallet_balance_for_order( order.id, buyer.id, {"Balance": { "Amount": order_confirmation.price_gross_cents }})
def order_confirmation(order, platform_user, logistics_user, traidoo_region): document = factories.OrderConfirmationBuyerFactory( order, region=traidoo_region ).compose() document.mangopay_payin_id = "payin-1" document.save() order.total_price = document.price_gross order.save() order.recalculate_items_delivery_fee() yield document
def test_order_confirmation_with_products_delivered_by_neighbouring_region_logistics( order_with_neighbour_product, traidoo_region, other_region_product): order_with_neighbour_product.recalculate_items_delivery_fee() factory = factories.OrderConfirmationBuyerFactory( order_with_neighbour_product, region=traidoo_region) document = factory.compose() document.save() assert document.lines[6]["category"] == "Logistik" assert document.lines[6][ "name"] == f"Lieferung von {other_region_product.name}" assert (document.lines[6]["producer"] == other_region_product.region.setting.logistics_company.company_name)
def create_documents(self, order): sellers = {item.product.seller for item in order.items.all()} order_confirmation = factories.OrderConfirmationBuyerFactory( order, region=order.region).compose() documents = list( itertools.chain( self.invoices(order, sellers), self.delivery_documents(order, sellers), [order_confirmation], )) if (order.setting.platform_user and order.setting.enable_platform_fee_share and order.setting.central_share and order.setting.central_share < Decimal("100")): credit_note = factories.CreditNoteFactory( order, region=order.region).compose() documents.append(credit_note) if not order_confirmation.mangopay_payin_id: self._add_iban_alias_to_order_confirmation(order_confirmation, order) for document in documents: if "Invoice" in document.document_type: document.seller["iban"] = ( "Bitte nutzen Sie die Kontodaten in der " "Bestellzusammenfassung zur Zahlung aller Rechnungen " "dieser Bestellung.") document.seller["bic"] = None document.seller["bank"] = None logger.debug(f"Number of documents: {len(documents)}.") [document.save() for document in documents] return documents
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 test_order_confirmation_buyer( order, order_items, products, central_platform_user, logistics_user, container_types, traidoo_region, delivery_address, delivery_options, traidoo_settings, buyer, ): buyer.is_cooperative_member = False buyer.save() order.recalculate_items_delivery_fee() factory = factories.OrderConfirmationBuyerFactory(order, region=traidoo_region) document = factory.compose() document.save() assert document.seller == factories.OrderConfirmationBuyerFactory.as_dict( traidoo_region.setting.platform_user) assert document.buyer == factories.OrderConfirmationBuyerFactory.as_company( buyer) assert len(document.lines) == 6 assert document.order_id == order.id assert document.lines[0] == { "amount": 3.0, "category": "Produkte", "count": 3, "name": products[0].name, "number": products[0].id, "organic_control_body": products[0].seller.organic_control_body, "price": 10.6, "producer": products[0].seller.company_name, "seller_user_id": products[0].seller.id, "unit": products[0].unit, "vat_rate": 19.0, } assert document.lines[1] == { "amount": 1.0, "category": "Produkte", "count": 2, "name": products[1].name, "number": products[1].id, "organic_control_body": products[1].seller.organic_control_body, "price": 20.3, "producer": products[1].seller.company_name, "seller_user_id": products[1].seller.id, "unit": products[1].unit, "vat_rate": 19, } assert document.lines[2] == { "amount": 1.0, "category": "Pfand", "count": 5.0, "name": "Isolierbox", "number": container_types[0].id, "price": 3.2, "producer": "", "seller_user_id": products[0].seller.id, "unit": "Stück", "vat_rate": 19.0, } assert document.lines[3] == { "amount": 1.0, "category": "Logistik", "count": 1, "name": f"Lieferung von {products[0].name}", "number": products[0].id, "price": 14.31, "producer": logistics_user.company_name, "seller_user_id": logistics_user.id, "unit": "", "vat_rate": 19.0, } assert document.lines[4] == { "amount": 1.0, "category": "Logistik", "count": 1, "name": f"Lieferung von {products[1].name}", "number": products[1].id, "price": 12, "producer": products[1].seller.company_name, "seller_user_id": products[1].seller.id, "unit": "", "vat_rate": traidoo_settings.mc_swiss_delivery_fee_vat, } assert document.lines[5] == { "amount": 1.0, "category": "Plattform", "count": 1, "name": "Plattformgebühr", "number": "", "price": 2.72, "producer": central_platform_user.company_name, "seller_user_id": central_platform_user.id, "unit": "", "vat_rate": 19.0, }