from tickets.models import *
# order_ids = {101375, 101577, 101577, 101696, 101696, 101724, 101839, 101879, 101903, 102041, 102054, 102078, 102078, 102086, 102094, 102094, 102094, 102094, 102228, 102228, 102228, 102269, 102272, 102464, 102464, 102464, 102467, 102504, 102591, 102596, 102596, 102596, 102835, 102835, 102917, 103034, 103412, 103509, 103677, 103701, 103724, 103900, 104173}
order_ids = {104958}
product_map = {
173: 175,
174: 176,
}
lgroup_map = {
135: 137,
136: 138,
}
# Due to braindamage, shop leaves ops with count=0 lying around. This will cause IntegrityError when updating product of ops. So clean up.
# OrderProduct.objects.filter(order__confirm_time__isnull=False, count=0).delete()
# Swap products in orders
for old_product_id, new_product_id in product_map.items():
old_product = Product.objects.get(id=old_product_id)
print(old_product)
ops = OrderProduct.objects.filter(order__in=order_ids, product=old_product_id, count__gt=0)
print(ops.count())
# Uncomment this to actually move
# ops.update(product=new_product_id)
# Update references in AccommodationInformation
for old_lg_id, new_lg_id in lgroup_map.items():
old_lg = LimitGroup.objects.get(id=old_lg_id)
new_lg = LimitGroup.objects.get(id=new_lg_id)
ais = AccommodationInformation.objects.filter(order_product__order__in=order_ids, limit_groups=old_lg_id)
print(old_lg)
for ai in ais:
print(ai)
# Uncomment these to actually move
# ai.limit_groups.remove(old_lg)
# ai.limit_groups.add(new_lg)
|