Add prettier UPCs to ordering worksheet report.

This commit is contained in:
Lance Edgar 2015-02-11 03:27:31 -06:00
parent bf18bab909
commit bc06a72993

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2014 Lance Edgar # Copyright © 2010-2015 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -20,7 +20,6 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Report Views Report Views
""" """
@ -46,14 +45,18 @@ plu_upc_pattern = re.compile(r'^000000000(\d{5})$')
weighted_upc_pattern = re.compile(r'^002(\d{5})00000\d$') weighted_upc_pattern = re.compile(r'^002(\d{5})00000\d$')
def get_upc(product): def get_upc(product):
upc = '%014u' % product.upc """
UPC formatter. Strips PLUs to bare number, and adds "minus check digit"
for non-PLU UPCs.
"""
upc = unicode(product.upc)
m = plu_upc_pattern.match(upc) m = plu_upc_pattern.match(upc)
if m: if m:
return str(int(m.group(1))) return unicode(int(m.group(1)))
m = weighted_upc_pattern.match(upc) m = weighted_upc_pattern.match(upc)
if m: if m:
return str(int(m.group(1))) return unicode(int(m.group(1)))
return upc return '{0}-{1}'.format(upc[:-1], upc[-1])
class OrderingWorksheet(View): class OrderingWorksheet(View):