fix: Update columns in new format
This commit is contained in:
parent
da73685f71
commit
2172ab2d37
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"add_total_row": 0,
|
"add_total_row": 1,
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"creation": "2013-02-25 17:03:34",
|
"creation": "2013-02-25 17:03:34",
|
||||||
"disable_prepared_report": 0,
|
"disable_prepared_report": 0,
|
||||||
@ -9,7 +9,7 @@
|
|||||||
"filters": [],
|
"filters": [],
|
||||||
"idx": 3,
|
"idx": 3,
|
||||||
"is_standard": "Yes",
|
"is_standard": "Yes",
|
||||||
"modified": "2021-11-13 19:14:23.730198",
|
"modified": "2022-02-11 10:18:36.956558",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Gross Profit",
|
"name": "Gross Profit",
|
||||||
|
|||||||
@ -70,43 +70,42 @@ def get_data_when_grouped_by_invoice(columns, gross_profit_data, filters, group_
|
|||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
def get_data_when_not_grouped_by_invoice(gross_profit_data, filters, group_wise_columns, data):
|
def get_data_when_not_grouped_by_invoice(gross_profit_data, filters, group_wise_columns, data):
|
||||||
for idx, src in enumerate(gross_profit_data.grouped_data):
|
for src in gross_profit_data.grouped_data:
|
||||||
row = []
|
row = []
|
||||||
for col in group_wise_columns.get(scrub(filters.group_by)):
|
for col in group_wise_columns.get(scrub(filters.group_by)):
|
||||||
row.append(src.get(col))
|
row.append(src.get(col))
|
||||||
|
|
||||||
row.append(filters.currency)
|
row.append(filters.currency)
|
||||||
if idx == len(gross_profit_data.grouped_data)-1:
|
|
||||||
row[0] = "Total"
|
|
||||||
|
|
||||||
data.append(row)
|
data.append(row)
|
||||||
|
|
||||||
def get_columns(group_wise_columns, filters):
|
def get_columns(group_wise_columns, filters):
|
||||||
columns = []
|
columns = []
|
||||||
column_map = frappe._dict({
|
column_map = frappe._dict({
|
||||||
"parent": _("Sales Invoice") + ":Link/Sales Invoice:120",
|
"parent": {"label": _('Sales Invoice'), "fieldname": "parent_invoice", "fieldtype": "Link", "options": "Sales Invoice", "width": 120},
|
||||||
"invoice_or_item": _("Sales Invoice") + ":Link/Sales Invoice:120",
|
"invoice_or_item": {"label": _('Sales Invoice'), "fieldtype": "Link", "options": "Sales Invoice", "width": 120},
|
||||||
"posting_date": _("Posting Date") + ":Date:100",
|
"posting_date": {"label": _('Posting Date'), "fieldname": "posting_date", "fieldtype": "Date", "width": 100},
|
||||||
"posting_time": _("Posting Time") + ":Data:100",
|
"posting_time": {"label": _('Posting Time'), "fieldname": "posting_time", "fieldtype": "Data", "width": 100},
|
||||||
"item_code": _("Item Code") + ":Link/Item:100",
|
"item_code": {"label": _('Item Code'), "fieldname": "item_code", "fieldtype": "Link", "options": "Item", "width": 100},
|
||||||
"item_name": _("Item Name") + ":Data:100",
|
"item_name": {"label": _('Item Name'), "fieldname": "item_name", "fieldtype": "Data", "width": 100},
|
||||||
"item_group": _("Item Group") + ":Link/Item Group:100",
|
"item_group": {"label": _('Item Group'), "fieldname": "item_group", "fieldtype": "Link", "options": "Item Group", "width": 100},
|
||||||
"brand": _("Brand") + ":Link/Brand:100",
|
"brand": {"label": _('Brand'), "fieldtype": "Link", "options": "Brand", "width": 100},
|
||||||
"description": _("Description") +":Data:100",
|
"description": {"label": _('Description'), "fieldname": "description", "fieldtype": "Data", "width": 100},
|
||||||
"warehouse": _("Warehouse") + ":Link/Warehouse:100",
|
"warehouse": {"label": _('Warehouse'), "fieldname": "warehouse", "fieldtype": "Link", "options": "warehouse", "width": 100},
|
||||||
"qty": _("Qty") + ":Float:80",
|
"qty": {"label": _('Qty'), "fieldname": "qty", "fieldtype": "Float", "width": 80},
|
||||||
"base_rate": _("Avg. Selling Rate") + ":Currency/currency:100",
|
"base_rate": {"label": _('Avg. Selling Rate'), "fieldname": "avg._selling_rate", "fieldtype": "Currency", "options": "currency", "width": 100},
|
||||||
"buying_rate": _("Valuation Rate") + ":Currency/currency:100",
|
"buying_rate": {"label": _('Valuation Rate'), "fieldname": "valuation_rate", "fieldtype": "Currency", "options": "currency", "width": 100},
|
||||||
"base_amount": _("Selling Amount") + ":Currency/currency:100",
|
"base_amount": {"label": _('Selling Amount'), "fieldname": "selling_amount", "fieldtype": "Currency", "options": "currency", "width": 100},
|
||||||
"buying_amount": _("Buying Amount") + ":Currency/currency:100",
|
"buying_amount": {"label": _('Buying Amount'), "fieldname": "buying_amount", "fieldtype": "Currency", "options": "currency", "width": 100},
|
||||||
"gross_profit": _("Gross Profit") + ":Currency/currency:100",
|
"gross_profit": {"label": _('Gross Profit'), "fieldname": "gross_profit", "fieldtype": "Currency", "options": "currency", "width": 100},
|
||||||
"gross_profit_percent": _("Gross Profit %") + ":Percent:100",
|
"gross_profit_percent": {"label": _('Gross Profit Percent'), "fieldname": "gross_profit_%",
|
||||||
"project": _("Project") + ":Link/Project:100",
|
"fieldtype": "Percent", "width": 100},
|
||||||
"sales_person": _("Sales person"),
|
"project": {"label": _('Project'), "fieldname": "project", "fieldtype": "Link", "options": "Project", "width": 100},
|
||||||
"allocated_amount": _("Allocated Amount") + ":Currency/currency:100",
|
"sales_person": {"label": _('Sales Person'), "fieldname": "sales_person", "fieldtype": "Data","width": 100},
|
||||||
"customer": _("Customer") + ":Link/Customer:100",
|
"allocated_amount": {"label": _('Allocated Amount'), "fieldname": "allocated_amount", "fieldtype": "Currency", "options": "currency", "width": 100},
|
||||||
"customer_group": _("Customer Group") + ":Link/Customer Group:100",
|
"customer": {"label": _('Customer'), "fieldname": "customer", "fieldtype": "Link", "options": "Customer", "width": 100},
|
||||||
"territory": _("Territory") + ":Link/Territory:100"
|
"customer_group": {"label": _('Customer Group'), "fieldname": "customer_group", "fieldtype": "Link", "options": "customer", "width": 100},
|
||||||
|
"territory": {"label": _('Territory'), "fieldname": "territory", "fieldtype": "Link", "options": "territory", "width": 100},
|
||||||
})
|
})
|
||||||
|
|
||||||
for col in group_wise_columns.get(scrub(filters.group_by)):
|
for col in group_wise_columns.get(scrub(filters.group_by)):
|
||||||
@ -223,16 +222,6 @@ class GrossProfitGenerator(object):
|
|||||||
self.get_average_rate_based_on_group_by()
|
self.get_average_rate_based_on_group_by()
|
||||||
|
|
||||||
def get_average_rate_based_on_group_by(self):
|
def get_average_rate_based_on_group_by(self):
|
||||||
# sum buying / selling totals for group
|
|
||||||
self.totals = frappe._dict(
|
|
||||||
qty=0,
|
|
||||||
base_amount=0,
|
|
||||||
buying_amount=0,
|
|
||||||
gross_profit=0,
|
|
||||||
gross_profit_percent=0,
|
|
||||||
base_rate=0,
|
|
||||||
buying_rate=0
|
|
||||||
)
|
|
||||||
for key in list(self.grouped):
|
for key in list(self.grouped):
|
||||||
if self.filters.get("group_by") != "Invoice":
|
if self.filters.get("group_by") != "Invoice":
|
||||||
for i, row in enumerate(self.grouped[key]):
|
for i, row in enumerate(self.grouped[key]):
|
||||||
@ -244,7 +233,6 @@ class GrossProfitGenerator(object):
|
|||||||
new_row.base_amount += flt(row.base_amount, self.currency_precision)
|
new_row.base_amount += flt(row.base_amount, self.currency_precision)
|
||||||
new_row = self.set_average_rate(new_row)
|
new_row = self.set_average_rate(new_row)
|
||||||
self.grouped_data.append(new_row)
|
self.grouped_data.append(new_row)
|
||||||
self.add_to_totals(new_row)
|
|
||||||
else:
|
else:
|
||||||
for i, row in enumerate(self.grouped[key]):
|
for i, row in enumerate(self.grouped[key]):
|
||||||
if row.indent == 1.0:
|
if row.indent == 1.0:
|
||||||
@ -258,17 +246,6 @@ class GrossProfitGenerator(object):
|
|||||||
if (flt(row.qty) or row.base_amount):
|
if (flt(row.qty) or row.base_amount):
|
||||||
row = self.set_average_rate(row)
|
row = self.set_average_rate(row)
|
||||||
self.grouped_data.append(row)
|
self.grouped_data.append(row)
|
||||||
self.add_to_totals(row)
|
|
||||||
|
|
||||||
self.set_average_gross_profit(self.totals)
|
|
||||||
|
|
||||||
if self.filters.get("group_by") == "Invoice":
|
|
||||||
self.totals.indent = 0.0
|
|
||||||
self.totals.parent_invoice = ""
|
|
||||||
self.totals.invoice_or_item = "Total"
|
|
||||||
self.si_list.append(self.totals)
|
|
||||||
else:
|
|
||||||
self.grouped_data.append(self.totals)
|
|
||||||
|
|
||||||
def is_not_invoice_row(self, row):
|
def is_not_invoice_row(self, row):
|
||||||
return (self.filters.get("group_by") == "Invoice" and row.indent != 0.0) or self.filters.get("group_by") != "Invoice"
|
return (self.filters.get("group_by") == "Invoice" and row.indent != 0.0) or self.filters.get("group_by") != "Invoice"
|
||||||
@ -284,11 +261,6 @@ class GrossProfitGenerator(object):
|
|||||||
new_row.gross_profit_percent = flt(((new_row.gross_profit / new_row.base_amount) * 100.0), self.currency_precision) \
|
new_row.gross_profit_percent = flt(((new_row.gross_profit / new_row.base_amount) * 100.0), self.currency_precision) \
|
||||||
if new_row.base_amount else 0
|
if new_row.base_amount else 0
|
||||||
|
|
||||||
def add_to_totals(self, new_row):
|
|
||||||
for key in self.totals:
|
|
||||||
if new_row.get(key):
|
|
||||||
self.totals[key] += new_row[key]
|
|
||||||
|
|
||||||
def get_returned_invoice_items(self):
|
def get_returned_invoice_items(self):
|
||||||
returned_invoices = frappe.db.sql("""
|
returned_invoices = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
@ -389,7 +361,7 @@ class GrossProfitGenerator(object):
|
|||||||
|
|
||||||
if row.project:
|
if row.project:
|
||||||
query.where(
|
query.where(
|
||||||
purchase_invoice_item.item_code == row.project
|
purchase_invoice_item.project == row.project
|
||||||
)
|
)
|
||||||
|
|
||||||
if row.cost_center:
|
if row.cost_center:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user