rattail.batch.vendorcatalog

Handler for Vendor Catalog batches

class rattail.batch.vendorcatalog.VendorCatalogHandler(config, **kwargs)[source]

Handler for vendor catalog batches.

allow_future()[source]

Returns boolean indicating whether “future” cost changes should be allowed.

Returns:

True if future cost changes allowed; else False.

batch_model_class

alias of VendorCatalogBatch

cost_differs(row, cost)[source]

Compare a batch row with a cost record to determine whether they match or differ.

identify_product(row)[source]

Try to locate the product represented by the given row. Lookups are done using either the upc or vendor_code attributes of the row.

Under normal circumstances the batch handler will have pre-cached all existing products, for quicker lookup. For instance this is the case for the full populate and refresh actions. But this logic is able to do its own slower lookups if there is no cache available.

Parameters:

row – A VendorCatalogBatchRow instance.

Returns:

A Product instance, or None if no match could be found.

populate(batch, progress=None)[source]

Default logic just invokes populate_from_file().

populate_from_file(batch, progress=None)[source]

Populate the given batch using data from its input file. A catalog parser will be instantiated and asked to read row data from the file. Each row is then added to the batch.

The batch must have valid filename and parser_key attributes. The path to the input file will be determined by invoking the filepath() method on the batch.

Parameters:
  • batch – The batch to be populated.

  • progress – Optional progress factory.

refresh_row(row)[source]

Refresh data attributes and status for the given row.

For a vendor catalog, the typical thing is done for basic product attributes.

If case cost is known but unit cost is not, the latter will be calculated if possible.

“Old” (i.e. “current” prior to batch execution) values will all be re-fetched from the main database(s), and “diff” values will be re-calculated.

Parameters:

row – A VendorCatalogBatchRow instance.

setup_populate(batch, progress=None)

Perform any setup (caching etc.) necessary for populating a batch.

setup_refresh(batch, progress=None)

Perform any setup (caching etc.) necessary for refreshing a batch.

should_populate(batch)[source]

Must return a boolean indicating whether the given batch should be populated from an initial data source, i.e. at time of batch creation. Override this method if you need to inspect the batch in order to determine whether the populate step is needed. Default behavior is to simply return the value of populate_batches.