Metadata-Version: 2.1
Name: odoo-addon-account_dynamic_rules
Version: 16.0.1.0.1.4
Requires-Python: >=3.10
Requires-Dist: odoo-addon-account_payment_partner>=16.0dev,<16.1dev
Requires-Dist: odoo>=16.0a,<16.1dev
Summary: Dynamic rules for account, product and payment terms mapping
Home-page: https://github.com/OCA/account-financial-tools
License: AGPL-3
Author: Som IT Cooperatiu SCCL, Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 16.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Description-Content-Type: text/markdown

# Account Dynamic Rules

## Overview
Allows to define dynamic rules to set Account, Product or Payment Terms on invoices based on Partner and Product criteria.

## Features
- Define rules matching by Partner, Product, and Payment Mode.
- Automatically update Invoice Line (Account, Product) and Invoice (Payment Term) when a match is found.
- Works for lines created via UI or API (e.g. n8n).

## Configuration
Go to Accounting > Configuration > Account Dynamic Rules.

### Defining Rules (Best Practices)
The engine evaluates rules by **Priority (Sequence)**. The first matching rule wins.

#### 1. Wildcards (Comodines)
You can leave fields empty to act as "Wildcards".
- **Empty Partner**: Applies to **ANY** Partner.
- **Empty Product**: Applies to **ANY** Product.

**Example**:
- Rule A: Partner "Azure" + Product (Empty) -> Account "629000".
    - *Result*: All bills from Azure go to 629000, regardless of the product.

#### 2. Description Matching
Use the **"Description Match"** field to refine rules based on text.
- Logic: "Contains" (Case Insensitive).
- Useful for generic invoices where the service type is in the text.

**Example**:
- Rule B: Partner (Empty) + Description "Hosting" -> Analytic Account "IT Infrastructure".
    - *Result*: Any bill line containing "hosting" (e.g. "Annual Web Hosting", "Hosting Service") gets the analytic account.
    - *Result*: Any bill line containing "hosting" (e.g. "Annual Web Hosting", "Hosting Service") gets the analytic account.

### Advanced Logic

#### 1. Priority & Conflicts
If two rules match the same line (e.g. Rule A matches Partner+Product, Rule B matches Partner+Wildcard), the system **ALWAYS applies the rule with the Lower Sequence**. Specificity does not automatically grant priority.

#### 2. Multiple Rules per Invoice
The engine works **Line by Line**. 
- Line 1 can match Rule A.
- Line 2 can match Rule B.
- Line 3 can match no rule.
This allows a single invoice to have mixed accounts/analytics based on its content.

**Note**: If rules modify **Header Fields** (e.g. Payment Terms), the **last matching line** determines the final value for the whole invoice.

### API & Automation (n8n / Imports)
This module enhances API reliability for **Purchase Invoices (Vendor Bills)**.
If you create an invoice via API (`create` method) and omit certain fields, the system auto-populates them from the Partner:
1.  **Payment Terms**: From `partner.property_payment_term_id`.
2.  **Bank Account**: From first `partner.bank_ids`.
3.  **Payment Mode**: From `partner.supplier_payment_mode_id`.
