From 72f8292bfebd1adc8e083c9ec00c1f07513c4195 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Wed, 24 Jun 2026 15:24:41 +0000 Subject: [PATCH] feat(report): add Purchase YGB VAT report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per-document purchase report (Cədvəl 21 — ƏDV - YGB hesabat). A Purchase Invoice qualifies when submitted and at least one of purchase_type / agricultural_goods is set (items are not filtered). Columns: document, date, line code, YGB, amount without VAT (net_total) and VAT amount. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../purchase_ygb_vat_report/__init__.py | 0 .../purchase_ygb_vat_report.js | 26 +++++ .../purchase_ygb_vat_report.json | 23 ++++ .../purchase_ygb_vat_report.py | 102 ++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 taxes_az/taxes_az/report/purchase_ygb_vat_report/__init__.py create mode 100644 taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.js create mode 100644 taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.json create mode 100644 taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.py diff --git a/taxes_az/taxes_az/report/purchase_ygb_vat_report/__init__.py b/taxes_az/taxes_az/report/purchase_ygb_vat_report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.js b/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.js new file mode 100644 index 0000000..4d5b5e0 --- /dev/null +++ b/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.js @@ -0,0 +1,26 @@ +// Copyright (c) 2026, Company and contributors +// For license information, please see license.txt + +frappe.query_reports["Purchase YGB VAT report"] = { + "filters": [ + { + "fieldname": "company", + "label": __("Company"), + "fieldtype": "Link", + "options": "Company", + "default": frappe.defaults.get_user_default("Company") + }, + { + "fieldname": "from_date", + "label": __("From Date"), + "fieldtype": "Date", + "default": frappe.datetime.month_start() + }, + { + "fieldname": "to_date", + "label": __("To Date"), + "fieldtype": "Date", + "default": frappe.datetime.month_end() + } + ] +}; diff --git a/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.json b/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.json new file mode 100644 index 0000000..7a674d5 --- /dev/null +++ b/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.json @@ -0,0 +1,23 @@ +{ + "add_total_row": 0, + "columns": [], + "creation": "2026-06-24 14:00:00", + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "letterhead": null, + "modified": "2026-06-24 14:00:00", + "modified_by": "Administrator", + "module": "Taxes Az", + "name": "Purchase YGB VAT report", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Purchase Invoice", + "report_name": "Purchase YGB VAT report", + "report_type": "Script Report", + "roles": [], + "timeout": 0 +} diff --git a/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.py b/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.py new file mode 100644 index 0000000..99bd6da --- /dev/null +++ b/taxes_az/taxes_az/report/purchase_ygb_vat_report/purchase_ygb_vat_report.py @@ -0,0 +1,102 @@ +# 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 (Cədvəl 21 — ƏDV - YGB hesabat).""" + return [ + { + "label": _("Purchase Invoice"), + "fieldname": "purchase_invoice", + "fieldtype": "Link", + "options": "Purchase Invoice", + "width": 160 + }, + { + # YGB-nin tarixi + "label": _("Date"), + "fieldname": "posting_date", + "fieldtype": "Date", + "width": 100 + }, + { + # Sətir kodu + "label": _("Line Code"), + "fieldname": "line_code", + "fieldtype": "Data", + "width": 100 + }, + { + "label": _("YGB"), + "fieldname": "ygb", + "fieldtype": "Data", + "width": 140 + }, + { + # YGB üzrə alınmış malın ƏDV-siz dəyəri, manatla + "label": _("Amount without VAT"), + "fieldname": "amount_without_vat", + "fieldtype": "Currency", + "width": 180 + }, + { + # YGB üzrə alınmış malın ƏDV məbləği, manatla + "label": _("VAT amount"), + "fieldname": "vat_amount", + "fieldtype": "Currency", + "width": 160 + } + ] + + +def get_data(filters=None): + """Get report data — one row per qualifying Purchase Invoice. + + A document qualifies when it is submitted and at least one of the + purchase_type / agricultural_goods flags is set. Items are not filtered. + """ + filters = filters or {} + + conditions = "pi.docstatus = 1 AND (pi.agricultural_goods = 1 OR pi.purchase_type = 1)" + params = {} + + if filters.get("company"): + conditions += " AND pi.company = %(company)s" + params["company"] = filters["company"] + + if filters.get("from_date"): + conditions += " AND pi.posting_date >= %(from_date)s" + params["from_date"] = filters["from_date"] + + if filters.get("to_date"): + conditions += " AND pi.posting_date <= %(to_date)s" + params["to_date"] = filters["to_date"] + + rows = frappe.db.sql(f""" + SELECT + pi.name AS purchase_invoice, + pi.posting_date, + pi.line_code, + pi.ygb, + pi.net_total AS amount_without_vat, + pi.total_taxes_and_charges AS vat_amount + FROM + `tabPurchase Invoice` pi + WHERE + {conditions} + ORDER BY + pi.posting_date, pi.name + """, params, as_dict=1) + + return rows