Skip to content

Commit 00341ea

Browse files
bosdclaude
andcommitted
Add documentation for VAT validation management
- Add VIES/VAT Manager to API reference (autodoc) - Add Module Manager to API reference (autodoc) - Add comprehensive VAT Validation Management guide section - Include CLI usage examples, programmatic usage, and custom validators 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 86bce87 commit 00341ea

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

docs/guides/odoo_workflows.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,168 @@ odoo-data-flow module uninstall --modules stock,account
8080

8181
---
8282

83+
## VAT Validation Management
84+
85+
When importing large numbers of contacts into Odoo, VAT validation can cause significant issues:
86+
87+
* **VIES (VAT Information Exchange System):** Online EU VAT validation that causes API timeouts with many contacts
88+
* **stdnum validation:** Python-based local format checking that adds CPU overhead
89+
90+
The `vat` command group allows you to temporarily disable these validations during imports and restore them afterwards.
91+
92+
### Checking Current Settings
93+
94+
Before making changes, you can check the current VAT validation settings for all companies:
95+
96+
```bash
97+
odoo-data-flow vat get-settings --connection-file conf/connection.conf
98+
```
99+
100+
This displays a table showing which companies have VIES checking enabled.
101+
102+
### Disabling VAT Validation for Import
103+
104+
To disable VAT validation before a large contact import:
105+
106+
```bash
107+
# Disable and save settings to a file for later restoration
108+
odoo-data-flow vat disable --connection-file conf/connection.conf --output vat_settings.json
109+
110+
# Disable only VIES (keep stdnum validation)
111+
odoo-data-flow vat disable --connection-file conf/connection.conf --no-stdnum --output vat_settings.json
112+
113+
# Disable for specific companies only
114+
odoo-data-flow vat disable --connection-file conf/connection.conf --company-ids 1,2,3 --output vat_settings.json
115+
```
116+
117+
#### Command-Line Options
118+
119+
| Option | Description |
120+
| :--- | :--- |
121+
| `--connection-file` | **(Required)** Path to your connection config file. |
122+
| `--company-ids` | Comma-separated list of company IDs. If omitted, applies to all companies. |
123+
| `--vies/--no-vies` | Enable/disable VIES online check. Default: disable. |
124+
| `--stdnum/--no-stdnum` | Enable/disable stdnum format validation. Default: disable. |
125+
| `--output` | Save original settings to a JSON file for later restoration. |
126+
127+
### Restoring VAT Validation Settings
128+
129+
After your import is complete, restore the original settings:
130+
131+
```bash
132+
odoo-data-flow vat restore --connection-file conf/connection.conf --input vat_settings.json
133+
```
134+
135+
### Batch VAT Validation
136+
137+
After importing contacts with validation disabled, you can validate VAT numbers in controlled batches to avoid API timeouts:
138+
139+
```bash
140+
# Validate all partners with VAT numbers
141+
odoo-data-flow vat validate --connection-file conf/connection.conf --batch-size 50 --delay 1.0
142+
143+
# Validate with user notifications on failures
144+
odoo-data-flow vat validate --connection-file conf/connection.conf --notify-users 1,2
145+
146+
# Validate only companies
147+
odoo-data-flow vat validate --connection-file conf/connection.conf \
148+
--domain "[('is_company', '=', True)]" \
149+
--max-records 1000
150+
```
151+
152+
#### Command-Line Options
153+
154+
| Option | Description |
155+
| :--- | :--- |
156+
| `--connection-file` | **(Required)** Path to your connection config file. |
157+
| `--batch-size` | Number of records per batch. Default: 50. |
158+
| `--delay` | Seconds to wait between batches. Default: 1.0. |
159+
| `--notify-users` | Comma-separated user IDs to notify on failures. |
160+
| `--domain` | Odoo domain filter (e.g., `"[('is_company', '=', True)]"`). |
161+
| `--max-records` | Maximum number of records to validate. |
162+
163+
### Complete Import Workflow Example
164+
165+
Here's a typical workflow for importing contacts with VAT validation management:
166+
167+
```bash
168+
# 1. Save current settings and disable validation
169+
odoo-data-flow vat disable --connection-file conf/connection.conf --output vat_settings.json
170+
171+
# 2. Run the contact import
172+
odoo-data-flow import --connection-file conf/connection.conf \
173+
--file contacts.csv \
174+
--model res.partner \
175+
--worker 4 \
176+
--size 500
177+
178+
# 3. Restore VAT validation settings
179+
odoo-data-flow vat restore --connection-file conf/connection.conf --input vat_settings.json
180+
181+
# 4. Validate VAT numbers in batches with notifications
182+
odoo-data-flow vat validate --connection-file conf/connection.conf \
183+
--batch-size 50 \
184+
--delay 2.0 \
185+
--notify-users 1
186+
```
187+
188+
### Programmatic Usage
189+
190+
You can also use these functions programmatically in Python:
191+
192+
```python
193+
from odoo_data_flow.lib.actions.vies_manager import (
194+
disable_vat_validation,
195+
restore_vat_validation_settings,
196+
run_import_with_vat_validation_disabled,
197+
)
198+
199+
# Option 1: Manual control
200+
settings = disable_vat_validation("conf/connection.conf")
201+
# ... run your import ...
202+
restore_vat_validation_settings("conf/connection.conf", settings)
203+
204+
# Option 2: Context manager style
205+
from odoo_data_flow.importer import run_import
206+
207+
result = run_import_with_vat_validation_disabled(
208+
config="conf/connection.conf",
209+
import_func=run_import,
210+
import_kwargs={
211+
"config": "conf/connection.conf",
212+
"filename": "contacts.csv",
213+
"model": "res.partner",
214+
# ... other import options
215+
},
216+
)
217+
```
218+
219+
### Custom VAT Validators
220+
221+
For high-performance VAT validation, you can replace the default Python validator with a custom implementation (e.g., Rust-based via PyO3):
222+
223+
```python
224+
from odoo_data_flow.lib.actions.vies_manager import (
225+
set_custom_vat_validator,
226+
validate_vat_local,
227+
)
228+
229+
# Define a custom validator function
230+
def my_rust_validator(vat: str) -> tuple[bool, str | None]:
231+
# Call your Rust library here
232+
from my_rust_vat_lib import validate
233+
result = validate(vat)
234+
return result.is_valid, result.error_message
235+
236+
# Register it
237+
set_custom_vat_validator(my_rust_validator)
238+
239+
# Now validate_vat_local() will use your custom validator
240+
is_valid, error = validate_vat_local("BE0123456789")
241+
```
242+
243+
---
244+
83245
## Data Processing Workflows
84246

85247
This command group is for running multi-step processes on records that are already in the database.

docs/reference.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,27 @@ These modules contain the high-level functions that are called by the CLI comman
5656
.. automodule:: odoo_data_flow.migrator
5757
:members: run_migration
5858
```
59+
60+
## Actions
61+
62+
These modules contain action functions for managing Odoo server state.
63+
64+
### VIES/VAT Manager (`lib.actions.vies_manager`)
65+
66+
This module provides functions for managing VAT validation settings during imports.
67+
68+
```{eval-rst}
69+
.. automodule:: odoo_data_flow.lib.actions.vies_manager
70+
:members: get_vat_validation_settings, disable_vat_validation, restore_vat_validation_settings, run_vies_validation, run_import_with_vat_validation_disabled, validate_vat_format, validate_vat_local, set_custom_vat_validator
71+
:member-order: bysource
72+
```
73+
74+
### Module Manager (`lib.actions.module_manager`)
75+
76+
This module provides functions for managing Odoo modules.
77+
78+
```{eval-rst}
79+
.. automodule:: odoo_data_flow.lib.actions.module_manager
80+
:members: run_module_installation, run_module_uninstallation, run_update_module_list
81+
:member-order: bysource
82+
```

0 commit comments

Comments
 (0)