From 16a6c7c3c0716dfc7941221469c121cc73a51178 2015-02-27 18:49:50 From: Lance Edgar Date: 2015-02-27 18:49:50 Subject: [PATCH] Add `GPC.pretty()` method. --- diff --git a/rattail/db/model/products.py b/rattail/db/model/products.py index 324fb99218fbb41d4827ca0051090fafae0e46c7..d0b7eabf84e3380917190b5c10840aae4edab0bc 100644 --- a/rattail/db/model/products.py +++ b/rattail/db/model/products.py @@ -219,7 +219,7 @@ associates, if any. """ if self.upc is None: return None - return "{0}-{1}".format(unicode(self.upc)[:-1], unicode(self.upc)[-1]) + return self.upc.pretty() def cost_for_vendor(self, vendor): """ diff --git a/rattail/gpc.py b/rattail/gpc.py index 12ebedae74324c1b9a624e03f9a2dc980dde0d28..b6da852e352b58f7fe19f475e3fa1a6184ee1c05 100644 --- a/rattail/gpc.py +++ b/rattail/gpc.py @@ -99,3 +99,11 @@ class GPC(object): def __unicode__(self): return u'%014d' % self.value + + def pretty(self): + """ + Returns the UPC as a somewhat more human-readable string. Basically + that just means the check digit is distinguished by a hyphen. + """ + upc = unicode(self) + return "{0}-{1}".format(upc[:-1], upc[-1])