Skip to content

Conversation

@alexleach
Copy link

Please provide enough information so that others can review your pull request:

Hello!

This is a proposed Draft for automatically adding the following Documents for UK Companies:-

  • Sales Taxes and Charges Templates
  • Purchase Taxes and Charges Templates
  • Item Tax Template
  • Tax Category
  • Tax Rule

Why Draft?
A Report format should be included, too. However, I feel that creating the PR now is useful in order to get feedback on the Templates and Rules made in the initial PR commits.

Background

VAT-registered companies in the UK need to submit their VAT returns electronically, using HMRC's Making Tax Digital (MTD) API submission system.

Creating relevant Templates, Categories and Rules is one of the first major hurdles to having an automated VAT system for UK companies. By having these templates pre-exist in the system, it will help UK VAT-paying companies get off the ground running.

Implementation

Users who create a United Kingdom company will now have the following additions.

  • Two additional VAT Accounts:-

    • Name: VAT
      Root Type: Liability

    • Name: Input VAT
      Root Type: Asset

  • 5 x Sales Taxes and Charges Templates:-

    • UK VAT Standard Rated - [abbr]
    • UK VAT Reduced Rate - [abbr]
    • UK VAT Zero-Rated - [abbr]
    • UK VAT Exempt - [abbr]
    • UK VAT Outside Scope - [abbr]
  • 4 x Purchase Taxes and Charges Templates:-

    • UK VAT Reverse Charge - [abbr]
    • UK VAT Zero-Rated - [abbr]
    • UK VAT Reduced Rate - [abbr]
    • UK VAT Standard Rated - [abbr]
  • 3 x Item Tax Templates:-

    • UK VAT Zero-Rated Item - [abbr]
    • UK VAT Reduced Rate Item - [abbr]
    • UK VAT Standard Rated Item - [abbr]
  • 8 x Tax Rules:-

    • UK to Rest of World Sales - [abbr]
    • UK to EU Sales - [abbr]
    • UK Zero Rated Sales - [abbr]
    • UK Reduced Rate Sales - [abbr]
    • UK Standard Rated Sales - [abbr]
    • UK Zero Rated Purchases - [abbr]
    • UK Reduced Rate Purchases - [abbr]
    • UK Standard Rated Purchases - [abbr]
  • 2 x Tax Categories:-

    • UK Export Customer - Rest of World
    • UK Export Customer - EU

Creating reports from these accounts should hopefully then be relatively simple.

Alternative Implementation
New Chart of Account (CoA) templates can be added to one of the erpnext/accounts/doctype/account/chart_of_accounts/ subdirectories. However, the UK does not have a formalised Chart of Accounts (CoA), so each UK company (or accountant) can use a unique Chart of Accounts. Therefore, I have relied on the existing Standard and "Standard with Numbers" CoAs.


Explain the details for making this change. What existing problem does the pull request solve?

As per the Regional documentation:-

ERPNext aims to support local regulation for all the regions in the world.

There is at least one Open Issue / Feature Request relating to UK Tax:-

I have been working on a fork of https://github.com/software-to-hardware/erpnext-vat-mtd, where I found one of the first major challenges is understanding how to set up these relevant templates correctly. The original repository is abandoned, and the code author has gone AWOL.

When I started to figure out how to add these templates etc in the plugin, I found ERPNext's existing regional and setup modules do this for other countries already, and in the long term, I think are a better home for these new Rules and Template Documents.


TODO

  • Add Report
  • Account Numbers are not added when using the "Standard with Numbers" CoA template
  • Review proposed Templates, Categories and Rules
  • [Optional]: Submit VAT returns to HMRC MTD system. Otherwise, will be done in plugin.

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Nov 5, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

📝 Walkthrough

Walkthrough

