With inclusive pricing and a discount on Grand Total the Total line is
the tax-inclusive item total and the discount is printed as entered,
followed by Total After Discount, which the Net Total and charge lines
then break down. Other cases keep the net layout: Total (net before
discount), the discount's net share, Net Total, charges. Thai label for
Total After Discount.
ERPNext takes an Additional Discount off the items' net amounts and,
for a discount on Grand Total, splits it between net and taxes: each
charge is booked at tax_amount_after_discount_amount and Total Taxes
and Charges sums those. The print showed the discount as entered and
the pre-discount tax_amount, so on a Grand Total discount the VAT line
disagreed with the invoice.
The totals includes now print the discount's net share (sum of
item.distributed_discount_amount), Net Total, and each charge after
discount, so the lines add up to Grand Total whichever total the
discount applies on and with inclusive or exclusive tax. A discount
that is not distributed (cash / non-trade) stays after the charges.
Default Standard Sales Invoice and Tax Invoice/Receipt printed the
Additional Discount Amount among the charges, after the Total line but
with no total after the discount. App copies of ERPNext's totals
includes are swapped in via doc.print_templates:
- taxes.html: a discount on Net Total is followed by the Net Total line
ahead of the charges; a discount on Grand Total stays after them.
- total.html: with inclusive tax, "Total (Without Tax)" is the total
before the discount (net_total + discount_amount); upstream printed
net_total, which already has the discount taken off, so the same
figure appeared before and after the discount line.
"Shipping Charges - <abbr>": Selling, Fixed, posting to a "Shipping
Charges" income account under Direct Income (created if the chart lacks
it) with the default cost center. Shipping Rule is named by its label,
so the company abbreviation keeps one rule per company, as ERPNext
names its tax templates. Created on Company save, after install, and by
a patch for existing companies.
The amount is entered on the transaction, not the rule: ERPNext
re-applies the rule on every recalculation and would reset the charge
row to the rule's fixed amount. ThaiShippingRule overrides the doctype
class so a Fixed rule with no amount only seeds the row and leaves the
entered amount alone.
Location fixture: "All Locations" group with Head Office, Branch Office and
Warehouse. Fixture import re-inserts tree nodes with fresh lft/rgt, which
strands locations users add beneath them, so after_migrate rebuilds the
Location tree.
Asset Category fixture: Land (non-depreciable), Buildings (20 years),
Plant and Machinery, Vehicles, Furniture and Fixtures, Office Equipment,
Computers and Electronics, Software (5 years) and Intangible Assets
(10 years), per Royal Decree 145 rates; monthly straight-line, daily
pro-rata. The accounts table is company-specific and therefore not
shipped: an Asset Category before_import hook links every Thai company
(same contract as the WHT categories), reusing the Standard chart's
fixed asset accounts and creating Land, Vehicles and Intangible Assets
under Fixed Assets. Company.on_update links new companies. Depreciation
accounts are left to the Company defaults.
get_or_create_account now takes account_type and parent_groups.
Submitted Income Tax Slab "Thailand Personal Income Tax" (THB, effective
2017-01-01) with the eight progressive brackets 0% to 35%, using the HRMS
from/to convention (150,001-300,000 etc.). standard_tax_exemption_amount
is 160,000: the Sec. 42 bis expense deduction (50%, max 100,000) plus the
personal allowance (60,000), which every employee gets without filing a
declaration. The "Expense Deduction" category and "Personal allowance"
sub-category are dropped from the exemption fixtures so they cannot be
counted twice; Personal and Family Allowances cap becomes 270,000.
Fixtures for Employee Tax Exemption Category / Sub Category covering the
Thai PIT allowances (personal and family, insurance, retirement savings,
Thai ESG/ESGX, social security, home loan interest, donations, income
exemptions, stimulus measures) plus the Sec. 42 bis expense deduction.
Category caps follow HRMS validation: a sub-category max must not exceed
its category max and the declaration caps the category total, so groups
with a real combined limit carry it, groups without one use the sum of
their sub caps, and uncapped per-person/percentage items live in 0-cap
categories. Social Security uses the 2026 ceiling (10,500/yr); SSF is
kept inactive. sync_fixtures skips these files on sites without hrms.
Per Thai company: Thailand VAT 7%, Thailand VAT 7% (Included) for
VAT-inclusive pricing, Thailand VAT 0% for zero-rated supplies. Sales
schemes post to Output VAT, purchase schemes to Input VAT (category
Total, so recoverable VAT stays out of valuation). The 7% scheme is the
default when the company has none. Created on Company save, after
install, and by a patch for existing companies.
Thai VAT is filed on P.P.30 as output tax (ภาษีขาย, collected on sales)
net of input tax (ภาษีซื้อ, paid on purchases); ERPNext's wizard makes a
single VAT account. Both join the per-company tax accounts created on
Company save and fixture import; a patch adds them to existing companies.
Account names are translated for the chart of accounts tree.
- translations/th.csv: custom field labels, messages, print format and
letter head text, the 22 Tax Withholding Category names; overrides the
upstream Thai for the standard labels the print formats show
- print formats embed Sarabun (public/fonts, OFL) so PDFs render Thai on
servers without a Thai font
- letter head labels go through _()
- withholding row description is translated when stored
- in_words: Thai "...บาทถ้วน" wording via num2words when the language is
Thai (ThaiSalesInvoice.set_total_in_words); print formats re-derive it
in the print language (get_in_words)
- fixture `modified` bumped so migrate re-imports the changed documents
- Split the Customer block into two columns: name / address / tax id on
the left, contact person with phone, mobile and email on the right
(only when the invoice has a contact person; phone read from Contact)
- Thailand Address Template: drop the blank line between the address and
the phone / fax / email lines
- Hide Total Quantity, Update Billed Amount in Delivery Note, Amount
Eligible for Commission and Company Tax ID (already in the letterhead)
- Move Posting Date / Payment Due Date into the print heading, right-aligned
- Add a Customer block (name, address, contact, tax id) under the heading
- Render Total (Without Tax) in the same right-half grid as Taxes / Totals
- Put In Words in the empty left column of Totals, level with Grand Total
- Print Format CSS: one 1.8 line-height rhythm with no row margins, 5px
letterhead margin, 5px margins around the item table
frappe.call filters kwargs to the target signature; the *args/**kwargs
wrapper accepted 'cmd' and forwarded it to ERPNext's function. Mirror
the original signature.
Tick Apply Tax Withholding Amount on unsaved customer receipts whose
references include a Sales Invoice carrying withholding: in the
get_payment_entry override (Create > Payment), in the
allocate_amount_to_references doc method (Get Outstanding Invoices /
Paid Amount changes, so the tax row updates live) and on first save.
Saved entries keep the user's choice; unticking now removes the row.
Client script recomputes the row when the checkbox or category changes.
With a deduction row ERPNext treats Paid Amount as cash received and
credits the party for paid + deduction, so a gross Paid Amount (what Get
Outstanding Invoices fills) over-credited Debtors and posted the gross
to the bank. Use the taxes table with add_deduct_tax=Deduct like
supplier TDS: Paid Amount is the gross settlement, bank receives paid
minus withholding, receivable is debited. Override Payment Entry
build_gl_map to flag the bank entry post_net_value so the merged bank
line shows the net amount.
Move the Sales Invoice withholding fields and both Property Setters from
fixtures to default_thai_company/custom/{sales_invoice,payment_entry}.json
with sync_on_migrate. sync_customizations updates Custom Fields in place
instead of the delete/re-insert that fixtures do on every migrate.
Custom fields Tax Withholding Category (fetched from Customer),
Withholding Tax and Net Payable After Withholding Tax on Sales Invoice;
computed in the Thai set_tax_withholding override from the category
rate and single threshold, informational only (totals/GL unchanged),
printed under Rounded Total by the standard layout. Payment Entry now
prefers each invoice's category over the customer's.
Integration tests on a throwaway Thai company: account creation and
category linking on Company insert, site-configured account surviving
fixture re-import, Sales Invoice left un-grossed, and Payment Entry
deductions (full, prorated, below threshold, unchecked). Run with
CI=1 bench --site <site> run-tests --app default_thai_company.
Thai customers withhold tax at payment; ERPNext's customer-side handling
is Indian TCS which adds tax on top of the Sales Invoice. Override
SalesInvoice.set_tax_withholding to no-op for Thai companies, expose
"Apply Tax Withholding Amount" on Customer/Receive Payment Entries, and
on validate compute rate x pre-VAT amount of each allocated reference
(prorated, single threshold honoured) as a deduction to "Withholding Tax
Receivable". Client script fetches the Customer's category when the box
is ticked.
Add 22 Tax Withholding Category fixtures covering Thailand domestic
withholding (Taw.Paw. 4/2528, Sec. 50(2), Sec. 70) with rates and
thresholds. Fixtures ship without accounts; on import each Thai company
gets "Withholding Tax Payable" (Liability) and "Withholding Tax
Receivable" (Asset) created and the payable account linked. Company
on_update does the same for companies created later. Site-configured
accounts survive fixture re-import on migrate.