Thank you Pavel
i checked with a developer. He thinks it would be possible if I install woocommerce pands and write a python script
like that:
from woocommerce import API
import pandas as pd
from datetime import datetime
Verbindung zur WooCommerce API herstellen
wcapi = API(
url="https://dein-shop.com",
consumer_key="dein_consumer_key",
consumer_secret="dein_consumer_secret",
version="wc/v3"
)
Funktion zum Abrufen des Lagerbestands am 1. Januar
def get_initial_stock(product_id):
Hier müsstest du den Lagerbestand am 1. Januar manuell oder aus einer Datenbank abrufen
return 100 # Beispielwert
Funktion zum Abrufen der Kundenbestellungen und Einkäufe
def get_orders_and_purchases(product_id):
orders = wcapi.get(f"orders?product={product_id}").json()
purchases = wcapi.get(f"products/{product_id}/purchase_orders").json()
return orders, purchases
Funktion zum Berechnen des neuen Lagerbestands
def calculate_new_stock(initial_stock, orders, purchases):
total_sales = sum(order['quantity'] for order in orders)
total_purchases = sum(purchase['quantity'] for purchase in purchases)
new_stock = initial_stock + total_purchases - total_sales
return total_sales, total_purchases, new_stock
Funktion zum Erstellen des Jahresblatts
def create_annual_sheet(product_id):
initial_stock = get_initial_stock(product_id)
orders, purchases = get_orders_and_purchases(product_id)
total_sales, total_purchases, new_stock = calculate_new_stock(initial_stock, orders, purchases)
data = {
"Eingangsinventar am 1. Januar": [initial_stock],
"Kundenbestellungen": [order['quantity'] for order in orders],
"Einkäufe": [purchase['quantity'] for purchase in purchases],
"Gesamtmenge der Einkäufe": [total_purchases],
"Gesamtmenge der Verkäufe": [total_sales],
"Neuer Lagerbestand": [new_stock]
}
df = pd.DataFrame(data)
df.to_csv(f"jahresblatt_{product_id}.csv", index=False)
Beispielaufruf für ein Produkt
create_annual_sheet(123) # Ersetze 123 durch die tatsächliche Produkt-ID
do you think this could be the way?