Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quotation Summary Report #3

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2024, Navari Limited and contributors
// For license information, please see license.txt

frappe.query_reports["Navari Quotation Summary"] = {
"filters": [
{
"fieldname":"company",
"label": __("Company"),
"fieldtype": "Link",
"options": "Company",
"default": frappe.defaults.get_user_default("Company"),
"width": "100px",
"reqd": 1
},
{
"fieldname":"start_date",
"label": __("Start Date"),
"fieldtype": "Date",
"default": frappe.defaults.get_user_default("year_start_date"),
"reqd": 1,
"width": "100px"
},
{
"fieldname":"end_date",
"label": __("End Date"),
"fieldtype": "Date",
"default": frappe.defaults.get_user_default("year_end_date"),
"reqd": 1,
"width": "100px"
},
{
"fieldname":"status",
"label": __("Status"),
"fieldtype": "Select",
options: [
{ "value": "Approved", "label": __("Approved") },
{ "value": "Pending Approval", "label": __("Pending Approval") },
],
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"add_total_row": 0,
"columns": [],
"creation": "2024-01-11 15:03:53.059911",
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"letter_head": "Default",
"letterhead": null,
"modified": "2024-01-11 15:03:53.059911",
"modified_by": "Administrator",
"module": "Navari Kayes",
"name": "Navari Quotation Summary",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Quotation",
"report_name": "Navari Quotation Summary",
"report_type": "Script Report",
"roles": [
{
"role": "Maintenance User"
},
{
"role": "Sales User"
},
{
"role": "Sales Manager"
},
{
"role": "Maintenance Manager"
},
{
"role": "Executive Manager"
},
{
"role": "CEO"
},
{
"role": "HOD"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

import frappe
from frappe import _, scrub
from pypika import Case
from functools import reduce


def execute(filters=None):
columns = get_columns()
data = get_quotation_data(filters)

return columns, data



def get_columns():
columns = [
{
"label": _("Start Date"),
"fieldname": "start_date",
"fieldtype": "Date",
"width": 100,
},
{
"label": _("End Date"),
"fieldname": "end_date",
"fieldtype": "Date",
"width": 100,
},
{
"label": _("Description"),
"fieldname": "quotation_number",
"fieldtype": "Link",
"options": "Quotation",
"width": 120,
},
{
"label": _("Customer Name"),
"fieldname": "customer_name",
"fieldtype": "Link",
"options": "Customer",
"width": 150,
},
{
"label": _("Status"),
"fieldname": "status",
"fieldtype": "Data",
"width": 100,
},
{
"label": _("VAT Status"),
"fieldname": "vat_status",
"fieldtype": "Data",
"width": 100,
},
{
"label": _("Sales"),
"fieldname": "sales",
"fieldtype": "Currency",
"width": 120,
},
{
"label": _("VAT"),
"fieldname": "vat",
"fieldtype": "Currency",
"width": 100,
},
{
"label": _("Total"),
"fieldname": "total",
"fieldtype": "Currency",
"width": 120,
},
{
"label": _("Cost"),
"fieldname": "cost",
"fieldtype": "Currency",
"width": 120,
},
{
"label": _("Margin"),
"fieldname": "margin",
"fieldtype": "Currency",
"width": 120,
},
]

return columns

def get_quotation_data(filters):
company = filters.get('company')
transaction_date = filters.get('start_date')
valid_till = filters.get('end_date')
status = filters.get('status')

quotation = frappe.qb.DocType("Quotation")
quotation_item = frappe.qb.DocType("Quotation Item")
sales_taxes_charges = frappe.qb.DocType("Sales Taxes and Charges")

conditions = [quotation.docstatus == 1]
if company:
conditions.append(quotation.company == company)
if transaction_date:
conditions.append(quotation.transaction_date == transaction_date)
if valid_till:
conditions.append(quotation.valid_till == valid_till)
if status:
conditions.append(quotation.workflow_state == status)


query = frappe.qb.from_(quotation) \
.inner_join(quotation_item) \
.on(quotation_item.parent == quotation.name) \
.inner_join(sales_taxes_charges) \
.on(sales_taxes_charges.parent == quotation.name) \
.select(
quotation.transaction_date.as_("start_date"),
quotation.valid_till.as_("end_date"),
quotation.name.as_("quotation_number"),
quotation.customer_name,
Case()
.when(quotation.workflow_state == 'Approved', 'Approved')
.else_('Pending Approval')
.as_('status'),
quotation.taxes_and_charges.as_("vat_status"),
quotation.base_total.as_("sales"),
sales_taxes_charges.base_tax_amount.as_("vat"),
sales_taxes_charges.base_total.as_("total"),
quotation_item.valuation_rate.as_("cost"),
quotation_item.gross_profit.as_("profit"),
((quotation_item.gross_profit / quotation.base_total) * 100).as_("margin")
).where(reduce(lambda x, y: x & y, conditions))

data = query.run(as_dict=True)

report_data = []
for row in data:
report_data.append({
"start_date": row["start_date"],
"end_date": row["end_date"],
"quotation_number": row["quotation_number"],
"customer_name": row["customer_name"],
"status": row["status"],
"vat_status": row["vat_status"],
"sales": row["sales"],
"vat": row["vat"],
"total": row["total"],
"cost": row["cost"],
"profit": row["profit"],
"margin": row["margin"]
})
return report_data

Loading