Merge pull request #17522 from rohitwaghchaure/invoiced_items_gross_margin_api_develop
feat: Get invoiced item's gross margin using API
This commit is contained in:
commit
8b7a5133a6
@ -23,6 +23,12 @@ frappe.query_reports["Gross Profit"] = {
|
|||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"default": frappe.defaults.get_user_default("year_end_date")
|
"default": frappe.defaults.get_user_default("year_end_date")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"sales_invoice",
|
||||||
|
"label": __("Sales Invoice"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Sales Invoice"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"group_by",
|
"fieldname":"group_by",
|
||||||
"label": __("Group By"),
|
"label": __("Group By"),
|
||||||
|
@ -302,6 +302,12 @@ class GrossProfitGenerator(object):
|
|||||||
sales_person_cols = ""
|
sales_person_cols = ""
|
||||||
sales_team_table = ""
|
sales_team_table = ""
|
||||||
|
|
||||||
|
if self.filters.get("sales_invoice"):
|
||||||
|
conditions += " and `tabSales Invoice`.name = %(sales_invoice)s"
|
||||||
|
|
||||||
|
if self.filters.get("item_code"):
|
||||||
|
conditions += " and `tabSales Invoice Item`.item_code = %(item_code)s"
|
||||||
|
|
||||||
self.si_list = frappe.db.sql("""
|
self.si_list = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
`tabSales Invoice Item`.parenttype, `tabSales Invoice Item`.parent,
|
`tabSales Invoice Item`.parenttype, `tabSales Invoice Item`.parent,
|
||||||
|
@ -135,3 +135,25 @@ def get_appropriate_company(filters):
|
|||||||
company = get_default_company()
|
company = get_default_company()
|
||||||
|
|
||||||
return company
|
return company
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_invoiced_item_gross_margin(sales_invoice=None, item_code=None, company=None, with_item_data=False):
|
||||||
|
from erpnext.accounts.report.gross_profit.gross_profit import GrossProfitGenerator
|
||||||
|
|
||||||
|
sales_invoice = sales_invoice or frappe.form_dict.get('sales_invoice')
|
||||||
|
item_code = item_code or frappe.form_dict.get('item_code')
|
||||||
|
company = company or frappe.get_cached_value("Sales Invoice", sales_invoice, 'company')
|
||||||
|
|
||||||
|
filters = {
|
||||||
|
'sales_invoice': sales_invoice,
|
||||||
|
'item_code': item_code,
|
||||||
|
'company': company,
|
||||||
|
'group_by': 'Invoice'
|
||||||
|
}
|
||||||
|
|
||||||
|
gross_profit_data = GrossProfitGenerator(filters)
|
||||||
|
result = gross_profit_data.grouped_data
|
||||||
|
if not with_item_data:
|
||||||
|
result = sum([d.gross_profit for d in result])
|
||||||
|
|
||||||
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user