> For the complete documentation index, see [llms.txt](https://support.ordereazi.com/central/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.ordereazi.com/central/apps/business-systems/cin7-core/rules.md).

# Rules

Use the Cin7 Core app's rules engine to send Quotes, Sales Orders, Tax Invoices, and stock transfers to Cin7 at the workflow steps you choose.

Sending only Sales Orders to Cin7 works for a simple sale. If Cin7 also needs Quotes, Tax Invoices, or stock moved between locations at certain stages, you'd otherwise do it by hand. With the Cin7 Core app's rules engine, each rule says what happens in Cin7 when something happens in OrderEazi, such as a workflow step being completed.

### Before you start

You'll need:

* **The push switches on:** Tick **OrderEazi → Cin7 (push)** and **Sales documents**, under **Sync Settings** on the **Configuration** tab. Without them, every run is skipped. See [Configuration](/central/apps/business-systems/cin7-core/configuration.md).
* **Workflow steps that tell the app:** A rule that waits for a workflow step only fires if that step has **Fire "Action Completed" webhook** ticked in the workflow editor. That setting sends the app a message when the step is done, and it's off by default for new steps. See [Configuring a step](/central/order-management/settings/workflow-manager/configuring-a-step.md).
* **Locations linked:** Transfer rules use your location links on the **Mappings** tab. See [Mappings](/central/apps/business-systems/cin7-core/mappings.md).

> **Note:** The rules engine changes what's sent to Cin7 for every project. Speak to your OrderEazi representative before you switch it on.

### How to set up rules

> **Warning:** With the rules engine on and no rules switched on, nothing is sent to Cin7, not even Sales Orders. Add and switch on your rules before you turn the engine on.

1. On the app's **Rules** tab, choose a template, such as **Direct order (original behaviour)**.
2. Select **Add template**.
3. For each new rule, select **Edit**.
4. Check its locations and step names against your own.
5. Tick **Enabled**.
6. Select **Save**.
7. On the **Configuration** tab, under **Rules Engine**, tick **Rules engine**.
8. Select **Save**.

When you add a template, you see "\[number] rules added, switched off. Check the locations and step names, then switch them on.", with the count in place of \[number]. Each rule you save shows "Rule saved." To build a rule from scratch, select **Add rule** instead of a template.

The templates are:

* **Direct order (original behaviour):** Each Sales Order becomes a draft Cin7 order, as with the rules engine off. It also adds a tracking note when Cin7 ships the sale.
* **Quote, then order on approval:** Quotes become Cin7 quotes, and approval makes them authorised orders. Tax Invoices are then sent to Cin7.
* **Quote, production transfers, invoice:** A Quote becomes a Cin7 order at a workflow step, and stock moves between locations at later steps. The invoice waits until the stock is back.

### How a rule works

Each rule has a **Name**, an **Order**, and an **Enabled** switch, then **When** (the trigger) and **Do** (the action). Matching rules run in their **Order**, about a minute after the event.

**When:**

* **A document is created:** A Quote, Sales Order, Tax Invoice, or Proforma Invoice is created.
* **A workflow step is completed:** You type the step's name as it appears in your workflow. For a question step, you also choose the answer.
* **An order is approved:** It fires once for each project.
* **Cin7 ships the sale:** Cin7 marks the sale shipped or part shipped. This needs **Cin7 → OrderEazi (pull-back)** and **Shipment status** on.

**Do:**

| Action                 | What it does in Cin7                                                         |
| ---------------------- | ---------------------------------------------------------------------------- |
| **Create quote**       | Creates a quote. Only when a Quote is created.                               |
| **Convert to order**   | Turns the project's Cin7 quote into an order.                                |
| **Create sales order** | Creates an order. Only when a Sales Order is created.                        |
| **Create invoice**     | Invoices the project's Cin7 order.                                           |
| **Transfer stock**     | Moves stock between two Cin7 locations.                                      |
| **Read shipment**      | Notes Cin7's tracking details on the project. Only when Cin7 ships the sale. |

Quotes, orders, and invoices can be **Draft** or **Authorised** under **Cin7 status**. Authorised reserves the stock, and Cin7 only invoices an authorised order. With **Create sales order**, a project has one Cin7 order: a newer Sales Order replaces its lines until the order is authorised.

**Example:** Your workflow has a "Ready for packing" step. You add a **Transfer stock** rule: when "Ready for packing" is completed, move the order's lines from "Johannesburg" to "Packing Bay". When a project reaches that step, Cin7 gets a completed transfer for those lines, and the project's history notes it.

### Stock transfers

* **From location** and **To location:** The Cin7 locations to move stock between.
* **Transfer name:** Each project gets each named transfer once. The name can't change once it has moved stock.
* **Which lines:** **Lines drawn from** moves the order's lines that come from a chosen location. **Same lines as transfer** copies another rule's lines. **All sales order lines** and **All project lines** move every line.
* **Never move SKUs starting:** Leaves out products whose SKU (product code) starts with the text you enter, such as SVC for service items.

A transfer never moves more than the **From location** has. Any shortfall is listed on the run, and isn't topped up later. On **Create invoice**, **Wait for transfers** holds the invoice until the transfers you choose have run, and the project notes what it's waiting for.

### How to test a project

1. On the **Rules** tab, go to **Test a project**.
2. Enter a **Project #**.
3. Choose the event, and the document type or step if it needs one.
4. Select **Test**.

Each rule shows **Would run**, **Would wait**, **Would skip**, or **Would fail**, with the lines it would move. Nothing is sent to Cin7.

### How runs are sent and retried

**Runs** lists every rule that fires, with its **Status**, **Retries**, Cin7 reference, and message. Select **Send now** to send a pending run straight away.

A failed run tries again after 1, 5, 15, 60, and 240 minutes, then stops as Failed. A run waiting on another one gives up after a day, or after 30 days for an invoice waiting on transfers.

> **Warning:** **Retry** on a failed run that has a Cin7 reference may send it to Cin7 a second time. Check Cin7 first.

### When a rule doesn't act

* **"OrderEazi → Cin7 sales documents are switched off.":** Tick the push switches on the **Configuration** tab.
* **"The client is on an excluded Cin7 price tier; nothing is sent to Cin7.":** The client's tier is excluded on the **Configuration** tab.
* **"This project has \[number] Cin7 sales (one per OrderEazi warehouse); invoice them in Cin7.", with the count in place of \[number]:** The invoice is skipped, so invoice the sales in Cin7.
* **Lines with no product code:** An invoice fails if any line with no product code has a value. Add a code to each line, then retry. Quotes and orders go ahead without those lines, with a warning.
* **A Cin7 order that isn't authorised:** Cin7 won't invoice it. Authorise the order first.

Projects sent to Cin7 before you turned on the rules engine have no link to their Cin7 sale. Transfer and invoice rules don't act on them.

### Related pages

* [Sales documents and statuses](/central/apps/business-systems/cin7-core/sales-documents-and-statuses.md): how Sales Orders are sent without rules
* [Configuring a step](/central/order-management/settings/workflow-manager/configuring-a-step.md): tick the step setting rules need
* [Logs](/central/apps/business-systems/cin7-core/logs.md): check what each rule did
