Changeset a41029d in rattail


Ignore:
Timestamp:
07/01/18 14:46:35 (2 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
7cfd48b
Parents:
159dd9c
Message:

Add some customization flags for rattail's Product importer

wrt how an "unknown" report code should be handled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/importing/model.py

    r159dd9c ra41029d  
    12491249
    12501250    maxlen_category_code = maxlen(model.Category.code)
     1251
     1252    # set to True in order to auto-create record for "unknown" report code
     1253    auto_create_unknown_report_code = False
     1254
     1255    # set to False in order to log debug instead of warning for "unknown" report code
     1256    warn_for_unknown_report_code = True
    12511257
    12521258    @property
     
    15711577            if code:
    15721578                rc = self.get_reportcode(code)
    1573                 if not rc:
     1579                if rc:
     1580                    product.report_code = rc
     1581                elif self.auto_create_unknown_report_code:
    15741582                    rc = model.ReportCode()
    15751583                    rc.code = code
    1576                     rc.name = "(auto-created)"
     1584                    rc.name = "(no name)"
    15771585                    self.session.add(rc)
    15781586                    if hasattr(self, 'reportcodes'):
    15791587                        self.reportcodes[rc.code] = rc
    1580                 product.report_code = rc
     1588                    product.report_code = rc
     1589                else:
     1590                    logger = log.warning if self.warn_for_unknown_report_code else log.debug
     1591                    logger("unknown report code '%s' for %s", code, product)
     1592                    if product.report_code:
     1593                        product.report_code = None
    15811594            elif product.report_code:
    15821595                product.report_code = None
Note: See TracChangeset for help on using the changeset viewer.