Esempio n. 1
0
    def from_gsx(cls, part):
        """
        Creates a Servo Product from GSX partDetail.
        We don't do GSX lookups here since we can't
        determine the correct GSX Account at this point.
        """
        conf = Configuration.conf()

        try:
            shipping = Decimal(conf.get("shipping_cost"))
        except TypeError:
            shipping = Decimal(0.0)

        part_number = part.originalPartNumber or part.partNumber
        product = Product(code=part_number)
        product.title = part.partDescription

        if part.originalPartNumber:
            product.subst_code = part.partNumber

        if part.stockPrice and not product.fixed_price:
            # calculate stock price
            purchase_sp = part.stockPrice or 0.0
            purchase_sp = Decimal(purchase_sp)
            sp, vat_sp = product.calculate_price(purchase_sp, shipping)
            product.pct_margin_stock = get_margin(purchase_sp)
            product.price_notax_stock = sp
            product.price_sales_stock = vat_sp
            # @TODO: make rounding configurable
            product.price_purchase_stock = purchase_sp.to_integral_exact(rounding=ROUND_CEILING)

        try:
            # calculate exchange price
            purchase_ep = part.exchangePrice or 0.0
            purchase_ep = Decimal(purchase_ep)

            if purchase_ep > 0 and not product.fixed_price:
                ep, vat_ep = product.calculate_price(purchase_ep, shipping)
                product.price_notax_exchange = ep
                product.price_sales_exchange = vat_ep
                product.pct_margin_exchange = Configuration.get_margin(purchase_ep)
                # @TODO: make rounding configurable
                product.price_purchase_exchange = purchase_ep.to_integral_exact(rounding=ROUND_CEILING)
        except AttributeError:
            pass  # Not all parts have exchange prices

        product.brand = "Apple"
        product.shipping = shipping
        product.warranty_period = 3

        product.labour_tier = part.laborTier
        product.part_type = part.partType.upper()

        # EEE and componentCode are sometimes missing
        if part.eeeCode:
            product.eee_code = str(part.eeeCode).strip()
        if part.componentCode:
            product.component_code = str(part.componentCode).strip()

        product.is_serialized = part.isSerialized
        return product
Esempio n. 2
0
    def from_gsx(cls, part):
        """
        Creates a Servo Product from GSX partDetail.
        We don't do GSX lookups here since we can't
        determine the correct GSX Account at this point.
        """
        conf = Configuration.conf()

        try:
            shipping = Decimal(conf.get("shipping_cost"))
        except TypeError:
            shipping = Decimal(0.0)

        part_number = part.originalPartNumber or part.partNumber
        product = Product(code=part_number)
        product.title = part.partDescription

        if part.originalPartNumber:
            product.subst_code = part.partNumber

        if part.stockPrice and not product.fixed_price:
            # calculate stock price
            purchase_sp = part.stockPrice or 0.0
            purchase_sp = Decimal(purchase_sp)
            sp, vat_sp  = product.calculate_price(purchase_sp, shipping)
            product.pct_margin_stock  = get_margin(purchase_sp)
            product.price_notax_stock = sp
            product.price_sales_stock = vat_sp
            # @TODO: make rounding configurable
            product.price_purchase_stock = purchase_sp.to_integral_exact(
                rounding=ROUND_CEILING
            )

        try:
            # calculate exchange price
            purchase_ep = part.exchangePrice or 0.0
            purchase_ep = Decimal(purchase_ep)

            if purchase_ep > 0 and not product.fixed_price:
                ep, vat_ep = product.calculate_price(purchase_ep, shipping)
                product.price_notax_exchange = ep
                product.price_sales_exchange = vat_ep
                product.pct_margin_exchange = Configuration.get_margin(purchase_ep)
                # @TODO: make rounding configurable
                product.price_purchase_exchange = purchase_ep.to_integral_exact(
                    rounding=ROUND_CEILING
                )
        except AttributeError:
            pass  # Not all parts have exchange prices

        product.brand = "Apple"
        product.shipping = shipping
        product.warranty_period = 3

        product.labour_tier = part.laborTier
        product.part_type = part.partType.upper()

        # EEE and componentCode are sometimes missing
        if part.eeeCode:
            product.eee_code = str(part.eeeCode).strip()
        if part.componentCode:
            product.component_code = str(part.componentCode).strip()

        product.is_serialized = part.isSerialized
        return product