def move_to_group(self, item, target_group, quantity):
try:
target_item = target_group.items.get(
product=item.product, product_name=item.product_name,
product_sku=item.product_sku)
except ObjectDoesNotExist:
target_group.items.create(
delivery_group=target_group, product=item.product,
product_name=item.product_name, product_sku=item.product_sku,
quantity=quantity, unit_price_net=item.unit_price_net,
stock=item.stock,
unit_price_gross=item.unit_price_gross)
else:
target_item.quantity += quantity
target_item.save()
item.quantity -= quantity
self.remove_empty_groups(item)
评论列表
文章目录