Ejemplo n.º 1
0
 def add_order_baseprice_component(self, desc, value):
     if isinstance(value, currency.CurrencyValue):
         self._orderbasecosts.append((desc, value))
     else:
         self._orderbasecosts.append(
             (desc, currency.CurrencyValue(value, self.currency))
         )
Ejemplo n.º 2
0
 def extended_price(self, qty, allow_partial=False):
     if not allow_partial:
         if qty < self.moq:
             raise ValueError
         if qty % self.oqmultiple != 0:
             pass
     return currency.CurrencyValue(self.unit_price._val * qty,
                                   self.unit_price._currency_def)
Ejemplo n.º 3
0
    def _process_other_costs(self):
        for k, v in self._data['costs_not_included'].iteritems():
            if v is False:
                self._data['costs_not_included'][k] = 'None'
            elif v == 'INCL':
                self._data['costs_not_included'][k] = 'None, ' \
                                                      'included in Invoice'
            elif v == 'LISTED':
                self._data['costs_not_included'][k] = 'Listed in Invoice'
            else:
                logger.warning("Unrecognized Other Costs definition for " + k +
                               " : " + v)

        if self._data['costs_not_included'][
                'FREIGHT'] == 'None, included in Invoice':  # noqa
            self.freight = currency.CurrencyValue(
                float(self._data['shipping_cost_incl']), self._vendor.currency)
            self._data['costs_not_included']['FREIGHT'] += " ({0})".format(
                self.freight.source_string)  # noqa
            self._includes_freight = True
        if self._data['costs_not_included']['FREIGHT'] == 'Listed in Invoice':
            self.freight = currency.CurrencyValue(
                float(self._data['shipping_cost_listed']),
                self._vendor.currency)
            self._data['costs_not_included'][
                'FREIGHT'] = "{0} (as listed in the invoice)".format(
                    self.freight.source_string)  # noqa
            self._includes_freight = True

        if 'insurance_pc' in self._data.keys():
            self.insurance_pc = float(self._data['insurance_pc'])
            if self.insurance_pc > 0:
                self._added_insurance = True
                self._data['costs_not_included'][
                    'INSURANCE'] = "{0} (@{1}% {2})".format(
                        self.insurance.source_string, self.insurance_pc,
                        self._data['insurance_note'])  # noqa

        if 'handling_pc' in self._data.keys():
            self.handling_pc = float(self._data['handling_pc'])
            if self.handling_pc > 0:
                self._added_handling = True
                self._data['costs_not_included'][
                    'LANDING'] = "{0} (@{1}% {2})".format(
                        self.landing.source_string, self.handling_pc,
                        self._data['handling_note'])  # noqa
Ejemplo n.º 4
0
    def _acquire_lines(self):
        logger.info("Acquiring Lines")
        invoice_file = os.path.join(self._source_folder,
                                    self._data['invoice_file'])
        with open(invoice_file) as f:
            reader = csv.reader(f)
            header = None
            for line in reader:
                if line[0].startswith(codecs.BOM_UTF8):
                    line[0] = line[0][3:]
                if line[0] == 'Index':
                    header = line
                    break
            if header is None:
                raise ValueError
            for line in reader:
                if line[0] != '':
                    idx = line[header.index('Index')].strip()
                    qty = int(line[header.index('Quantity')].strip())
                    vpno = line[header.index('Part Number')].strip()
                    desc = line[header.index('Description')].strip()
                    ident = line[header.index('Customer Reference')].strip()
                    boqty = line[header.index('Backorder')].strip()
                    try:
                        if int(boqty) > 0:
                            logger.warning(
                                "Apparant backorder. "
                                "Crosscheck customs treatment for: " + idx +
                                ' ' + ident)
                    except ValueError:
                        pass

                    unitp_str = line[header.index('Unit Price')].strip()

                    unitp = currency.CurrencyValue(float(unitp_str),
                                                   self._vendor.currency)
                    lineobj = customs.CustomsInvoiceLine(self,
                                                         ident,
                                                         vpno,
                                                         unitp,
                                                         qty,
                                                         idx=idx,
                                                         desc=desc)
                    self._lines.append(lineobj)
Ejemplo n.º 5
0
 def order_baseprice(self):
     t = 0
     for price in self._orderbasecosts:
         t += price[1].native_value
     return currency.CurrencyValue(t, currency.native_currency_defn)
Ejemplo n.º 6
0
 def __init__(self, moq, price, currency_def, oqmultiple=1):
     self._moq = moq
     self._price = currency.CurrencyValue(price, currency_def)
     self._oqmulitple = oqmultiple
Ejemplo n.º 7
0
 def extendedprice(self):
     return currency.CurrencyValue(self._unitp._val * self._qty,
                                   self._unitp._currency_def)
Ejemplo n.º 8
0
def test_currency_values():
    ncd = currency.native_currency_defn
    cv1 = currency.CurrencyValue(1, ncd)

    assert float(cv1) == 1.0
    assert repr(cv1) == BASE_CURRENCY_SYMBOL + '1.00'

    if currency.BASE_CURRENCY != 'USD':
        fcur = 'USD'
    else:
        fcur = 'GBP'

    fcd = currency.CurrencyDefinition(fcur, exchval=10)
    fcv1 = currency.CurrencyValue(1, fcd)
    assert fcv1.source_value == 1
    assert fcv1.native_value == 10
    assert fcv1.source_string == fcur + '1.00'
    assert fcv1.native_string == BASE_CURRENCY_SYMBOL + '10.00'

    fcv2 = currency.CurrencyValue(1, fcur)
    assert fcv2._currency_def._code == fcur

    cv2 = cv1 + fcv1

    assert cv2.native_value == 11
    assert cv2.source_value == 11
    assert cv2._currency_def == ncd

    cv3 = cv1 + 0
    assert cv1 == cv3

    cv3 = 0 + cv1
    assert cv1 == cv3

    cv3 = cv3 + cv1
    assert cv3.native_value == 2

    with pytest.raises(NotImplementedError):
        cv1 + 10

    with pytest.raises(NotImplementedError):
        10 + cv1

    cv3 = cv2 - cv1
    assert cv3.native_value == 10

    cv3 = cv2 - 0
    assert cv3.native_value == 11

    with pytest.raises(NotImplementedError):
        cv2 - "Test"

    # TODO Implement this?
    # cv3 = 0 - cv2
    # assert cv3.native_value == 11

    # with pytest.raises(NotImplementedError):
    #     "Test" - cv2

    cv3 = cv1 * 10
    assert cv3.native_value == 10
    assert cv3._currency_def == cv1._currency_def

    cv3 = 10 * cv1
    assert cv3.native_value == 10
    assert cv3._currency_def == cv1._currency_def

    with pytest.raises(NotImplementedError):
        cv1 * cv3

    ratio = fcv1 / cv1
    assert ratio == 10
    assert isinstance(ratio, Number)

    cv3 = cv1 / 10
    assert cv3.native_value == 1 / 10
    assert cv3._currency_def == cv1._currency_def

    with pytest.raises(NotImplementedError):
        cv1 / '10'

    assert 0 < cv1
    assert 0 == cv1 - cv1
    assert cv2 - 11 * cv1 == 0
    assert 0 > currency.CurrencyValue(-1, ncd)
    assert currency.CurrencyValue(-1, ncd) < 0
    assert cv1 > 0
    assert cv1 < cv2
    assert cv2 > cv1
    assert fcv1 == cv1 * 10

    with pytest.raises(TypeError):
        cv1 > 10