Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions erpnext/accounts/report/purchase_register/purchase_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import frappe
from frappe import _, msgprint
from frappe.model.meta import get_field_precision
from frappe.query_builder.custom import ConstantColumn
from frappe.utils import flt, getdate
from pypika.terms import Bracket, LiteralValue, Order
Expand Down Expand Up @@ -125,17 +126,32 @@ def _execute(filters=None, additional_table_columns=None):
row.update({frappe.scrub(tax_acc): tax_amount})

# total tax, grand total, rounded total & outstanding amount

outstanding_precision = (
get_field_precision(
frappe.get_meta("Purchase Invoice").get_field("outstanding_amount"),
currency=company_currency,
)
or 2
)
row.update(
{
"total_tax": total_tax,
"grand_total": inv.base_grand_total,
"rounded_total": inv.base_rounded_total,
"outstanding_amount": inv.outstanding_amount,
}
)

if inv.doctype == "Purchase Invoice":
row.update({"debit": inv.base_grand_total, "credit": 0.0})
row.update(
{
"debit": inv.base_grand_total,
"credit": 0.0,
"outstanding_amount": flt(
(inv.outstanding_amount * (inv.conversion_rate or 1)), outstanding_precision
),
}
)
Comment on lines +146 to +154
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Please add regression tests for Purchase Register outstanding conversion.

Line 150-Line 152 changes monetary behavior (conversion + rounding). Add coverage for foreign-currency invoices and precision expectations to prevent regressions.

I can help draft concrete fixtures/assertions if you want.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@erpnext/accounts/report/purchase_register/purchase_register.py` around lines
146 - 154, Add a regression test that verifies outstanding_amount conversion and
rounding in purchase_register logic: create foreign-currency Purchase Invoices
with a non-1 conversion_rate and known outstanding_amount, call the function
that builds rows (the code path that executes row.update with "debit", "credit",
"outstanding_amount" in purchase_register.py) and assert that outstanding_amount
equals flt(inv.outstanding_amount * (inv.conversion_rate or 1),
outstanding_precision) and that debit/credit are set as expected; name the test
e.g. test_purchase_register_outstanding_conversion and include fixtures for an
invoice in another currency, a specific conversion_rate, and expected precision
values to lock in rounding behavior.

else:
row.update({"debit": 0.0, "credit": inv.base_grand_total})
data.append(row)
Expand Down Expand Up @@ -395,6 +411,7 @@ def get_invoices(filters, additional_query_columns):
pi.base_rounded_total,
pi.outstanding_amount,
pi.mode_of_payment,
pi.conversion_rate,
)
.where(pi.docstatus == 1)
)
Expand Down
19 changes: 17 additions & 2 deletions erpnext/accounts/report/sales_register/sales_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,31 @@ def _execute(filters, additional_table_columns=None):

# total tax, grand total, outstanding amount & rounded total

outstanding_precision = (
get_field_precision(
frappe.get_meta("Sales Invoice").get_field("outstanding_amount"),
currency=company_currency,
)
or 2
)
row.update(
{
"tax_total": total_tax,
"grand_total": inv.base_grand_total,
"rounded_total": inv.base_rounded_total,
"outstanding_amount": inv.outstanding_amount,
}
)

if inv.doctype == "Sales Invoice":
row.update({"debit": inv.base_grand_total, "credit": 0.0})
row.update(
{
"debit": inv.base_grand_total,
"credit": 0.0,
"outstanding_amount": flt(
(inv.outstanding_amount * (inv.conversion_rate or 1)), outstanding_precision
),
}
)
Comment on lines +160 to +168
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add regression tests for multi-currency outstanding conversion in Sales Register.

This changes financial output semantics (outstanding_amount now converted and rounded). Please add report-level coverage for at least: foreign-currency invoice, same-currency invoice, and precision assertion on the displayed outstanding value.

If useful, I can draft a focused test matrix and expected values for these scenarios.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@erpnext/accounts/report/sales_register/sales_register.py` around lines 160 -
168, Add regression tests that exercise the Sales Register report's
outstanding_amount conversion and rounding: create one foreign-currency invoice
with conversion_rate != 1 and one same-currency invoice with conversion_rate =
1, set known outstanding_amount and outstanding_precision, run the Sales
Register report (the code path that produces row.update({...
"outstanding_amount": flt((inv.outstanding_amount * (inv.conversion_rate or 1)),
outstanding_precision) })) and assert the returned/displayed outstanding_amount
equals the expected (inv.outstanding_amount * conversion_rate) rounded to
outstanding_precision; include assertions for both invoices and an explicit
precision check to ensure the flt and rounding behavior is correct.

else:
row.update({"debit": 0.0, "credit": inv.base_grand_total})
data.append(row)
Expand Down Expand Up @@ -437,6 +451,7 @@ def get_invoices(filters, additional_query_columns):
si.is_internal_customer,
si.represents_company,
si.company,
si.conversion_rate,
)
.where(si.docstatus == 1)
)
Expand Down
Loading