Skip to content

Purchase Register report doubles tax amount when Purchase Invoice and Purchase Receipt share the same name #54250

@sagarrgarg

Description

@sagarrgarg

Information about bug

Description

The Purchase Register report (purchase_register.py) shows doubled tax amounts for Purchase Invoices when a Purchase Receipt
exists with the same document name.

Root Cause

In get_invoice_tax_map() (erpnext/accounts/report/purchase_register/purchase_register.py, line 497-510), the SQL query on
tabPurchase Taxes and Charges filters by parent IN (...) but does not filter by parenttype = 'Purchase Invoice'.

Since Purchase Taxes and Charges is a shared child table used by Purchase Invoice, Purchase Receipt, and Purchase Order — when a PI
and PR share the same name, the SUM() picks up tax rows from both documents, doubling the amount.

-- Current (buggy):
SELECT parent, account_head, ... sum(base_tax_amount_after_discount_amount) ...
FROM `tabPurchase Taxes and Charges`                                                                                                   
WHERE parent IN (%s) AND category IN ('Total', 'Valuation and Total')
GROUP BY parent, account_head, add_deduct_tax                                                                                          
                                                                                                                                       
-- Fix: add parenttype filter
... WHERE parent IN (%s) AND parenttype = 'Purchase Invoice' AND category IN ('Total', 'Valuation and Total') 

Comparison
                                                                                                                                       
- get_invoice_expense_map() (same file, line 463) correctly filters parenttype='Purchase Invoice'                                      
- get_taxes_query() in utils.py (line 224) correctly filters parenttype == parenttype
- Only get_invoice_tax_map() is missing the filter                                                                                     
                                                                                                                                       
How to reproduce
                                                                                                                                       
1. Create a Purchase Receipt with name X                                                                                               
2. Create a Purchase Invoice with the same name X (via custom naming or matching series)
3. Both should have tax rows (e.g., IGST)                                                                                              
4. Open Purchase Register report for the date range covering that invoice                                                              
5. Observe: the tax column shows 2x the actual tax amount                                                                              
6. The grand_total column is correct (comes from the PI doc field), but total_tax is doubled                                           
                                                                                                                                       

### Module

accounts

### Version

                                                                                                   
Frappe version -- v15
ERPNext version -- v15

### Installation method

FrappeCloud

### Relevant log output / Stack trace / Full Error Message.

```shell
No error/stack trace — this is a silent data bug in report output.
The fix is a one-line addition of and parenttype = 'Purchase Invoice' at line 503 of:                                                  
erpnext/accounts/report/purchase_register/purchase_register.py

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions