Changeset f34703e in rattail


Ignore:
Timestamp:
07/22/2022 12:38:16 PM (7 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
032dcc3
Parents:
dfadd3f
Message:

Add flags for auto-creating brand in product importers

if brands are tracked with foreign system key, then auto-create is
probably not suitable since new brand won't get the key

Location:
rattail
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rattail/datasync/daemon.py

    rdfadd3f rf34703e  
    653653                return False
    654654
     655            else: # more attempts to be made, but log error for debug
     656                log.debug("attempt #%s failed calling `consumer.process_changes()`",
     657                          attempts, exc_info=True)
     658
    655659            # if this exception is not the first, and is of a different type
    656660            # than seen previously, do *not* continue to retry
  • rattail/importing/model.py

    rdfadd3f rf34703e  
    17161716    def set_config_flags(self):
    17171717
     1718        # set to True in order to auto-create record for "unknown" brand
     1719        self.auto_create_unknown_brand = self.config.getbool(
     1720            'rattail.importing', 'products.auto_create_unknown_brand',
     1721            default=False)
     1722
    17181723        # set to True in order to auto-create record for "unknown" category
    17191724        self.auto_create_unknown_category = self.config.getbool(
     
    17251730            'rattail.importing', 'products.auto_create_unknown_report_code',
    17261731            default=False)
     1732
     1733        # set to False in order to log debug instead of warning for "unknown" brand
     1734        self.warn_for_unknown_brand = self.config.getbool(
     1735            'rattail.importing', 'products.warn_for_unknown_brand',
     1736            default=True)
    17271737
    17281738        # set to False in order to log debug instead of warning for "unknown" category
     
    19671977    def update_object(self, product, data, local_data=None):
    19681978        product = super(ProductImporter, self).update_object(product, data, local_data)
     1979        model = self.model
    19691980
    19701981        if 'brand_name' in self.fields:
     
    19721983            if name:
    19731984                brand = self.get_brand(name)
    1974                 if not brand:
     1985                if brand:
     1986                    product.brand = brand
     1987                elif self.auto_create_unknown_brand:
    19751988                    brand = model.Brand()
    19761989                    brand.name = name
    19771990                    self.session.add(brand)
    19781991                    if hasattr(self, 'brands'):
    1979                         self.brands[brand.name] = brand
    1980                 product.brand = brand
     1992                        self.brands[name] = brand
     1993                    product.brand = brand
     1994                else:
     1995                    logger = log.warning if self.warn_for_unknown_brand else log.debug
     1996                    logger("unknown brand for product %s: %s", product.uuid, name)
     1997                    if product.brand:
     1998                        product.brand = None
    19811999            elif product.brand:
    19822000                product.brand = None
Note: See TracChangeset for help on using the changeset viewer.