mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-20 18:54:55 +00:00
fix: currency formatting in item-wise sales history (#33903)
fix: currency formatting in item-wise sales history (#33903)
* fix(item-sales-history): currency formatting
* chore: linting issues
* fix: convert raw sql to qb
(cherry picked from commit 2cc7239dd5)
Co-authored-by: Dany Robert <danyrt@wahni.com>
Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
This commit is contained in:
@@ -41,8 +41,20 @@ def get_columns(filters):
|
|||||||
{"label": _("Description"), "fieldtype": "Data", "fieldname": "description", "width": 150},
|
{"label": _("Description"), "fieldtype": "Data", "fieldname": "description", "width": 150},
|
||||||
{"label": _("Quantity"), "fieldtype": "Float", "fieldname": "quantity", "width": 150},
|
{"label": _("Quantity"), "fieldtype": "Float", "fieldname": "quantity", "width": 150},
|
||||||
{"label": _("UOM"), "fieldtype": "Link", "fieldname": "uom", "options": "UOM", "width": 100},
|
{"label": _("UOM"), "fieldtype": "Link", "fieldname": "uom", "options": "UOM", "width": 100},
|
||||||
{"label": _("Rate"), "fieldname": "rate", "options": "Currency", "width": 120},
|
{
|
||||||
{"label": _("Amount"), "fieldname": "amount", "options": "Currency", "width": 120},
|
"label": _("Rate"),
|
||||||
|
"fieldname": "rate",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"width": 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Amount"),
|
||||||
|
"fieldname": "amount",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"width": 120,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": _("Sales Order"),
|
"label": _("Sales Order"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
@@ -93,8 +105,9 @@ def get_columns(filters):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": _("Billed Amount"),
|
"label": _("Billed Amount"),
|
||||||
"fieldtype": "currency",
|
"fieldtype": "Currency",
|
||||||
"fieldname": "billed_amount",
|
"fieldname": "billed_amount",
|
||||||
|
"options": "currency",
|
||||||
"width": 120,
|
"width": 120,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -104,6 +117,13 @@ def get_columns(filters):
|
|||||||
"options": "Company",
|
"options": "Company",
|
||||||
"width": 100,
|
"width": 100,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": _("Currency"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"fieldname": "currency",
|
||||||
|
"options": "Currency",
|
||||||
|
"hidden": 1,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -141,31 +161,12 @@ def get_data(filters):
|
|||||||
"billed_amount": flt(record.get("billed_amt")),
|
"billed_amount": flt(record.get("billed_amt")),
|
||||||
"company": record.get("company"),
|
"company": record.get("company"),
|
||||||
}
|
}
|
||||||
|
row["currency"] = frappe.get_cached_value("Company", row["company"], "default_currency")
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_conditions(filters):
|
|
||||||
conditions = ""
|
|
||||||
if filters.get("item_group"):
|
|
||||||
conditions += "AND so_item.item_group = %s" % frappe.db.escape(filters.item_group)
|
|
||||||
|
|
||||||
if filters.get("from_date"):
|
|
||||||
conditions += "AND so.transaction_date >= '%s'" % filters.from_date
|
|
||||||
|
|
||||||
if filters.get("to_date"):
|
|
||||||
conditions += "AND so.transaction_date <= '%s'" % filters.to_date
|
|
||||||
|
|
||||||
if filters.get("item_code"):
|
|
||||||
conditions += "AND so_item.item_code = %s" % frappe.db.escape(filters.item_code)
|
|
||||||
|
|
||||||
if filters.get("customer"):
|
|
||||||
conditions += "AND so.customer = %s" % frappe.db.escape(filters.customer)
|
|
||||||
|
|
||||||
return conditions
|
|
||||||
|
|
||||||
|
|
||||||
def get_customer_details():
|
def get_customer_details():
|
||||||
details = frappe.get_all("Customer", fields=["name", "customer_name", "customer_group"])
|
details = frappe.get_all("Customer", fields=["name", "customer_name", "customer_group"])
|
||||||
customer_details = {}
|
customer_details = {}
|
||||||
@@ -187,29 +188,50 @@ def get_item_details():
|
|||||||
|
|
||||||
|
|
||||||
def get_sales_order_details(company_list, filters):
|
def get_sales_order_details(company_list, filters):
|
||||||
conditions = get_conditions(filters)
|
db_so = frappe.qb.DocType("Sales Order")
|
||||||
|
db_so_item = frappe.qb.DocType("Sales Order Item")
|
||||||
|
|
||||||
return frappe.db.sql(
|
query = (
|
||||||
"""
|
frappe.qb.from_(db_so)
|
||||||
SELECT
|
.inner_join(db_so_item)
|
||||||
so_item.item_code, so_item.description, so_item.qty,
|
.on(db_so_item.parent == db_so.name)
|
||||||
so_item.uom, so_item.base_rate, so_item.base_amount,
|
.select(
|
||||||
so.name, so.transaction_date, so.customer,so.territory,
|
db_so.name,
|
||||||
so.project, so_item.delivered_qty,
|
db_so.customer,
|
||||||
so_item.billed_amt, so.company
|
db_so.transaction_date,
|
||||||
FROM
|
db_so.territory,
|
||||||
`tabSales Order` so, `tabSales Order Item` so_item
|
db_so.project,
|
||||||
WHERE
|
db_so.company,
|
||||||
so.name = so_item.parent
|
db_so_item.item_code,
|
||||||
AND so.company in ({0})
|
db_so_item.description,
|
||||||
AND so.docstatus = 1 {1}
|
db_so_item.qty,
|
||||||
""".format(
|
db_so_item.uom,
|
||||||
",".join(["%s"] * len(company_list)), conditions
|
db_so_item.base_rate,
|
||||||
),
|
db_so_item.base_amount,
|
||||||
tuple(company_list),
|
db_so_item.delivered_qty,
|
||||||
as_dict=1,
|
(db_so_item.billed_amt * db_so.conversion_rate).as_("billed_amt"),
|
||||||
|
)
|
||||||
|
.where(db_so.docstatus == 1)
|
||||||
|
.where(db_so.company.isin(tuple(company_list)))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if filters.get("item_group"):
|
||||||
|
query = query.where(db_so_item.item_group == frappe.db.escape(filters.item_group))
|
||||||
|
|
||||||
|
if filters.get("from_date"):
|
||||||
|
query = query.where(db_so.transaction_date >= filters.from_date)
|
||||||
|
|
||||||
|
if filters.get("to_date"):
|
||||||
|
query = query.where(db_so.transaction_date <= filters.to_date)
|
||||||
|
|
||||||
|
if filters.get("item_code"):
|
||||||
|
query = query.where(db_so_item.item_group == frappe.db.escape(filters.item_code))
|
||||||
|
|
||||||
|
if filters.get("customer"):
|
||||||
|
query = query.where(db_so.customer == filters.customer)
|
||||||
|
|
||||||
|
return query.run(as_dict=1)
|
||||||
|
|
||||||
|
|
||||||
def get_chart_data(data):
|
def get_chart_data(data):
|
||||||
item_wise_sales_map = {}
|
item_wise_sales_map = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user