diff --git a/inflatinator/revbank.py b/inflatinator/revbank.py index a403a96..0c4bd4e 100644 --- a/inflatinator/revbank.py +++ b/inflatinator/revbank.py @@ -47,7 +47,16 @@ class Product: price = f'{self.price:.2f}' description = f'"{self.description}"' metadata = ' '.join(sorted(f'#{k}' if v is None else f'#{k}={v}' for (k, v) in self.metadata.items())) - return f'{aliases:<30} {price:<6} {description:<60} {metadata}' + + accum = '' + for col, txt in [ + (30, aliases), + (37, price), + (98, description), + (0, metadata), + ]: + accum += txt + ' ' + ' '*max(0, col-len(accum)-len(txt)) + return accum.rstrip() class NoAutoUpdate(Exception): diff --git a/inflatinator/revbank_test.py b/inflatinator/revbank_test.py index 96db8cb..9b8ddd6 100644 --- a/inflatinator/revbank_test.py +++ b/inflatinator/revbank_test.py @@ -14,3 +14,7 @@ def test_format_product_lines(): '8711327538481,liuk 0.80 "Ola Liuk" #ah=wi162664 #qty=8' assert Product(['5000112659184','colazero'], Decimal(1), 'Cola Zero', {'sligro': None}).format_line() == \ '5000112659184,colazero 1.00 "Cola Zero" #sligro' + assert Product(['8711327607569','8712566340309','magnumwhite'], Decimal(1.50), 'Magnum White chocolate', {'ah': None}).format_line() == \ + '8711327607569,8712566340309,magnumwhite 1.50 "Magnum White chocolate" #ah' + assert Product(['8717677337712','8717677336036','8717677337729'], Decimal(1.95), 'Tony\'s Chocolonely Chocoladereep melk met karamel en zeezout, FT (47 gram)', {'sligro': None}).format_line() == \ + '8717677337712,8717677336036,8717677337729 1.95 "Tony\'s Chocolonely Chocoladereep melk met karamel en zeezout, FT (47 gram)" #sligro'