From 5d2a218087fc322fc6dcdf194af4879a1fdcd0a5 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Tue, 23 Jun 2026 09:47:04 +0000 Subject: [PATCH] feat(report): add Purchase invoice info report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../purchase_invoice_info_report/__init__.py | 0 .../purchase_invoice_info_report.js | 19 +++ .../purchase_invoice_info_report.json | 23 ++++ .../purchase_invoice_info_report.py | 120 ++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 taxes_az/taxes_az/report/purchase_invoice_info_report/__init__.py create mode 100644 taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.js create mode 100644 taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.json create mode 100644 taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.py diff --git a/taxes_az/taxes_az/report/purchase_invoice_info_report/__init__.py b/taxes_az/taxes_az/report/purchase_invoice_info_report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.js b/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.js new file mode 100644 index 0000000..2252569 --- /dev/null +++ b/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.js @@ -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() + } + ] +}; diff --git a/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.json b/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.json new file mode 100644 index 0000000..c4e095d --- /dev/null +++ b/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.json @@ -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 +} diff --git a/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.py b/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.py new file mode 100644 index 0000000..3f2a45c --- /dev/null +++ b/taxes_az/taxes_az/report/purchase_invoice_info_report/purchase_invoice_info_report.py @@ -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