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
| Variable | Available In | Description |
|---|---|---|
record | Workers with list input | The current record being processed. |
data | Workers with list input | The full list of all input records. |
index | Workers with list input | Index (0-based) of the current record. |
response | Web workers | The HTTP response object of the request triggered by the worker. |
env | All code fields | The Odoo environment, e.g. env['account.move']. |
instance | All code fields | The current zbs.instance record (this pipeline run). |
instance_env | All code fields | The instance environment dict — runtime values shared across workers in the same pipeline run. |
vars | All code fields | Named, per-environment variables, e.g. vars.my_variable. |
environment | All code fields | The current zbs.environment record. |
logger | All code fields | Logging object, e.g. logger.info(...). |
arrow | All code fields | The Arrow date library. |
datetime, date, timedelta | All code fields | Python's standard datetime objects. |
base64 | All code fields | Python's base64 module. |
Path | All code fields | pathlib.Path. |
last_execution_date | All code fields | Datetime of the last successful pipeline run — commonly used in Grabber domains for incremental syncs. |
SkipRecord | All code fields | Exception to raise to skip the current record and continue the pipeline. |
ZBSPipelineException | All code fields | Exception to raise to abort the pipeline with an error. |
For
record,data,index, andresponse— 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