from django.db.transaction import atomic

from shoop.core.models import Order

from ._creator import OrderProcessor


class OrderModifier(OrderProcessor):

    @atomic
    def update_order_from_source(self, order_source, order):
        data = self.get_source_base_data(order_source)
        Order.objects.filter(pk=order.pk).update(**data)

        order = Order.objects.get(pk=order.pk)

        for line in order.lines.all():
            line.delete()

        return self.finalize_creation(order, order_source)

from django.db.transaction import atomic

from shoop.core.models import Order

from ._creator import OrderProcessor


class OrderModifier(OrderProcessor):

    @atomic
    def update_order_from_source(self, order_source, order):
        data = self.get_source_base_data(order_source)
        Order.objects.filter(pk=order.pk).update(**data)

        order = Order.objects.get(pk=order.pk)

        for line in order.lines.all():
            line.taxes.all().delete()  # Delete all tax lines before OrderLine's
            line.delete()

        return self.finalize_creation(order, order_source)

Enable modifying orders with taxes
Core: Enable modifying orders with taxes

Refs SHOOP-2338 / SHOOP-2578

  from django.db.transaction import atomic
  
  from shoop.core.models import Order
  
  from ._creator import OrderProcessor
  
  
  class OrderModifier(OrderProcessor):
  
      @atomic
      def update_order_from_source(self, order_source, order):
          data = self.get_source_base_data(order_source)
          Order.objects.filter(pk=order.pk).update(**data)
  
          order = Order.objects.get(pk=order.pk)
  
          for line in order.lines.all():
+             line.taxes.all().delete()  # Delete all tax lines before OrderLine's
              line.delete()
  
          return self.finalize_creation(order, order_source)
  
Enable modifying orders with taxes
## Code Before:
from django.db.transaction import atomic

from shoop.core.models import Order

from ._creator import OrderProcessor


class OrderModifier(OrderProcessor):

    @atomic
    def update_order_from_source(self, order_source, order):
        data = self.get_source_base_data(order_source)
        Order.objects.filter(pk=order.pk).update(**data)

        order = Order.objects.get(pk=order.pk)

        for line in order.lines.all():
            line.delete()

        return self.finalize_creation(order, order_source)

## Instruction:
Enable modifying orders with taxes
## Code After:
from django.db.transaction import atomic

from shoop.core.models import Order

from ._creator import OrderProcessor


class OrderModifier(OrderProcessor):

    @atomic
    def update_order_from_source(self, order_source, order):
        data = self.get_source_base_data(order_source)
        Order.objects.filter(pk=order.pk).update(**data)

        order = Order.objects.get(pk=order.pk)

        for line in order.lines.all():
            line.taxes.all().delete()  # Delete all tax lines before OrderLine's
            line.delete()

        return self.finalize_creation(order, order_source)
