Beispiel #1
0
 def __set__(self, instance, value):
     try:
         vat_rate_id = VatRates.get_vat_rate_id_by_rate(value)
     except KeyError:
         raise Exception("{}% is not a valid VAT rate.".format(value))
     CCAPI.set_product_vat_rate(product_ids=[instance.id], vat_rate=value)
     instance._vat_rate_id = vat_rate_id
Beispiel #2
0
    def end_of_line(self, value):
        """
        Set the end of line status of the range.

        Args:
            value <bool>: True if product is End of Line, else False.

        """
        CCAPI.update_range_settings(
            self.id,
            current_name=self.name,
            current_sku=self.sku,
            current_end_of_line=self.end_of_line,
            current_pre_order=self.pre_order,
            current_group_items=self.grouped,
            new_name=self.name,
            new_sku=self.sku,
            new_end_of_line=bool(value),
            new_pre_order=self.pre_order,
            new_group_items=self.grouped,
            channels=[],
        )
        self._end_of_line = bool(value)
        for product in self.products:
            product.discontinued = True
Beispiel #3
0
 def stock_level(self, new_stock_level):
     """Update the stock level of the product."""
     CCAPI.update_product_stock_level(
         product_id=self.id,
         new_stock_level=new_stock_level,
         old_stock_level=self._stock_level,
     )
     self._stock_level = new_stock_level
Beispiel #4
0
 def __set__(self, instance, value):
     setattr(instance, self.instance_attr, value)
     CCAPI.set_product_scope(
         product_id=instance.id,
         weight=instance.weight,
         height=instance.cloud_commerce_height,
         length=instance.cloud_commerce_length,
         width=instance.cloud_commerce_width,
         large_letter_compatible=instance.large_letter_compatible,
         external_id=instance.external_product_id,
     )
 def __setitem__(self, key, value):
     value = str(value)
     if self.product_has_option(key):
         option = self.names[key]
     else:
         range_option = self.product.product_range.options[key]
         range_option.selected = True
         option = range_option
     value_id = CCAPI.get_option_value_id(option.id, value, create=True)
     CCAPI.set_product_option_value(product_ids=[self.product.id],
                                    option_id=option.id,
                                    option_value_id=value_id)
     self._options = None
    def variable(self, value):
        """
        Set weather this Product Option is a Variation Option.

        Args:
            selected(bool): If True product option will be set as a Variation
                Option.
        """
        value = bool(value)
        if value == self._variable:
            return
        CCAPI.set_range_option_drop_down(range_id=self.product_range.id,
                                         option_id=self.id,
                                         drop_down=value)
        self._variable = value
Beispiel #7
0
    def bays(self, new_bays):
        """
        Update Warehouse Bays for product.

        Args:
            new_bays: list<int> of Warehouse Bay IDs.
        """
        new_bays = [int(bay) for bay in new_bays]
        old_bays = self.bays
        bays_to_remove = [b for b in old_bays if b not in new_bays]
        bays_to_add = [b for b in new_bays if b not in old_bays]
        for bay in bays_to_remove:
            CCAPI.remove_warehouse_bay_from_product(self.id, bay)
        for bay in bays_to_add:
            CCAPI.add_warehouse_bay_to_product(self.id, bay)
        self._bays = None
Beispiel #8
0
 def name(self, name):
     CCAPI.set_product_name(product_ids=[p.id for p in self.products], name=name)
     CCAPI.update_range_settings(
         self.id,
         current_name=self.name,
         current_sku=self.sku,
         current_end_of_line=self.end_of_line,
         current_pre_order=self.pre_order,
         current_group_items=self.grouped,
         new_name=name,
         new_sku=self.sku,
         new_end_of_line=self.end_of_line,
         new_pre_order=self.pre_order,
         new_group_items=self.grouped,
         channels=self._get_sales_channel_ids(),
     )
Beispiel #9
0
 def __init__(self):
     """Load Profit/Loss data from Cloud Commerce."""
     self.courier_rules = CCAPI.get_courier_rules()
     self.shipping_rules = ShippingRules()
     self.products = {}
     orders = self.filter_orders(self.get_orders())
     self.orders = self.process_orders(orders)
Beispiel #10
0
    def selected(self, selected):
        """
        Set weather this Product Option is selected.

        Args:
            selected(bool): If True product option will be seleced.
        """
        value = bool(selected)
        if value:
            CCAPI.add_option_to_product(range_id=self.product_range.id,
                                        option_id=self.id)
        else:
            CCAPI.remove_option_from_product(range_id=self.product_range.id,
                                             option_id=self.id)
        for product in self.product_range:
            product._options = None
        self._selected = value
Beispiel #11
0
    def add_product(self, barcode, description, vat_rate):
        """Create a new product belonging to this range."""
        from .functions import get_product

        product_id = CCAPI.create_product(
            range_id=self.id,
            name=self.name,
            barcode=barcode,
            description=description,
            vat_rate=vat_rate,
        )
        return get_product(product_id)
