Пример #1
0
 def search(self):
     vendor_id = self.request.POST.get('vendor_id') 
     from_dt = self.request.POST.get('from_dt', util.str_today())
     to_dt = self.request.POST.get('to_dt', util.str_today())
     return {
         'vendor_id' : vendor_id, 
         'from_dt' : from_dt, 
         'to_dt' : to_dt, 
         'purchases' : PurchaseOrder.search(self.enterprise_id, vendor_id, from_dt, to_dt),
         'vendors' : util.select_list(Vendor.find_all(self.enterprise_id), 'vendor_id', 'name')
         }
Пример #2
0
 def test_util(self):
     d8e = util.today_date()
     dtime = util.today()
     assert util.format_rss_date(d8e) == d8e.strftime("%a, %d %b %Y %H:%M:%S EST")
     assert util.words_date(dtime) == dtime.strftime("%B %d, %Y")
     assert util.is_empty(" ") == True
     assert util.float_("8") == None
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 2) == [3, 4]
     assert util.page_list([1, 2, 3, 4, 5, 6, 7, 8, 9], None, None) == [1, 2, 3, 4, 5, 6, 7, 8, 9]
     assert util.parse_date("2012-05-06") == datetime.datetime.strptime("2012-05-06", "%Y-%m-%d")
     today_ = datetime.date.today()
     assert [today_.year + 10, today_.year + 10] in util.year_list()
     assert util.month_list()[0] == ["1", "January"]
     assert util.this_year() == datetime.date.today().year
     assert util.get_first_day(today_) == util.get_first_day(
         today_
     )  # this is pretty dumb.  it works, just get it covered.
     assert util.get_last_day(today_) == util.get_last_day(today_)
     assert util.to_uuid("ken") == None
     assert int(util.average([1, 2, 3])) == 2
     assert util.format_date(util.truncate_datetime(dtime)) == util.str_today()
     assert util.is_today(d8e) == True
Пример #3
0
    def test_dates(self):
        d8e = util.today_date()
        dtime = util.today()
        assert h.is_today(d8e)
        assert h.str_today() == util.str_today()
        assert h.date_time(None) == ''
        assert h.date_time(d8e) == d8e.strftime("%Y-%m-%d %H:%M:%S")
        assert h.date_(None) == ''
        assert h.date_(d8e) == d8e.strftime("%Y-%m-%d")
        assert h.format_date(None) == ''
        assert h.format_date(d8e) == d8e.strftime("%Y-%m-%d")
        assert h.words_date_time(None) == ''
        assert h.words_date_time(dtime) == dtime.strftime("%B %d, %Y at %I:%M %p")
        assert h.slash_date(None) == ''
        assert h.slash_date(dtime) == dtime.strftime("%m/%d/%Y")
        assert h.words_date(None) == ''
        assert h.words_date(dtime) == dtime.strftime("%B %d, %Y")
        assert h.this_year() == datetime.date.today().year
        self.assertEqual('checkbox' in h.chkbox('fud'), True)

        dobj = TestObj()
        assert h.get(dobj, 'a') == 'aa'
        assert h.get(dobj, 'bogus') == ''
Пример #4
0
def str_today():
    return util.str_today()
Пример #5
0
def is_today(dat):
    return util.format_date(dat) == util.str_today()
Пример #6
0
    def add_item(self, product, campaign, quantity=1, base_price=None, start_dt=None, attributes={}, note=None): #pylint: disable-msg=R0913,W0102
        """ KB: [2013-02-24]: attribute_ids == {'123abc...' : 3, ...}  where 3 is the quantity """
        if not base_price:
            base_price = product.get_price(campaign)
        base_price = float(base_price)
        unit_price = base_price
        quantity = float(quantity)
        discount_price = product.get_discount_price(campaign)
        if discount_price is not None and round(discount_price, 2) < round(unit_price, 2):
            unit_price = discount_price

        self.items.append({'product': product,
                           'quantity': quantity,
                           'campaign_id': campaign.campaign_id,
                           'attributes': attributes, 
                           'dt': datetime.datetime.date(datetime.datetime.now()),
                           'base_price':base_price,
                           'unit_price':unit_price,
                           'note' : note,
                           'discount_amount':(base_price-unit_price)*quantity,
                           'regular_price':round(base_price*quantity, 2),
                           'price': round(unit_price*quantity, 2),
                           'start_dt':util.parse_date_as_date(util.nvl(str(start_dt), util.str_today())),
                           'handling':(product.handling_price if product.handling_price else 0)*quantity,
                           'weight':(product.weight if product.weight else 0) * quantity})
        self.shipping_options = None
        self.shipping_selection = None