Adds a new UK regional setup module with two functions: setup(company=None, patch=True) (no-op placeholder) and update_regional_tax_settings(country=None, company=None), which builds and persists eight UK-specific Tax Rule records (covering UK domestic purchases/sales, UK→EU sales, and UK→Rest of World sales) and renames existing Tax Rule documents to the constructed names. Replaces the prior single United Kingdom tax entry in country_wise_tax.json with a detailed configuration containing tax_categories and chart_of_accounts templates: multiple sales_tax_templates, purchase_tax_templates (including reverse-charge entries with negative rates), and item_tax_templates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • Review tax rule creation and renaming flow in erpnext/regional/united_kingdom/setup.py for correctness and edge cases (company abbreviation extraction, name collisions).
  • Verify template lookups by title and company and that referenced template names exist in erpnext/setup/setup_wizard/data/country_wise_tax.json.
  • Validate JSON structure and numeric values (rates, negative reverse-charge rates) and account_head/root_type consistency.
  • Check effects on existing Tax Rule records when renaming and creation (autoname behavior, uniqueness).

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add UK Tax Rules and Categories' clearly summarizes the main change, accurately reflecting the addition of tax rules and tax categories for UK companies in the changeset.
Description check ✅ Passed The description provides comprehensive context explaining the purpose, implementation details, and motivation for adding UK-specific tax templates, rules, and categories for VAT compliance and HMRC MTD readiness.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fee13ad and 39e01b0.