Beispiel #12
0
 def _update_product_factory_link(
     self, factory_id, dropship=False, supplier_sku="", price=0
 ):
     factory_links = self._get_factory_links()
     for link in factory_links:
         link.delete()
     return CCAPI.update_product_factory_link(
         product_id=self.id,
         factory_id=factory_id,
         dropship=dropship,
         supplier_sku=supplier_sku or self.supplier_sku,
         price=price,
     )
Beispiel #13
0
    def __init__(self, product_range):
        """
        Configure product options for product range.

        Args:
            product_range: The cc_product.ProductRange for which to load
                Options.
        """
        self.product_range = product_range
        option_data = CCAPI.get_product_range_options(self.product_range.id)
        options = {o.id: o for o in option_data.options}
        self.options = [
            RangeOption(self.product_range, o, options.get(o.id))
            for o in option_data.shop_options
        ]
Beispiel #14
0
    def supplier(self, factory_name):
        """
        Set the supplier of the product.

        Remove all Factory Links and create a new Factory Link to the Factory
        named factory_name.

        Set Product Option Supplier to factory name.
        """
        if not isinstance(factory_name, Factory):
            factories = CCAPI.get_factories()
            if factory_name in factories.names:
                factory = factories.names[factory_name]
            else:
                raise exceptions.FactoryDoesNotExist(factory_name)
        self._update_product_factory_link(factory.id)
        self.options["Supplier"] = factory.name
Beispiel #15
0
    def get_product(self):
        """
        Return product inventory data from Cloud Commerce.

        Returns:
            ccapi.inventory_items.Product.

        """
        if self.order_product.product_id in self.update.products:
            return self.update.products[self.order_product.product_id]
        for attempt in range(100):
            try:
                return CCAPI.get_product(self.order_product.product_id)
            except Exception:
                time.sleep(10)
                continue
            else:
                break
        else:
            raise Exception("Unable to load product {}.".format(
                self.order_product.sku))
Beispiel #16
0
 def delete(self):
     """Delete this Product Range."""
     CCAPI.delete_range(self.id)
Beispiel #17
0
 def _get_sales_channels(self):
     """Get Sales Channels for this Product Range."""
     return CCAPI.get_sales_channels_for_range(self.id)
Beispiel #18
0
 def _get_factory_links(self):
     return CCAPI.get_product_factory_links(self.id)
Beispiel #19
0
 def _reload(self):
     self.load_from_cc_data(CCAPI.get_product(self.id).json)
Beispiel #20
0
 def description(self):
     """Return the description of the product."""
     if self._description is None:
         self._description = CCAPI.get_product(self.id).description
     return self._description
Beispiel #21
0
 def options(self):
     """Return Variation Product Options belinging to self.product."""
     if self._options is None:
         options = CCAPI.get_options_for_product(self.product.id)
         self._options = [VariationOption(o) for o in options]
     return self._options
Beispiel #22
0
 def description(self, value):
     """Set the description of the product."""
     if value is None or value == "":
         value = self.name
     CCAPI.set_product_description(product_ids=[self.id], description=value)
     self._description = value
Beispiel #23
0
 def name(self, name):
     """Set the product's name."""
     CCAPI.set_product_name(name=name, product_ids=[self.id])
     self._name = name
     self.full_name = None
Beispiel #24
0
 def get_pending_stock(self):
     """Return the pending stock level of the product."""
     return CCAPI.get_pending_stock(self.id)
Beispiel #25
0
 def description(self, description):
     """Set the description for the Range."""
     CCAPI.set_product_description(
         product_ids=[p.id for p in self.products], description=description
     )
     self._description = description
Beispiel #26
0
 def handling_time(self, handling_time):
     """Set the handling time for the product."""
     CCAPI.set_product_handling_time(product_id=self.id, handling_time=handling_time)
     self._handling_time = handling_time
Beispiel #27
0
from django.template.engine import Engine
from django.conf import settings
import os
import webbrowser
import sys

settings.configure(DEBUG=False)

template_path = os.path.join(os.path.dirname(__file__), "template.html")

with open(template_path, "r") as f:
    template_string = f.read()

template = Template(template_string, engine=Engine())

options = CCAPI.get_product_options()
suppliers = [o for o in options if o.option_name == "Supplier"][0].values
suppliers.sort(key=lambda x: x.value)

supplier_id = None

while supplier_id is None:
    print(
        'Enter name of supplier or enter "list" or a list of suppliers.',
        file=sys.stderr,
    )
    supplier_name = input("Supplier Name: ").strip().lower()
    if supplier_name == "list":
        print(file=sys.stderr)
        for supplier in suppliers:
            print(supplier.value, file=sys.stderr)
Beispiel #28
0
 def price(self, price):
     """Set the base price for the product."""
     CCAPI.set_product_base_price(product_id=self.id, price=price)
     self._price = price
Beispiel #29
0
 def get_orders(self):
     """Return dispatched orders from Cloud Commerce."""
     return CCAPI.get_orders_for_dispatch(
         order_type=1, number_of_days=self.number_of_days
     )
Beispiel #30
0
 def setUp(self):
     """Get product."""
     super().setUp()
     self.register_request(requests.FindProductSelectedOptionsOnly,
                           json=self.RESPONSE_DATA)
     self.product = CCAPI.get_product(self.PRODUCT_ID)