Tax Python
Custom tax calculation with Python code
Tax Python module allows writing custom tax calculation logic with Python code for complex tax cases that cannot be handled by standard configuration.
System supports writing flexible Python formulas to calculate taxes based on multiple conditions, products, partners and special regulations.
Key Features
Key points
• Write tax calculation logic with Python code
• Flexible and complex tax formulas
• Calculate taxes based on multiple conditions
• Support special taxes per regulations
• Debug and test tax formulas
Configure Python Tax
Steps
1. Go to Accounting → Configuration → Taxes
2. Create or edit tax
3. Select Tax Computation: Python Code
4. Write Python code in Python Code field
5. Test formula with sample data
6. Save and apply
Python Code Examples
Sample Tax Formulas
| Case | Code |
|---|---|
| Progressive tax | result = base_amount * 0.1 if base_amount < 1000 else base_amount * 0.15 |
| Product-based tax | result = base_amount * (0.2 if product.categ_id.name == "Luxury" else 0.1) |
| Conditional tax | result = base_amount * 0.05 if partner.country_id.code == "VN" else 0 |
Best Practices
Key points
• Test formulas thoroughly before production
• Document tax logic in code comments
• Use available variables: base_amount, product, partner
• Check edge cases and negative values
• Backup important tax formulas