[shopoob] Improvements + pep8 fixes
This commit is contained in:
parent
f7e7e45760
commit
8ae6ad68aa
1 changed files with 51 additions and 29 deletions
80
weboob/applications/shopoob/shopoob.py
Executable file → Normal file
80
weboob/applications/shopoob/shopoob.py
Executable file → Normal file
|
|
@ -30,29 +30,24 @@ __all__ = ['Shopoob']
|
||||||
|
|
||||||
|
|
||||||
class OrdersFormatter(IFormatter):
|
class OrdersFormatter(IFormatter):
|
||||||
MANDATORY_FIELDS = ('id', 'date', 'discount', 'shipping', 'tax', 'total')
|
MANDATORY_FIELDS = ('id', 'date', 'total')
|
||||||
|
|
||||||
def start_format(self, **kwargs):
|
def start_format(self, **kwargs):
|
||||||
self.output('%sId Date Discount Shipping Tax Total ' % ((' ' * 15) if not self.interactive else ''))
|
self.output(' Id Date Total ')
|
||||||
self.output('-------------%s+------------+----------+----------+----------+----------' % (('-' * 15) if not self.interactive else ''))
|
self.output('-----------------------------+------------+-----------')
|
||||||
|
|
||||||
def format_obj(self, obj, alias):
|
def format_obj(self, obj, alias):
|
||||||
date = obj.date.strftime('%Y-%m-%d') if not empty(obj.date) else ''
|
date = obj.date.strftime('%Y-%m-%d') if not empty(obj.date) else ''
|
||||||
discount = obj.discount or Decimal('0')
|
|
||||||
shipping = obj.shipping or Decimal('0')
|
|
||||||
tax = obj.tax or Decimal('0')
|
|
||||||
total = obj.total or Decimal('0')
|
total = obj.total or Decimal('0')
|
||||||
result = u'%s %s %s %s %s %s' % (self.colored('%-28s' % obj.fullid, 'yellow'),
|
result = u'%s %s %s' % (self.colored('%-28s' % obj.fullid, 'yellow'),
|
||||||
self.colored('%-10s' % date, 'blue'),
|
self.colored('%-10s' % date, 'blue'),
|
||||||
self.colored('%9.2f' % discount, 'green'),
|
self.colored('%9.2f' % total, 'green'))
|
||||||
self.colored('%9.2f' % shipping, 'green'),
|
|
||||||
self.colored('%9.2f' % tax, 'green'),
|
|
||||||
self.colored('%9.2f' % total, 'green'))
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.output(u'-------------%s+------------+----------+----------+----------+----------' % (('-' * 15) if not self.interactive else ''))
|
self.output(u'----------------------------+------------+-----------')
|
||||||
|
|
||||||
|
|
||||||
class ItemsFormatter(IFormatter):
|
class ItemsFormatter(IFormatter):
|
||||||
MANDATORY_FIELDS = ('label', 'url', 'price')
|
MANDATORY_FIELDS = ('label', 'url', 'price')
|
||||||
|
|
@ -64,14 +59,15 @@ class ItemsFormatter(IFormatter):
|
||||||
def format_obj(self, obj, alias):
|
def format_obj(self, obj, alias):
|
||||||
price = obj.price or Decimal('0')
|
price = obj.price or Decimal('0')
|
||||||
result = u'%s %s %s' % (self.colored('%-75s' % obj.label[:75], 'yellow'),
|
result = u'%s %s %s' % (self.colored('%-75s' % obj.label[:75], 'yellow'),
|
||||||
self.colored('%-43s' % obj.url, 'magenta'),
|
self.colored('%-43s' % obj.url, 'magenta'),
|
||||||
self.colored('%9.2f' % price, 'green'))
|
self.colored('%9.2f' % price, 'green'))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.output(u'---------------------------------------------------------------------------+---------------------------------------------+----------')
|
self.output(u'---------------------------------------------------------------------------+---------------------------------------------+----------')
|
||||||
|
|
||||||
|
|
||||||
class PaymentsFormatter(IFormatter):
|
class PaymentsFormatter(IFormatter):
|
||||||
MANDATORY_FIELDS = ('date', 'method', 'amount')
|
MANDATORY_FIELDS = ('date', 'method', 'amount')
|
||||||
|
|
||||||
|
|
@ -83,20 +79,21 @@ class PaymentsFormatter(IFormatter):
|
||||||
date = obj.date.strftime('%Y-%m-%d') if not empty(obj.date) else ''
|
date = obj.date.strftime('%Y-%m-%d') if not empty(obj.date) else ''
|
||||||
amount = obj.amount or Decimal('0')
|
amount = obj.amount or Decimal('0')
|
||||||
result = u'%s %s %s' % (self.colored('%-10s' % date, 'blue'),
|
result = u'%s %s %s' % (self.colored('%-10s' % date, 'blue'),
|
||||||
self.colored('%-17s' % obj.method, 'yellow'),
|
self.colored('%-17s' % obj.method, 'yellow'),
|
||||||
self.colored('%9.2f' % amount, 'green'))
|
self.colored('%9.2f' % amount, 'green'))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
self.output(u'-----------+-----------------+----------')
|
self.output(u'-----------+-----------------+----------')
|
||||||
|
|
||||||
|
|
||||||
class Shopoob(ReplApplication):
|
class Shopoob(ReplApplication):
|
||||||
APPNAME = 'shopoob'
|
APPNAME = 'shopoob'
|
||||||
VERSION = '1.1'
|
VERSION = '1.1'
|
||||||
COPYRIGHT = 'Copyright(C) 2015 Christophe Lampin'
|
COPYRIGHT = 'Copyright(C) 2015 Christophe Lampin'
|
||||||
DESCRIPTION = 'Console application to obtain details and status of e-commerce orders.'
|
DESCRIPTION = 'Console application to obtain details and status of e-commerce orders.'
|
||||||
SHORT_DESCRIPTION = "obtain details and status of e-commerce orders"
|
SHORT_DESCRIPTION = "Obtain details and status of e-commerce orders"
|
||||||
CAPS = CapShop
|
CAPS = CapShop
|
||||||
COLLECTION_OBJECTS = (Order, )
|
COLLECTION_OBJECTS = (Order, )
|
||||||
EXTRA_FORMATTERS = {'orders': OrdersFormatter,
|
EXTRA_FORMATTERS = {'orders': OrdersFormatter,
|
||||||
|
|
@ -108,7 +105,7 @@ class Shopoob(ReplApplication):
|
||||||
'items': 'items',
|
'items': 'items',
|
||||||
'payments': 'payments',
|
'payments': 'payments',
|
||||||
'ls': 'orders',
|
'ls': 'orders',
|
||||||
}
|
}
|
||||||
|
|
||||||
def main(self, argv):
|
def main(self, argv):
|
||||||
self.load_config()
|
self.load_config()
|
||||||
|
|
@ -117,27 +114,46 @@ class Shopoob(ReplApplication):
|
||||||
@defaultcount(10)
|
@defaultcount(10)
|
||||||
def do_orders(self, line):
|
def do_orders(self, line):
|
||||||
"""
|
"""
|
||||||
orders
|
orders [BACKEND_NAME]
|
||||||
|
|
||||||
List all orders.
|
Get orders of a backend.
|
||||||
|
If no BACKEND_NAME given, display all orders of all backends.
|
||||||
"""
|
"""
|
||||||
|
if len(line) > 0:
|
||||||
|
backend_name = line
|
||||||
|
else:
|
||||||
|
backend_name = None
|
||||||
|
|
||||||
|
self.do_count(str(self.options.count)) # Avoid raise of MoreResultsAvailable
|
||||||
|
l = []
|
||||||
|
for order in self.do('iter_orders', backends=backend_name):
|
||||||
|
l.append(order)
|
||||||
|
|
||||||
self.start_format()
|
self.start_format()
|
||||||
for order in self.do('iter_orders'):
|
for order in sorted(l, self.comp_object):
|
||||||
self.format(order)
|
self.format(order)
|
||||||
|
|
||||||
|
# Order by date DESC
|
||||||
|
def comp_object(self, obj1, obj2):
|
||||||
|
if obj1.date == obj2.date:
|
||||||
|
return 0
|
||||||
|
elif obj1.date < obj2.date:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
def do_items(self, id):
|
def do_items(self, id):
|
||||||
"""
|
"""
|
||||||
items [ID]
|
items [ID]
|
||||||
|
|
||||||
Get items of orders.
|
Get items of orders.
|
||||||
If no ID given, display all details of all backends.
|
|
||||||
"""
|
"""
|
||||||
l = []
|
l = []
|
||||||
id, backend_name = self.parse_id(id)
|
id, backend_name = self.parse_id(id, unique_backend=True)
|
||||||
|
|
||||||
if not id:
|
if not id:
|
||||||
for order in self.get_object_list('iter_orders'):
|
print('Error: please give a order ID (hint: use orders command)', file=self.stderr)
|
||||||
l.append((order.id, order.backend))
|
return 2
|
||||||
else:
|
else:
|
||||||
l.append((id, backend_name))
|
l.append((id, backend_name))
|
||||||
|
|
||||||
|
|
@ -163,7 +179,13 @@ class Shopoob(ReplApplication):
|
||||||
Get payments of orders.
|
Get payments of orders.
|
||||||
If no ID given, display payment of all backends.
|
If no ID given, display payment of all backends.
|
||||||
"""
|
"""
|
||||||
self.start_format()
|
|
||||||
for payment in self.do('iter_payments', id):
|
|
||||||
self.format(payment)
|
|
||||||
|
|
||||||
|
id, backend_name = self.parse_id(id, unique_backend=True)
|
||||||
|
|
||||||
|
if not id:
|
||||||
|
print('Error: please give a order ID (hint: use orders command)', file=self.stderr)
|
||||||
|
return 2
|
||||||
|
|
||||||
|
self.start_format()
|
||||||
|
for payment in self.do('iter_payments', id, backends=backend_name):
|
||||||
|
self.format(payment)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue