Procházet zdrojové kódy

delete duplicate stock entry which code is null

xjc před 6 měsíci
rodič
revize
383b6f8442
1 změnil soubory, kde provedl 4 přidání a 0 odebrání
  1. 4 0
      src/tools/sync_stock_data.py

+ 4 - 0
src/tools/sync_stock_data.py

@@ -60,6 +60,10 @@ def sync_stock_data():
         else:
             cm.Stock.objects.create(code=code, name=name)
 
+    # delete duplicate entry which code is null
+    with connection.cursor() as cur:
+        cur.execute("delete from stock where name in (select name from (select name,count(name) as c from stock group by name having c>1) as t0) and code is NULL order by name")
+
 
 if __name__ == "__main__":
     print("start sync stock...")