Zum Hauptinhalt springen

zSYNC Code Fields

zSYNC Code Fields are Python based data fields, used across many Worker types (Mapper, Python Code Worker, Web Worker, SQL Executor, and more), to allow for deeper customisability of each pipeline. Data is passed between workers as Zebroo Sets — a Python wrapper around dicts/lists that adds dot-notation access and JSON serialisation — and every code field also gets access to a standard set of variables and helpers.

Available Variables

VariableAvailable InDescription
recordWorkers with list inputThe current record being processed.
dataWorkers with list inputThe full list of all input records.
indexWorkers with list inputIndex (0-based) of the current record.
responseWeb workersThe HTTP response object of the request triggered by the worker.
envAll code fieldsThe Odoo environment, e.g. env['account.move'].
instanceAll code fieldsThe current zbs.instance record (this pipeline run).
instance_envAll code fieldsThe instance environment dict — runtime values shared across workers in the same pipeline run.
varsAll code fieldsNamed, per-environment variables, e.g. vars.my_variable.
environmentAll code fieldsThe current zbs.environment record.
loggerAll code fieldsLogging object, e.g. logger.info(...).
arrowAll code fieldsThe Arrow date library.
datetime, date, timedeltaAll code fieldsPython's standard datetime objects.
base64All code fieldsPython's base64 module.
PathAll code fieldspathlib.Path.
last_execution_dateAll code fieldsDatetime of the last successful pipeline run — commonly used in Grabber domains for incremental syncs.
SkipRecordAll code fieldsException to raise to skip the current record and continue the pipeline.
ZBSPipelineExceptionAll code fieldsException to raise to abort the pipeline with an error.

For record, data, index, and response — the variables tied to the data flowing through the pipeline — see Zebroo Sets.

Odoo Environment (env)

Available in every code field, env is the standard Odoo environment. It gives full access to any model available on the Odoo instance zSYNC is installed on, exactly as in server-side Odoo Python code.

# Browse and act on records directly
env["account.move"].browse(record.invoice_id).action_post()

Instance and Instance Env (instance, instance_env)

instance is the current zbs.instance record — the specific pipeline run currently executing. instance_env is that run's environment dict, used to pass values between workers without routing them through the record data itself (session tokens, counters, flags, or values received from a trigger).

instance_env["session_cookies"] = {"bearer_token": response.headers["Authorization"]}

Variables and Environment (vars, environment)

environment is the current zbs.environment record (e.g. "Production", "Staging") the pipeline is running under. vars gives access to named, typed variables (string/int/float/bool) configured per environment, so the same pipeline can behave differently depending on which environment it runs in.

api_key = vars.my_api_key

Logging (logger)

Use logger to write to the standard Odoo/zSYNC logs instead of print(), so messages show up correctly in log output and instance debugging views.

logger.info(f"Processing record {record.id}")

Dates (arrow, datetime, date, timedelta)

Standard Python date/time handling is available in every code field, plus the Arrow library for more ergonomic date arithmetic and parsing.

from_date = datetime.strptime(record.date, '%Y.%m.%d')
record.date = from_date.strftime('%d/%m/%Y')
record

Other Helpers (base64, Path)

base64 (Python's standard module) and Path (pathlib.Path) are pre-imported for convenience when handling encoded payloads or file paths.

Last Execution Date (last_execution_date)

The datetime of the pipeline's last successful run. Most commonly used in a Grabber's domain/filter to fetch only records changed since then, e.g. an Odoo Grabber domain of [('write_date', '>=', last_execution_date)].

Exceptions

Raise these from any code field to control pipeline flow:

raise SkipRecord # skip this record, continue the pipeline
raise ZBSPipelineException("message") # abort the pipeline with an error
raise RetryableJobError("message", seconds=60) # retry this step after N seconds (Queue Jobs only)
raise RetryInNextTimeframe # retry in the next scheduled run