Пример #7
0
    def results_export(self):
        report_id = self.request.matchdict.get('report_id')
        rep = Report.load(report_id)
        enterprise_id = self.enterprise_id
        sidx = self.request.GET.get('sidx')  # get index row - i.e. user click to sort
        sord = self.request.GET.get('sord')  # get the direction

        rpt_start_dt = self.request.GET.get('rpt_start_dt') if self.request.GET.get('rpt_start_dt') else util.str_today()
        rpt_end_dt = self.request.GET.get('rpt_end_dt') if self.request.GET.get('rpt_end_dt') else util.str_today()
        rpt_campaign_id = self.request.GET.get('rpt_campaign_id') if 'rpt_campaign_id' in self.request.GET else ''
        rpt_company_id = self.request.GET.get('rpt_company_id') if 'rpt_company_id' in self.request.GET else ''
        rpt_user_id = self.request.GET.get('rpt_user_id') if 'rpt_user_id' in self.request.GET else ''
        rpt_product_id = self.request.GET.get('rpt_product_id') if 'rpt_product_id' in self.request.GET else ''
        rpt_vendor_id = self.request.GET.get('rpt_vendor_id') if 'rpt_vendor_id' in self.request.GET else ''
        rpt_p0 = self.request.GET.get('rpt_p0') if 'rpt_p0' in self.request.GET else ''
        rpt_p1 = self.request.GET.get('rpt_p1') if 'rpt_p1' in self.request.GET else ''
        rpt_p2 = self.request.GET.get('rpt_p2') if 'rpt_p2' in self.request.GET else ''

        sql = rep.sql.format(enterprise_id=enterprise_id,
                             vendor_id=self.request.ctx.user.vendor_id,
                             rpt_start_dt=rpt_start_dt,
                             rpt_end_dt=rpt_end_dt,
                             rpt_campaign_id=rpt_campaign_id,
                             rpt_company_id=rpt_company_id,
                             rpt_user_id=rpt_user_id,
                             rpt_product_id=rpt_product_id,
                             rpt_vendor_id=rpt_vendor_id,
                             rpt_p0=rpt_p0,
                             rpt_p1=rpt_p1,
                             rpt_p2=rpt_p2)
        
        results = db.get_list(sql + (' ORDER BY %s %s ' % (sidx, sord) if sidx else ''))

        self.request.response.content_type = 'application/vnd.ms-excel'
        self.request.response.headers['Content-Disposition'] = 'attachment; filename="report.xls"'
        columns = []
        if rep.column_names:
            jstr = '[{"columns" : %s}]' % rep.column_names.replace("'", '"')
            columns = json.loads(jstr)
            columns = columns[0]['columns']

        return {
            'rows' : results,
            'columns' : columns
            }
Пример #8
0
    def results(self):
        report_id = self.request.matchdict.get('report_id')
        rep = Report.load(report_id)
        page = self.request.GET.get('page', 1)
        limit = self.request.GET.get('rows', 100) # get how many rows we want to have into the grid
        sidx = self.request.GET.get('sidx', None)  # get index row - i.e. user click to sort
        sord = self.request.GET.get('sord', 'asc')  # get the direction

        rpt_start_dt = self.request.GET.get('rpt_start_dt') if self.request.GET.get('rpt_start_dt') else util.str_today()
        rpt_end_dt = self.request.GET.get('rpt_end_dt') if self.request.GET.get('rpt_end_dt') else util.str_today()
        rpt_campaign_id = self.request.GET.get('rpt_campaign_id') if 'rpt_campaign_id' in self.request.GET else ''
        rpt_company_id = self.request.GET.get('rpt_company_id') if 'rpt_company_id' in self.request.GET else ''
        rpt_user_id = self.request.GET.get('rpt_user_id') if 'rpt_user_id' in self.request.GET else ''
        rpt_product_id = self.request.GET.get('rpt_product_id') if 'rpt_product_id' in self.request.GET else ''
        rpt_vendor_id = self.request.GET.get('rpt_vendor_id') if 'rpt_vendor_id' in self.request.GET else ''
        rpt_p0 = self.request.GET.get('rpt_p0') if 'rpt_p0' in self.request.GET else ''
        rpt_p1 = self.request.GET.get('rpt_p1') if 'rpt_p1' in self.request.GET else ''
        rpt_p2 = self.request.GET.get('rpt_p2') if 'rpt_p2' in self.request.GET else ''

        sql = rep.sql.format(enterprise_id=self.enterprise_id,
                             vendor_id=self.request.ctx.user.vendor_id,
                             rpt_start_dt=rpt_start_dt,
                             rpt_end_dt=rpt_end_dt,
                             rpt_campaign_id=rpt_campaign_id,
                             rpt_company_id=rpt_company_id,
                             rpt_user_id=rpt_user_id,
                             rpt_product_id=rpt_product_id,
                             rpt_vendor_id=rpt_vendor_id,
                             rpt_p0=rpt_p0,
                             rpt_p1=rpt_p1,
                             rpt_p2=rpt_p2)

        count = db.get_value('select count(0) from (%s) x' % sql)
        total_pages = 0
        if count > 0:
            total_pages = math.ceil(int(count)/int(limit))
            total_pages = total_pages if total_pages > 1 else 1

        page = min(page, total_pages)

        start = max(int(limit)*int(page)-int(limit), 0)  # // do not put $limit*($page - 1)
        limit = util.nvl(limit, 'all')
        results = db.get_list(sql +
                              (' ORDER BY %s %s ' % (sidx, sord) if sidx else '') +
                              ' LIMIT {limit} offset {start}'.format(limit=limit,
                                                                     start=start))
        response = {
            'page': page,
            'total': int(total_pages),
            'records': int(count)}

        rows = []
        for res_row in results:
            rows.append({'id': str(res_row[0]),
                         'cell': list([unicode(util.nvl(i)) for i in res_row])})

        response['rows'] = rows
        return json.dumps(response)
Пример #9
0
    def _create_subscription(self, prod, order_item, customer, billing):
        try:
            xml = render('/crm/billing/authnet_arb_create_subscription.xml.mako',
                         {'auth_login' : self.authnet_login_id,
                          'auth_key' : self.authnet_transaction_key,
                          'amount' : order_item.total(),
                          'card_number' : billing.get_cc_num(),
                          'exp_date' : billing.cc_exp,
                          'start_date' : util.format_date(order_item.start_dt) if order_item.start_dt else util.str_today(),
                          'total_occurrences' : 9999,
                          'interval_length' : 1,
                          'interval_unit' : 'months',
                          'sub_name' : '',
                          'first_name' : customer.fname,
                          'last_name' : customer.lname
                          })

            headers = {'content-type': 'text/xml'}

            conn = urllib2.Request(url=self._arb_url, data=xml, headers=headers)
            try:
                open_conn = urllib2.urlopen(conn)
                xml_response = open_conn.read()
            except urllib2.URLError: #pragma: no cover
                return (5, '1', 'Could not talk to payment gateway.')

            response = util.xml_str_to_dict(xml_response)['ARBCreateSubscriptionResponse']
            if response['messages']['resultCode'].lower() != 'ok':
                message = response['messages']['message']
                message = message[0] if type(message) == list else message
                self.last_status = message['code']
                self.last_note = message['text']
                return False
            order_item.third_party_id = response['subscriptionId']
            order_item.save()
            return True
        except Exception as exc2: #pragma: no cover
            self.last_status = -1
            self.last_note = exc2.message
        return False  #pragma: no cover