Fix how bottle deposit amounts are calculated, for Catapult export
This commit is contained in:
parent
c330cfccb5
commit
aefaaf8351
|
@ -29,6 +29,7 @@ import logging
|
||||||
|
|
||||||
from sqlalchemy.exc import ProgrammingError
|
from sqlalchemy.exc import ProgrammingError
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
from corepos import enum as corepos_enum
|
from corepos import enum as corepos_enum
|
||||||
from corepos.db.office_op import model as corepos
|
from corepos.db.office_op import model as corepos
|
||||||
|
@ -172,6 +173,29 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo
|
||||||
# tax_component_ids_1 = (1,)
|
# tax_component_ids_1 = (1,)
|
||||||
# tax_component_ids_2 = (2,)
|
# tax_component_ids_2 = (2,)
|
||||||
|
|
||||||
|
self.deposits = {}
|
||||||
|
deposits = self.host_session.query(corepos.Product.deposit.distinct())\
|
||||||
|
.all()
|
||||||
|
|
||||||
|
def cache(deposit, i):
|
||||||
|
assert isinstance(deposit, tuple)
|
||||||
|
assert len(deposit) == 1
|
||||||
|
deposit = deposit[0]
|
||||||
|
if deposit:
|
||||||
|
deposit = int(deposit)
|
||||||
|
upc = "{:013d}".format(deposit)
|
||||||
|
try:
|
||||||
|
product = self.host_session.query(corepos.Product)\
|
||||||
|
.filter(corepos.Product.upc == upc)\
|
||||||
|
.one()
|
||||||
|
except NoResultFound:
|
||||||
|
pass # we will log warnings per-item later
|
||||||
|
else:
|
||||||
|
self.deposits[deposit] = product
|
||||||
|
|
||||||
|
self.progress_loop(cache, deposits,
|
||||||
|
message="Caching product deposits data")
|
||||||
|
|
||||||
def query(self):
|
def query(self):
|
||||||
query = self.host_session.query(corepos.Product)\
|
query = self.host_session.query(corepos.Product)\
|
||||||
.order_by(corepos.Product.upc)\
|
.order_by(corepos.Product.upc)\
|
||||||
|
@ -247,6 +271,15 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo
|
||||||
product.upc, diff, product)
|
product.upc, diff, product)
|
||||||
price_divider = product.quantity
|
price_divider = product.quantity
|
||||||
|
|
||||||
|
bottle_deposit = None
|
||||||
|
if product.deposit:
|
||||||
|
deposit = int(product.deposit)
|
||||||
|
if deposit in self.deposits:
|
||||||
|
bottle_deposit = self.deposits[deposit].normal_price
|
||||||
|
else:
|
||||||
|
log.warning("product %s has unknown deposit %s which will be ignored: %s",
|
||||||
|
product.upc, deposit, product)
|
||||||
|
|
||||||
sold_by_ea_or_lb = None
|
sold_by_ea_or_lb = None
|
||||||
if is_plu:
|
if is_plu:
|
||||||
sold_by_ea_or_lb = 'LB' if product.scale else 'EA'
|
sold_by_ea_or_lb = 'LB' if product.scale else 'EA'
|
||||||
|
@ -420,7 +453,7 @@ class InventoryItemImporter(FromCore, catapult_importing.model.InventoryItemImpo
|
||||||
# TODO: does CORE have these?
|
# TODO: does CORE have these?
|
||||||
# 'disc_mult': None,
|
# 'disc_mult': None,
|
||||||
|
|
||||||
'bottle_deposit': product.deposit or None,
|
'bottle_deposit': bottle_deposit,
|
||||||
|
|
||||||
# TODO: does CORE have this?
|
# TODO: does CORE have this?
|
||||||
# 'pos_menu_group': None,
|
# 'pos_menu_group': None,
|
||||||
|
|
Loading…
Reference in a new issue