Add support for importing full size, uom data from CORE
also add core-specific product handler and mixin, to find all UOM abbreviations in the wild.
This commit is contained in:
parent
10c119ea60
commit
2faa0cb18b
4 changed files with 147 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -24,7 +24,10 @@
|
|||
Rattail model importer extensions, for CORE-POS integration
|
||||
"""
|
||||
|
||||
import decimal
|
||||
|
||||
from rattail import importing
|
||||
from rattail.util import pretty_quantity
|
||||
|
||||
|
||||
##############################
|
||||
|
@ -97,6 +100,14 @@ class ProductImporter(importing.model.ProductImporter):
|
|||
'corepos_id',
|
||||
]
|
||||
|
||||
def setup(self):
|
||||
super(ProductImporter, self).setup()
|
||||
|
||||
if self.fields_active(self.size_fields):
|
||||
app = self.config.get_app()
|
||||
handler = app.get_products_handler()
|
||||
self.uoms = handler.get_uom_sil_codes(self.session, uppercase=True)
|
||||
|
||||
def cache_query(self):
|
||||
query = super(ProductImporter, self).cache_query()
|
||||
model = self.config.get_model()
|
||||
|
@ -108,6 +119,51 @@ class ProductImporter(importing.model.ProductImporter):
|
|||
|
||||
return query
|
||||
|
||||
def get_uom_code(self, uom):
|
||||
if hasattr(self, 'uoms'):
|
||||
return self.uoms.get(uom.upper())
|
||||
|
||||
app = self.config.get_app()
|
||||
handler = app.get_products_handler()
|
||||
return handler.get_uom_sil_code(self.session, uom.upper())
|
||||
|
||||
def normalize_size_info(self, core_product):
|
||||
|
||||
# convert product to dict if needed
|
||||
if isinstance(core_product, dict):
|
||||
core_data = core_product
|
||||
else:
|
||||
core_data = {
|
||||
'size': core_product.size,
|
||||
'unitofmeasure': core_product.unit_of_measure,
|
||||
}
|
||||
|
||||
unit_size = None
|
||||
if 'size' in core_data and core_data['size'] is not None:
|
||||
unit_size = decimal.Decimal(core_data['size'])
|
||||
|
||||
uom_abbrev = core_data.get('unitofmeasure')
|
||||
|
||||
uom_code = self.enum.UNIT_OF_MEASURE_NONE
|
||||
if uom_abbrev is not None:
|
||||
uom_code = self.get_uom_code(uom_abbrev) or self.enum.UNIT_OF_MEASURE_NONE
|
||||
|
||||
if unit_size is not None and uom_abbrev is not None:
|
||||
size = "{} {}".format(pretty_quantity(unit_size), uom_abbrev)
|
||||
elif unit_size is not None:
|
||||
size = pretty_quantity(unit_size)
|
||||
elif uom_abbrev is not None:
|
||||
size = uom_abbrev
|
||||
else:
|
||||
size = None
|
||||
|
||||
return {
|
||||
'size': size,
|
||||
'unit_size': unit_size,
|
||||
'uom_abbrev': uom_abbrev,
|
||||
'uom_code': uom_code,
|
||||
}
|
||||
|
||||
|
||||
class ProductCostImporter(importing.model.ProductCostImporter):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue