コード例 #1
0
    def update_stock(self, product_id):
        """
        Supplier module update stock should always bump product
        cache and send `shuup.core.signals.stocks_updated` signal.
        """
        supplier_id = self.supplier.pk
        sv, _ = StockCount.objects.get_or_create(supplier_id=supplier_id, product_id=product_id)
        if not sv.stock_managed:
            # item doesn't manage stocks
            return

        # TODO: Consider whether this should be done without a cache table
        values = get_current_stock_value(supplier_id=supplier_id, product_id=product_id)
        sv.logical_count = values["logical_count"]
        sv.physical_count = values["physical_count"]
        latest_event = (
            StockAdjustment.objects
            .filter(supplier=supplier_id, product=product_id, type=StockAdjustmentType.INVENTORY)
            .last())
        if latest_event:
            sv.stock_value_value = latest_event.purchase_price_value * sv.logical_count

        if self.supplier.stock_managed and has_installed("shuup.notify"):
            if sv.alert_limit and sv.physical_count < sv.alert_limit:
                product = Product.objects.filter(id=product_id).first()
                if product:
                    from .notify_events import AlertLimitReached
                    for shop in self.supplier.shops.all():
                        AlertLimitReached(supplier=self.supplier, product=product).run(shop=shop)

        sv.save(update_fields=("logical_count", "physical_count", "stock_value_value"))
        context_cache.bump_cache_for_product(Product.objects.get(id=product_id))
        stocks_updated.send(
            type(self), shops=self.supplier.shops.all(), product_ids=[product_id], supplier=self.supplier)
コード例 #2
0
ファイル: module.py プロジェクト: yashodhank/shuup
    def update_stock(self, product_id):
        supplier_id = self.supplier.pk
        # TODO: Consider whether this should be done without a cache table
        values = get_current_stock_value(supplier_id=supplier_id,
                                         product_id=product_id)
        sv, _ = StockCount.objects.get_or_create(supplier_id=supplier_id,
                                                 product_id=product_id)
        sv.logical_count = values["logical_count"]
        sv.physical_count = values["physical_count"]
        latest_event = (StockAdjustment.objects.filter(
            supplier=supplier_id,
            product=product_id,
            type=StockAdjustmentType.INVENTORY).last())
        if latest_event:
            sv.stock_value_value = latest_event.purchase_price_value * sv.logical_count

        if "shuup.notify" in settings.INSTALLED_APPS:
            if sv.alert_limit and sv.physical_count < sv.alert_limit:
                product = Product.objects.filter(id=product_id).first()
                if product and product.stock_behavior == StockBehavior.STOCKED:
                    from .notify_events import AlertLimitReached
                    for shop in self.supplier.shops.all():
                        AlertLimitReached(supplier=self.supplier,
                                          product=product).run(shop=shop)

        sv.save(update_fields=("logical_count", "physical_count",
                               "stock_value_value"))
        context_cache.bump_cache_for_product(
            Product.objects.get(id=product_id))
コード例 #3
0
ファイル: module.py プロジェクト: rrosajp/shuup
    def update_stock(self, product_id, *args, **kwargs):
        """
        Supplier module update stock should always bump product
        cache and send `shuup.core.signals.stocks_updated` signal.
        """
        supplier_id = self.supplier.pk
        sv, _ = StockCount.objects.select_related("product").get_or_create(
            supplier_id=supplier_id, product_id=product_id)

        # kind not supported
        if sv.product.kind not in self.get_supported_product_kinds_values():
            return

        # item doesn't manage stocks
        if not sv.stock_managed:
            # make sure to index products either way
            run_task("shuup.simple_supplier.tasks.index_product",
                     product=product_id,
                     supplier=self.supplier.pk)
            return

        values = get_current_stock_value(supplier_id=supplier_id,
                                         product_id=product_id)
        sv.logical_count = values["logical_count"]
        sv.physical_count = values["physical_count"]
        latest_event = StockAdjustment.objects.filter(
            supplier=supplier_id,
            product=product_id,
            type=StockAdjustmentType.INVENTORY).last()
        if latest_event:
            sv.stock_value_value = latest_event.purchase_price_value * sv.logical_count

        # TODO: get rid of this and move to shuup.notify app instead, through signals
        if self.supplier.stock_managed and has_installed("shuup.notify"):
            if sv.alert_limit and sv.physical_count < sv.alert_limit:
                product = Product.objects.filter(id=product_id).first()
                if product:
                    from .notify_events import AlertLimitReached

                    for shop in self.supplier.shops.all():
                        supplier_email = self.supplier.contact_address.email if self.supplier.contact_address else ""
                        shop_email = shop.contact_address.email if shop.contact_address else ""
                        AlertLimitReached(
                            supplier=self.supplier,
                            product=product,
                            shop_email=shop_email,
                            supplier_email=supplier_email,
                        ).run(shop=shop)

        sv.save(update_fields=("logical_count", "physical_count",
                               "stock_value_value"))
        context_cache.bump_cache_for_product(product_id)
        stocks_updated.send(type(self),
                            shops=self.supplier.shops.all(),
                            product_ids=[product_id],
                            supplier=self.supplier)
        run_task("shuup.simple_supplier.tasks.index_product",
                 product=product_id,
                 supplier=self.supplier.pk)
