Changeset eb08988 in rattail


Ignore:
Timestamp:
07/01/18 16:51:04 (2 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
3f924b1
Parents:
7cfd48b
Message:

Add customization flags for rattail's Product importer, category fields

wrt how an "unknown" category code/number should be handled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/importing/model.py

    r7cfd48b reb08988  
    33#
    44#  Rattail -- Retail Software Framework
    5 #  Copyright © 2010-2017 Lance Edgar
     5#  Copyright © 2010-2018 Lance Edgar
    66#
    77#  This file is part of Rattail.
     
    3030import logging
    3131
     32import six
    3233from sqlalchemy import orm
    3334from sqlalchemy.orm.exc import NoResultFound
     
    12501251    maxlen_category_code = maxlen(model.Category.code)
    12511252
     1253    # set to True in order to auto-create record for "unknown" category
     1254    auto_create_unknown_category = False
     1255
    12521256    # set to True in order to auto-create record for "unknown" report code
    12531257    auto_create_unknown_report_code = False
     1258
     1259    # set to False in order to log debug instead of warning for "unknown" category
     1260    warn_for_unknown_category = True
    12541261
    12551262    # set to False in order to log debug instead of warning for "unknown" report code
     
    15291536
    15301537                category = self.get_category_by_code(code)
    1531                 if not category:
     1538                if category:
     1539                    product.category = category
     1540                elif self.auto_create_unknown_category:
    15321541                    category = model.Category()
    15331542                    category.code = code
     
    15391548                    if hasattr(self, 'categories'):
    15401549                        self.categories[code] = category
    1541                 product.category = category
     1550                    product.category = category
     1551                else:
     1552                    logger = log.warning if self.warn_for_unknown_category else log.debug
     1553                    logger("unknown category code '%s' for %s", code, product)
     1554                    if product.category:
     1555                        product.category = None
     1556
    15421557            elif product.category:
    15431558                product.category = None
     
    15461561            number = data['category_number']
    15471562            if number:
    1548                 cat = self.get_category_by_number(number)
    1549                 if not cat:
    1550                     cat = model.Category()
    1551                     cat.number = number
    1552                     cat.name = "(auto-created)"
    1553                     self.session.add(cat)
     1563                category = self.get_category_by_number(number)
     1564                if category:
     1565                    product.category = category
     1566                elif self.auto_create_unknown_category:
     1567                    category = model.Category()
     1568                    category.number = number
     1569                    category.code = six.text_type(number)
     1570                    category.name = "(auto-created)"
     1571                    self.session.add(category)
    15541572                    if hasattr(self, 'categories'):
    1555                         self.categories[number] = cat
    1556                 product.category = cat
     1573                        self.categories[number] = category
     1574                    product.category = category
     1575                else:
     1576                    logger = log.warning if self.warn_for_unknown_category else log.debug
     1577                    logger("unknown category number '%s' for %s", number, product)
     1578                    if product.category:
     1579                        product.category = None
    15571580            elif product.category:
    15581581                product.category = None
Note: See TracChangeset for help on using the changeset viewer.