feat(report): add Purchase invoice info report

New Script Report grouping purchase-type Purchase Invoices by Act Type,
showing counterparty (ФИО/company/country), VOEN/FIN, and amount.
Includes a link column to the source Purchase Invoice and optional
date-range filters; formula-editor friendly (no total row).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-06-23 09:47:04 +00:00
parent aaa352098c
commit 5d2a218087
4 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,19 @@
// Copyright (c) 2026, Company and contributors
// For license information, please see license.txt
frappe.query_reports["Purchase invoice info report"] = {
"filters": [
{
"fieldname": "from_date",
"label": __("From Date"),
"fieldtype": "Date",
"default": frappe.datetime.add_months(frappe.datetime.get_today(), -1)
},
{
"fieldname": "to_date",
"label": __("To Date"),
"fieldtype": "Date",
"default": frappe.datetime.get_today()
}
]
};

View File

@ -0,0 +1,23 @@
{
"add_total_row": 0,
"columns": [],
"creation": "2026-06-23 12:00:00",
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letterhead": null,
"modified": "2026-06-23 13:00:00",
"modified_by": "Administrator",
"module": "Taxes Az",
"name": "Purchase invoice info report",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Purchase Invoice",
"report_name": "Purchase invoice info report",
"report_type": "Script Report",
"roles": [],
"timeout": 0
}

View File

@ -0,0 +1,120 @@
# Copyright (c) 2026, Company and contributors
# For license information, please see license.txt
import frappe
from frappe import _
def execute(filters=None):
"""Main function for report execution"""
columns = get_columns(filters)
data = get_data(filters)
return columns, data
def get_columns(filters=None):
"""Get report columns definition"""
return [
{
"label": _("Purchase Invoice"),
"fieldname": "purchase_invoice",
"fieldtype": "Link",
"options": "Purchase Invoice",
"width": 160
},
{
"label": _("Act Type"),
"fieldname": "act_type",
"fieldtype": "Data",
"width": 120
},
{
"label": _("Counterparty"),
"fieldname": "counterparty",
"fieldtype": "Data",
"width": 240
},
{
"label": _("VOEN"),
"fieldname": "voen",
"fieldtype": "Data",
"width": 130
},
{
"label": _("FIN"),
"fieldname": "fin",
"fieldtype": "Data",
"width": 130
},
{
"label": _("Amount"),
"fieldname": "amount",
"fieldtype": "Currency",
"width": 140
}
]
def get_data(filters=None):
"""Get report data"""
filters = filters or {}
conditions = ""
if filters.get("from_date"):
conditions += " AND pi.posting_date >= %(from_date)s"
if filters.get("to_date"):
conditions += " AND pi.posting_date <= %(to_date)s"
rows = frappe.db.sql(f"""
SELECT
pi.name AS purchase_invoice,
pi.act_type,
pi.agricultural_country,
pi.supplier_name,
pi.grand_total,
sup.supplier_type,
sup.tax_id,
sup.fin
FROM
`tabPurchase Invoice` pi
LEFT JOIN
`tabSupplier` sup ON sup.name = pi.supplier
WHERE
pi.docstatus = 1
AND pi.purchase_type = 1
{conditions}
ORDER BY
pi.posting_date DESC, pi.name
""", filters, as_dict=1)
data = []
for r in rows:
# Column 2-4 depend on the act type / supplier type:
# Import -> counterparty = country, VOEN/FIN empty
# Individual -> counterparty = full name (ФИО), FIN filled
# Company (MMC) -> counterparty = company name, VOEN filled
if r.act_type == "Import":
counterparty = r.agricultural_country or ""
voen = ""
fin = ""
elif r.supplier_type == "Individual":
counterparty = r.supplier_name or ""
voen = ""
fin = r.fin or ""
else:
counterparty = r.supplier_name or ""
voen = r.tax_id or ""
fin = ""
data.append({
"purchase_invoice": r.purchase_invoice,
"act_type": r.act_type or "",
"counterparty": counterparty,
"voen": voen,
"fin": fin,
"amount": r.grand_total or 0
})
return data