コード例 #4
0
ファイル: module.py プロジェクト: arissetyawan/shuup
 def update_stock(self, product_id):
     supplier_id = self.supplier.pk
     # TODO: Consider whether this should be done without a cache table
     values = get_current_stock_value(supplier_id=supplier_id, product_id=product_id)
     sv, _ = StockCount.objects.get_or_create(supplier_id=supplier_id, product_id=product_id)
     sv.logical_count = values["logical_count"]
     sv.physical_count = values["physical_count"]
     latest_event = StockAdjustment.objects.filter(
         supplier=supplier_id, product=product_id).order_by("-created_on").first()
     if latest_event:
         sv.stock_value_value = latest_event.purchase_price_value * sv.logical_count
     sv.save(update_fields=("logical_count", "physical_count", "stock_value_value"))
コード例 #5
0
ファイル: module.py プロジェクト: dragonsg/shuup-1
 def update_stock(self, product_id):
     supplier_id = self.supplier.pk
     # TODO: Consider whether this should be done without a cache table
     values = get_current_stock_value(supplier_id=supplier_id, product_id=product_id)
     sv, _ = StockCount.objects.get_or_create(supplier_id=supplier_id, product_id=product_id)
     sv.logical_count = values["logical_count"]
     sv.physical_count = values["physical_count"]
     latest_event = StockAdjustment.objects.filter(
         supplier=supplier_id, product=product_id).order_by("-created_on").first()
     if latest_event:
         sv.stock_value_value = latest_event.purchase_price_value * sv.logical_count
     sv.save(update_fields=("logical_count", "physical_count", "stock_value_value"))
コード例 #6
0
ファイル: module.py プロジェクト: ruqaiya/shuup
    def update_stock(self, product_id):
        """
        Supplier module update stock should always bump product
        cache and send `shuup.core.signals.stocks_updated` signal.
        """
        supplier_id = self.supplier.pk
        sv, _ = StockCount.objects.get_or_create(supplier_id=supplier_id, product_id=product_id)
        if not sv.stock_managed:
            # item doesn't manage stocks
            return

        # TODO: Consider whether this should be done without a cache table
        values = get_current_stock_value(supplier_id=supplier_id, product_id=product_id)
        sv.logical_count = values["logical_count"]
        sv.physical_count = values["physical_count"]
        latest_event = (
            StockAdjustment.objects
            .filter(supplier=supplier_id, product=product_id, type=StockAdjustmentType.INVENTORY)
            .last())
        if latest_event:
            sv.stock_value_value = latest_event.purchase_price_value * sv.logical_count

        if self.supplier.stock_managed and has_installed("shuup.notify"):
            if sv.alert_limit and sv.physical_count < sv.alert_limit:
                product = Product.objects.filter(id=product_id).first()
                if product:
                    from .notify_events import AlertLimitReached
                    for shop in self.supplier.shops.all():
                        supplier_email = self.supplier.contact_address.email if self.supplier.contact_address else ""
                        shop_email = shop.contact_address.email if shop.contact_address else ""
                        AlertLimitReached(
                            supplier=self.supplier,
                            product=product,
                            shop_email=shop_email,
                            supplier_email=supplier_email
                        ).run(shop=shop)

        sv.save(update_fields=("logical_count", "physical_count", "stock_value_value"))
        context_cache.bump_cache_for_product(Product.objects.get(id=product_id))
        stocks_updated.send(
            type(self), shops=self.supplier.shops.all(), product_ids=[product_id], supplier=self.supplier)
コード例 #7
0
ファイル: module.py プロジェクト: suutari/shoop
    def update_stock(self, product_id):
        supplier_id = self.supplier.pk
        # TODO: Consider whether this should be done without a cache table
        values = get_current_stock_value(supplier_id=supplier_id, product_id=product_id)
        sv, _ = StockCount.objects.get_or_create(supplier_id=supplier_id, product_id=product_id)
        sv.logical_count = values["logical_count"]
        sv.physical_count = values["physical_count"]
        latest_event = (
            StockAdjustment.objects
            .filter(supplier=supplier_id, product=product_id, type=StockAdjustmentType.INVENTORY)
            .last())
        if latest_event:
            sv.stock_value_value = latest_event.purchase_price_value * sv.logical_count

        if "shuup.notify" in settings.INSTALLED_APPS:
            if sv.alert_limit and sv.physical_count < sv.alert_limit:
                product = Product.objects.filter(id=product_id).first()
                if product and product.stock_behavior == StockBehavior.STOCKED:
                    from .notify_events import AlertLimitReached
                    AlertLimitReached(supplier=self.supplier, product=product).run()
        sv.save(update_fields=("logical_count", "physical_count", "stock_value_value"))