feat(report): add Purchase YGB VAT report
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) <noreply@anthropic.com>
This commit is contained in:
parent
97b8b4ed56
commit
72f8292bfe
|
|
@ -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()
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue