source: client/sapweb.py @ 53a42c4

client
Last change on this file since 53a42c4 was 53a42c4, checked in by Alex Dehnert <adehnert@…>, 11 years ago

pysapweb-based RFP creation script

This requires btidor's pysapweb, currently with some additional patches by me,
which can be found at https://github.com/dehnert/pysapweb. Seem pysapweb's
documentation for getting that set up and its dependencies.

In addition, this includes a sample CSV input file for testing with.

  • Property mode set to 100755
File size: 1.9 KB
Line 
1#!/usr/bin/python
2
3import csv
4import sys
5
6import selenium.common.exceptions
7
8import pysapweb.rfp
9import pysapweb.sap_profiles
10
11def get_profile():
12    try:
13        browser = pysapweb.sap_profiles.load_firefox()
14        return browser
15    except selenium.common.exceptions.WebDriverException as e:
16        print e.msg
17        raise
18
19def to_bool(val):
20    if val == 'True':
21        return True
22    elif val == 'False':
23        return False
24    else:
25        raise ValueError("Expected True or False, got '%s'" % (val, ))
26
27def read_rfp_info(line):
28    id = int(line['id'])
29    name = line['name']
30    addr_fields = ('street', 'city', 'state', 'postal')
31    address = [line['addr.'+f] for f in addr_fields] + ['US']
32    item_fields = ('date', 'gl', 'co', 'amount', 'desc')
33    line_item = [line['item.'+f] for f in item_fields]
34    payee = (to_bool(line['payee.mit']), line['payee.name'])
35    return id, name, address, line_item, payee
36
37def create_rfps(fd):
38    reader = csv.DictReader(fd)
39    browser = get_profile()
40    for line in reader:
41        id, name, address, line_item, payee = read_rfp_info(line)
42        args = dict(
43            name=name,
44            payee=payee,
45            line_items=(line_item, ),
46        )
47        if not payee[0]:
48            args['address'] = address
49        print "args=%s" % (args, )
50        rfp = pysapweb.rfp.create(browser, **args)
51        print "Created voucher %d -> RFP %s" % (id, rfp)
52
53def create_test_rfp():
54    browser = get_profile()
55    address = ('69 School St', 'Cambridge', 'MA', '02139', 'US')
56    line_items = (
57        ('1/1/2014', '421000', '2720842', '12.50', 'test meeting food'),
58    )
59    rfp = pysapweb.rfp.create(browser,
60        name='test RFP',
61        payee=(False, 'Alex Dehnert'),
62        address=address,
63        line_items=line_items,
64    )
65    print "Created RFP %s" % (rfp, )
66
67if __name__ == '__main__':
68    create_rfps(sys.stdin)
Note: See TracBrowser for help on using the repository browser.