fix: Multiple fixes in Gross Profit report
This commit is contained in:
parent
bb105a33b2
commit
da73685f71
@ -8,20 +8,22 @@ frappe.query_reports["Gross Profit"] = {
|
|||||||
"label": __("Company"),
|
"label": __("Company"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Company",
|
"options": "Company",
|
||||||
"reqd": 1,
|
"default": frappe.defaults.get_user_default("Company"),
|
||||||
"default": frappe.defaults.get_user_default("Company")
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"from_date",
|
"fieldname":"from_date",
|
||||||
"label": __("From Date"),
|
"label": __("From Date"),
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"default": frappe.defaults.get_user_default("year_start_date")
|
"default": frappe.defaults.get_user_default("year_start_date"),
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"to_date",
|
"fieldname":"to_date",
|
||||||
"label": __("To Date"),
|
"label": __("To Date"),
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"default": frappe.defaults.get_user_default("year_end_date")
|
"default": frappe.defaults.get_user_default("year_end_date"),
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"sales_invoice",
|
"fieldname":"sales_invoice",
|
||||||
|
|||||||
@ -369,20 +369,37 @@ class GrossProfitGenerator(object):
|
|||||||
return self.average_buying_rate[item_code]
|
return self.average_buying_rate[item_code]
|
||||||
|
|
||||||
def get_last_purchase_rate(self, item_code, row):
|
def get_last_purchase_rate(self, item_code, row):
|
||||||
condition = ''
|
purchase_invoice = frappe.qb.DocType("Purchase Invoice")
|
||||||
if row.project:
|
purchase_invoice_item = frappe.qb.DocType("Purchase Invoice Item")
|
||||||
condition += " AND a.project=%s" % (frappe.db.escape(row.project))
|
|
||||||
elif row.cost_center:
|
|
||||||
condition += " AND a.cost_center=%s" % (frappe.db.escape(row.cost_center))
|
|
||||||
if self.filters.to_date:
|
|
||||||
condition += " AND modified='%s'" % (self.filters.to_date)
|
|
||||||
|
|
||||||
last_purchase_rate = frappe.db.sql("""
|
query = (frappe.qb.from_(purchase_invoice_item)
|
||||||
select (a.base_rate / a.conversion_factor)
|
.inner_join(
|
||||||
from `tabPurchase Invoice Item` a
|
purchase_invoice
|
||||||
where a.item_code = %s and a.docstatus=1
|
).on(
|
||||||
{0}
|
purchase_invoice.name == purchase_invoice_item.parent
|
||||||
order by a.modified desc limit 1""".format(condition), item_code)
|
).select(
|
||||||
|
purchase_invoice_item.base_rate / purchase_invoice_item.conversion_factor
|
||||||
|
).where(
|
||||||
|
purchase_invoice.docstatus == 1
|
||||||
|
).where(
|
||||||
|
purchase_invoice.posting_date <= self.filters.to_date
|
||||||
|
).where(
|
||||||
|
purchase_invoice_item.item_code == item_code
|
||||||
|
))
|
||||||
|
|
||||||
|
if row.project:
|
||||||
|
query.where(
|
||||||
|
purchase_invoice_item.item_code == row.project
|
||||||
|
)
|
||||||
|
|
||||||
|
if row.cost_center:
|
||||||
|
query.where(
|
||||||
|
purchase_invoice_item.cost_center == row.cost_center
|
||||||
|
)
|
||||||
|
|
||||||
|
query.orderby(purchase_invoice.posting_date, order=frappe.qb.desc)
|
||||||
|
query.limit(1)
|
||||||
|
last_purchase_rate = query.run()
|
||||||
|
|
||||||
return flt(last_purchase_rate[0][0]) if last_purchase_rate else 0
|
return flt(last_purchase_rate[0][0]) if last_purchase_rate else 0
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user