예제 #1
0
def test_analog():
    FakeModelLogEntry = define_log_model(FakeModel)
    assert FakeModelLogEntry.__module__ == FakeModel.__module__
    assert FakeModelLogEntry._meta.get_field("target").rel.to is FakeModel
    assert FakeModel.log_entries.related.model is FakeModel
    assert FakeModel.log_entries.related.related_model is FakeModelLogEntry
    assert issubclass(FakeModelLogEntry, BaseLogEntry)
    assert isinstance(FakeModelLogEntry(), BaseLogEntry)
예제 #2
0
파일: orders.py 프로젝트: krisera/shoop
            "product_id", "quantity"))
        for product_id, quantity in lines:
            products[product_id]['ordered'] += quantity
            products[product_id]['unshipped'] += quantity

        from .shipments import ShipmentProduct

        shipment_prods = (ShipmentProduct.objects.filter(
            shipment__order=self).values_list("product_id", "quantity"))
        for product_id, quantity in shipment_prods:
            products[product_id]['shipped'] += quantity
            products[product_id]['unshipped'] -= quantity

        return products

    def get_unshipped_products(self):
        return dict(
            (product, summary_datum)
            for product, summary_datum in self.get_product_summary().items()
            if summary_datum['unshipped'])

    def get_status_display(self):
        return force_text(self.status)


OrderLogEntry = define_log_model(Order)


def _round_price(value):
    return bankers_round(value, settings.SHOOP_ORDER_TOTAL_DECIMALS)
예제 #3
0
            products[product_id]['unshipped'] += quantity

        from ._shipments import ShipmentProduct

        shipment_prods = (
            ShipmentProduct.objects
            .filter(shipment__order=self)
            .values_list("product_id", "quantity"))
        for product_id, quantity in shipment_prods:
            products[product_id]['shipped'] += quantity
            products[product_id]['unshipped'] -= quantity

        return products

    def get_unshipped_products(self):
        return dict(
            (product, summary_datum)
            for product, summary_datum in self.get_product_summary().items()
            if summary_datum['unshipped']
        )

    def get_status_display(self):
        return force_text(self.status)


OrderLogEntry = define_log_model(Order)


def _round_price(value):
    return bankers_round(value, 2)  # TODO: To be fixed in SHOOP-1912
예제 #4
0
            if quantity <= 0:
                raise ValueError("Quantity %s is invalid" % quantity)
            ProductPackageLink.objects.create(parent=self, child=child_product, quantity=quantity)
        self.verify_mode()

    def get_package_child_to_quantity_map(self):
        if self.mode == ProductMode.PACKAGE_PARENT:
            product_id_to_quantity = dict(
                ProductPackageLink.objects.filter(parent=self).values_list("child_id", "quantity")
            )
            products = dict((p.pk, p) for p in Product.objects.filter(pk__in=product_id_to_quantity.keys()))
            return {products[product_id]: quantity for (product_id, quantity) in six.iteritems(product_id_to_quantity)}
        return {}


ProductLogEntry = define_log_model(Product)


class ProductCrossSell(models.Model):
    product1 = models.ForeignKey(Product, related_name="cross_sell_1")
    product2 = models.ForeignKey(Product, related_name="cross_sell_2")
    weight = models.IntegerField(default=0)
    type = EnumIntegerField(ProductCrossSellType)

    class Meta:
        verbose_name = _('cross sell link')
        verbose_name_plural = _('cross sell links')


class ProductAttribute(AppliedAttribute):
    _applied_fk_field = "product"
예제 #5
0
    def __str__(self):
        return self.safe_translation_getter("name", any_language=True)

    def is_visible(self, customer):
        if customer and customer.is_all_seeing:
            return (self.status != CategoryStatus.DELETED)
        if self.status != CategoryStatus.VISIBLE:
            return False
        if not customer or customer.is_anonymous:
            if self.visibility != CategoryVisibility.VISIBLE_TO_ALL:
                return False
        else:
            if self.visibility == CategoryVisibility.VISIBLE_TO_GROUPS:
                group_ids = customer.groups.all().values_list("id", flat=True)
                return self.visibility_groups.filter(id__in=group_ids).exists()
        return True

    @staticmethod
    def _get_slug_name(self):
        if self.status == CategoryStatus.DELETED:
            return None
        return self.safe_translation_getter("name")

    def save(self, *args, **kwargs):
        rv = super(Category, self).save(*args, **kwargs)
        generate_multilanguage_slugs(self, self._get_slug_name)
        return rv


CategoryLogEntry = define_log_model(Category)
예제 #6
0
파일: products.py 프로젝트: taedori81/shoop
    def get_all_package_parents(self):
        return Product.objects.filter(pk__in=(
            ProductPackageLink.objects.filter(child=self).values_list("parent", flat=True)
        ))

    def get_all_package_children(self):
        return Product.objects.filter(pk__in=(
            ProductPackageLink.objects.filter(parent=self).values_list("child", flat=True)
        ))

    def get_public_media(self):
        return self.media.filter(enabled=True, public=True)


ProductLogEntry = define_log_model(Product)


class ProductCrossSell(models.Model):
    product1 = models.ForeignKey(Product, related_name="cross_sell_1", on_delete=models.CASCADE)
    product2 = models.ForeignKey(Product, related_name="cross_sell_2", on_delete=models.CASCADE)
    weight = models.IntegerField(default=0)
    type = EnumIntegerField(ProductCrossSellType)

    class Meta:
        verbose_name = _('cross sell link')
        verbose_name_plural = _('cross sell links')


class ProductAttribute(AppliedAttribute):
    _applied_fk_field = "product"
예제 #7
0
    def __str__(self):
        return self.safe_translation_getter("name", any_language=True)

    def is_visible(self, customer):
        if customer and customer.is_all_seeing:
            return (self.status != CategoryStatus.DELETED)
        if self.status != CategoryStatus.VISIBLE:
            return False
        if not customer or customer.is_anonymous:
            if self.visibility != CategoryVisibility.VISIBLE_TO_ALL:
                return False
        else:
            if self.visibility == CategoryVisibility.VISIBLE_TO_GROUPS:
                group_ids = customer.groups.all().values_list("id", flat=True)
                return self.visibility_groups.filter(id__in=group_ids).exists()
        return True

    @staticmethod
    def _get_slug_name(self):
        if self.status == CategoryStatus.DELETED:
            return None
        return self.safe_translation_getter("name")

    def save(self, *args, **kwargs):
        rv = super(Category, self).save(*args, **kwargs)
        generate_multilanguage_slugs(self, self._get_slug_name)
        return rv

CategoryLogEntry = define_log_model(Category)