示例#1
0
 def q_contents(self):
     """Returns an editable copy of the cart's contents, plus subtotals"""
     res = copy.deepcopy(self._contents)
     for row in res:
         row["subtotal"] = str(FixedPoint(row["price"]) \
                               * row["quantity"])
     return res
示例#2
0
文件: Sale.py 项目: souca/sixthdev
 def get_subtotal(self):
     res = FixedPoint('0.00')
     for item in self.details:
         if item.productID:
             if item.subtotal is not None:
                 res = res + item.subtotal
     return res
示例#3
0
 def calcWeight(self):
     """calculate order weight by summing product weights"""
     weight = 0
     for item in self.q_contents():
         weight = weight + \
                  (FixedPoint(item["extra"]["weight"] or "",0)
                   * item["quantity"])
     return weight
示例#4
0
 def setUp(self):
     self.store = Store(clerk)
     try:
         try:
             state = clerk.match(State, CD="CA")[0]
         except:
             state = State(CD="CA")
         state.salestax = FixedPoint("8.25")
         clerk.store(state)
     except:
         pass
示例#5
0
def newEvent(event, acct=None, posted=None, note=None, amount=None):
    e = Event()
    e.account = acct or None
    e.event = event
    if type(posted) == type(""):
        e.posted = DateTime(posted)
    elif isinstance(posted, DateTime) or isinstance(posted, Date):
        e.posted = posted
    elif not posted:
        e.posted = DateTime("now")
    else:
        raise TypeError, "Event posted with illegal DateTime type"
    e.amount = amount or FixedPoint("0.00")
    e.note = note or ""
    return e
示例#6
0
    def test_salesTax(self):

        addr = Contact()
        addr.stateCD = 'NY'
        addr.postal = '123456'

        actual = self.store.calcSalesTax(addr, 10)
        assert actual == 0, \
               "shouldn't have sales tax because no nexus in NY"

        addr = Contact()
        addr.stateCD = 'CA'

        actual = self.store.calcSalesTax(addr, 10)
        goal = (FixedPoint(clerk.match(State, CD="CA")[0].salestax) *
                10) / 100.0
        assert actual == goal, \
               "wrong sales tax after nexus established: %s vs %s" \
               % (actual, goal)
示例#7
0
    def testVesting(self):
        "ensure charges are slowly 'earned' over time"
        e = Event(event="charge", amount="50",
                  posted="1/1/2000", maturity="11/1/2000")
        assert e.percentVested(e.posted) == 0
        assert e.percentVested(e.posted-1) == 0
        assert e.percentVested(e.maturity) == 100
        assert e.percentVested(e.maturity+1) == 100

        #@TODO: paramaterize number of decimal places ?

        # In a single month, we're fully vested at the end of the month.
        # With a yearly charge, the vesting happens slowly over time.
        self.assertEquals(FixedPoint(e.percentVested(Date("2/1/2000"))), 10.16)
        self.assertEquals(FixedPoint(e.percentVested(Date("5/1/2000"))), 39.67)
        self.assertEquals(FixedPoint(e.percentVested(Date("7/1/2000"))), 59.67)
        self.assertEquals(FixedPoint(e.percentVested(Date("10/1/2000"))), 89.84)
        self.assertEquals(FixedPoint(e.percentVested(Date("10/31/2000"))),99.67)
        self.assertEquals(FixedPoint(e.percentVested(Date("11/1/2000"))), 100)
        self.assertEquals(FixedPoint(e.percentVested(Date("12/1/2000"))), 100)

        # valueOn should multiply by amount
        e.amount = 200
        self.assertEquals(e.valueOn(Date("2/1/2000")), 20.32)
示例#8
0
print >> RES, '<table  cellspacing="0" cellpadding="2" width="500">'
print >> RES, '<tr><th align="left">period</th>'
print >> RES, '<th align="right">charges</th>'
print >> RES, '<th align="right">payments</th>'
print >> RES, '<th align="right">difference</th>'
print >> RES, '</tr>'

this, next = "odd", "even"
totC, totP, totD = 0, 0, 0
subC, subP = 0, 0

lastYear = 'x'

for row in cur.fetchall():
    period = row[0]
    charges = FixedPoint(row[1])
    payments = FixedPoint(row[2])
    diff = charges - payments

    year = str(period)[-1]
    if (year != lastYear):
        if lastYear != 'x':
            print >> RES, '<tr class="subtotal">'
            print >> RES, '<td>&nbsp</td><td align="right">%s</td><td align="right">%s</td><td>&nbsp;</td>' \
                  % (subP, subC)
            print >> RES, '</tr>'
        subC = 0
        subP = 0
        lastYear = year

    print >> RES, '<tr class="%s">' % this
示例#9
0
def fakeSubscription():
    return duckbill.Subscription(service='blog',
                                 username='******',
                                 rate=FixedPoint('10.00'))
示例#10
0
print >> RES, '<th align="right">new/mo</th>'
print >> RES, '<th align="right">new/yr</th>'
print >> RES, '<td>&nbsp;</td>'
print >> RES, '<th align="right">base</th>'
print >> RES, '<th align="right">renew</th>'
print >> RES, '<th align="right">total</th>'
print >> RES, '</tr>'

this, next = "odd", "even"
totM, totY = 0, 0
renewals = [0] * 12
periodnum = 0

for row in cur.fetchall():
    period = row[0]
    monthly = FixedPoint(row[1])
    yearly = FixedPoint(row[2])
    base = totM

    renew = renewals[periodnum % 12]
    renewals[periodnum % 12] += yearly
    periodnum += 1

    totP = monthly + yearly + base + renew

    print >> RES, '<tr class="%s">' % this
    print >> RES, '<td>%s</td><td align="right">%s</td><td align="right">%s</td>' \
          % (period, monthly, yearly)
    print >> RES, '<td>&nbsp;</td><td align="right">%s</td><td align="right">%s</td>' \
          % (base, renew)
    print >> RES, '<td align="right" style="background:white">%s</td>' % totP
示例#11
0
文件: txt2qif.py 项目: souca/sixthdev
    print "usage: txt2qif.py fileName"
    sys.exit()

autoNumber = 0
transactions = []
trans = None
for line in textData:
    if not line.strip(): continue
    if line.startswith("\t"):
        _1, category, memo, payment, _2, deposit = line.split("\t")
        assert (_1 == "") and (_2 == "")
        split = SplitLine()
        split.category = category
        split.memo = memo
        assert (payment and not deposit) or (deposit and not payment)  # xor :(
        split.amount = FixedPoint((payment or deposit).replace(",", ""))
        #print "%7s  %-20s %-20s" % (split.amount, split.category, split.memo)
        trans.split.append(split)
    else:
        date, number, payee, account, memo, payment, c, deposit, balance \
              = line.split("\t")
        transactions.append(Transaction())
        trans = transactions[-1]
        trans.date = date

        if number in ["", "d", "debit", "Debit", "s", "D", "10000", "10001"]:
            trans.memo = memo
        else:
            trans.memo = "#%s: %s" % (number, memo)

        autoNumber += 1