def modify_item(self, product, relative=None, absolute=None,
                    recalculate=True, data=None, item=None, force_new=False):
        """
        Updates order with the given product

        - ``relative`` or ``absolute``: Add/subtract or define order item
          amount exactly
        - ``recalculate``: Recalculate order after cart modification
          (defaults to ``True``)
        - ``data``: Additional data for the order item; replaces the contents
          of the JSON field if it is not ``None``. Pass an empty dictionary
          if you want to reset the contents.
        - ``item``: The order item which should be modified. Will be
          automatically detected using the product if unspecified.
        - ``force_new``: Force the creation of a new order item, even if the
          product exists already in the cart (especially useful if the
          product is configurable).

        Returns the ``OrderItem`` instance; if quantity is zero, the order
        item instance is deleted, the ``pk`` attribute set to ``None`` but
        the order item is returned anyway.
        """

        assert (relative is None) != (absolute is None),\
            'One of relative or absolute must be provided.'
        assert not (force_new and item),\
            'Cannot set item and force_new at the same time.'

        if self.is_confirmed():
            raise ValidationError(
                _('Cannot modify order once it has been confirmed.'),
                code='order_sealed')

        if item is None and not force_new:
            try:
                item = self.items.get(product=product)
            except self.items.model.DoesNotExist:
                # Ok, product does not exist in cart yet.
                pass
            except self.items.model.MultipleObjectsReturned:
                # Oops. Product already exists several times. Stay on the
                # safe side and add a new one instead of trying to modify
                # another.
                if not force_new:
                    raise ValidationError(
                        _(
                            'The product already exists several times in the'
                            ' cart, and neither item nor force_new were'
                            ' given.'),
                        code='multiple')

        if item is None:
            item = self.items.model(
                order=self,
                product=product,
                quantity=0,
                currency=self.currency,
            )

        if relative is not None:
            item.quantity += relative
        else:
            item.quantity = absolute

        if item.quantity > 0:
            try:
                price = product.get_price(
                    currency=self.currency,
                    orderitem=item)
            except ObjectDoesNotExist:
                logger.error(
                    u'No price could be found for %s with currency %s' % (
                        product, self.currency))

                raise ValidationError(
                    _('The price could not be determined.'),
                    code='unknown_price')

            if data is not None:
                item.data = data

            price.handle_order_item(item)
            product.handle_order_item(item)
            item.save()
        else:
            if item.pk:
                item.delete()
                item.pk = None

        if recalculate:
            self.recalculate_total()

            # Reload item instance from DB to preserve field values
            # changed in recalculate_total
            if item.pk:
                item = self.items.get(pk=item.pk)

        try:
            self.validate(self.VALIDATE_BASE)
        except ValidationError:
            if item.pk:
                item.delete()
            raise

        return item
dataset/ETHPy150Open matthiask/plata/plata/shop/models.py/Order.modify_item/original