📒 Files selected for processing (1)
  • erpnext/setup/setup_wizard/data/country_wise_tax.json (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: alexleach
Repo: frappe/erpnext PR: 50373
File: erpnext/regional/united_kingdom/setup.py:28-31
Timestamp: 2025-11-05T16:19:19.499Z
Learning: In ERPNext's setup wizard flow, `update_regional_tax_settings` is called from `setup_taxes_and_charges` in `erpnext/setup/setup_wizard/operations/taxes_setup.py` only after `from_detailed_data()` has created all tax templates from `country_wise_tax.json`, guaranteeing that templates exist when regional tax rules are created.
📚 Learning: 2025-11-05T16:19:19.499Z
Learnt from: alexleach
Repo: frappe/erpnext PR: 50373
File: erpnext/regional/united_kingdom/setup.py:28-31
Timestamp: 2025-11-05T16:19:19.499Z
Learning: In ERPNext's setup wizard flow, `update_regional_tax_settings` is called from `setup_taxes_and_charges` in `erpnext/setup/setup_wizard/operations/taxes_setup.py` only after `from_detailed_data()` has created all tax templates from `country_wise_tax.json`, guaranteeing that templates exist when regional tax rules are created.

Applied to files:

  • erpnext/setup/setup_wizard/data/country_wise_tax.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Summary
🔇 Additional comments (4)
erpnext/setup/setup_wizard/data/country_wise_tax.json (4)

5040-5100: Verify reverse charge template semantics.

The UK VAT Reverse Charge template (lines 5081–5100) uses two tax entries with unusual rate signs: Input VAT with -20.00 rate and VAT (Liability) with +20.00 rate. While this structure is syntactically valid, the semantic interpretation of negative input tax rates for reverse charge scenarios is non-standard. Please confirm this accurately models UK VAT reverse charge accounting within ERPNext's tax calculation engine.


5044-5077: Confirmed: rate vs tax_rate inconsistency has been resolved.

Lines 5050, 5063, 5076, and similar entries in purchase tax templates now correctly use the "rate" field (e.g., lines 5050, 5063, 5076, 5089, 5097), matching the pattern established by sales tax templates and consistent with codebase conventions where Purchase/Sales Templates use "rate" while Item Tax Templates use "tax_rate". This resolves the issue flagged in the previous review.


4981-5168: All required UK tax templates and categories are present and correctly structured.

The United Kingdom section now includes:

  • Tax Categories (2): "UK Export Customer - EU" and "UK Export Customer - Rest of World" ✓
  • Sales Tax Templates (5): Standard Rated, Reduced Rate, Zero-Rated, Exempt, Outside Scope ✓
  • Purchase Tax Templates (4): Standard Rated, Reduced Rate, Zero-Rated, Reverse Charge ✓
  • Item Tax Templates (3): Standard Rated Item, Reduced Rate Item, Zero-Rated Item ✓

Naming convention is consistent ("UK VAT [Type]"), and structure mirrors established patterns (Germany, Australia) with the wildcard "*" CoA key serving as the default. Item templates properly reference both Asset and Liability root_types for Input VAT and VAT accounts respectively.


4981-5010: Confirm account references are guaranteed to exist when templates are created.

The sales and purchase tax templates reference account names "VAT" and "Input VAT" without explicit creation logic in this JSON. Per the learnings provided, update_regional_tax_settings() in the regional setup module is called after from_detailed_data() has processed this JSON. Please verify that the account creation (VAT as Liability, Input VAT as Asset) either occurs within that flow or is documented as a prerequisite.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (3)
erpnext/setup/setup_wizard/data/country_wise_tax.json (1)

4992-5038: Consider adding root_type to sales tax account definitions.

The sales tax templates define account heads without specifying root_type. Other countries' configurations (e.g., France at lines 608-610) explicitly set root_type: "Liability" for VAT accounts. While the system may infer this, explicit specification ensures consistent account creation.

Consider this update:

 							{
 								"account_head": {
 									"account_name": "VAT",
+									"root_type": "Liability",
 									"tax_rate": 20.00
 								},
 								"rate": 20.00
 							}

Apply similar changes to all sales tax templates (lines 4997-5003, 5010-5015, 5022-5027).

erpnext/regional/united_kingdom/setup.py (2)

8-9: Placeholder function noted.

The setup() function is currently a placeholder. Consider adding a docstring to document its intended future purpose or remove it if not needed.


12-12: Remove unused country parameter.

The country parameter in update_regional_tax_settings() is never used in the function body.

-def update_regional_tax_settings(country=None, company=None):
+def update_regional_tax_settings(company=None):
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc78109 and fee13ad.

📒 Files selected for processing (2)
  • erpnext/regional/united_kingdom/setup.py (1 hunks)
  • erpnext/setup/setup_wizard/data/country_wise_tax.json (1 hunks)
🔇 Additional comments (3)
erpnext/setup/setup_wizard/data/country_wise_tax.json (2)

4982-4989: LGTM! Tax categories align with UK VAT export requirements.

The two tax categories properly distinguish between EU and Rest of World exports, which is essential for UK VAT compliance post-Brexit.


5102-5166: LGTM! Item tax templates are well-structured.

The item tax templates correctly define both Input VAT (Asset) and VAT (Liability) components, following the pattern established by other countries like Germany. This allows proper tax calculation for items in both purchase and sales contexts.

erpnext/regional/united_kingdom/setup.py (1)

123-128: Verify tax rule creation is idempotent.

The function doesn't check if tax rules already exist before calling make_records(). If this function is called multiple times (e.g., during a patch rerun), it could create duplicate tax rules or fail during renaming.

Run the following script to check the behavior when tax rules already exist:

Consider adding a check to skip creation if tax rules already exist:

# Check if tax rules already exist
existing_rules = frappe.get_all("Tax Rule", filters={"company": company, "name": ["like", "UK%"]})
if existing_rules:
	frappe.logger().info(f"UK Tax Rules already exist for company {company}, skipping creation")
	return

@alexleach alexleach marked this pull request as draft November 5, 2025 17:22
@stale
Copy link

stale bot commented Nov 21, 2025

This pull request has been automatically marked as inactive because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing.

@stale stale bot added the inactive label Nov 21, 2025
@stale stale bot removed the inactive label Nov 22, 2025
@alexleach alexleach force-pushed the uk-tax branch 3 times, most recently from 5fe6df4 to 1223098 Compare November 24, 2025 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-tests This PR needs automated unit-tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant