Add Product.get_default_pack_item()
convenience method
This commit is contained in:
parent
26a561ff21
commit
323eb81c1f
|
@ -1,8 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2017 Lance Edgar
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -27,6 +27,7 @@ Data Models for Products
|
|||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
|
@ -43,6 +44,9 @@ from rattail.db.util import make_full_description
|
|||
from rattail.util import pretty_quantity
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@six.python_2_unicode_compatible
|
||||
class Brand(Base):
|
||||
"""
|
||||
|
@ -422,6 +426,20 @@ class Product(Base):
|
|||
return True
|
||||
return False
|
||||
|
||||
def get_default_pack_item(self):
|
||||
"""
|
||||
Returns the "default" pack item for the current product, which is
|
||||
assumed to be a unit item.
|
||||
"""
|
||||
if self.is_unit_item():
|
||||
for pack in self.packs:
|
||||
if pack.default_pack:
|
||||
return pack
|
||||
if self.packs:
|
||||
log.warning("unit item %s has %s packs, but none is default: %s",
|
||||
self.uuid, len(self.packs), self)
|
||||
return self.packs[0]
|
||||
|
||||
@property
|
||||
def pretty_upc(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue