[Fix] Total materials consumed cost not consider in the calculation of Gross Margin in project (#15171)
This commit is contained in:
parent
5c5688b374
commit
ecc6af9d2a
@ -504,3 +504,4 @@ erpnext.patches.v10_0.show_leaves_of_all_department_members_in_calendar
|
||||
erpnext.patches.v10_0.update_status_in_purchase_receipt
|
||||
erpnext.patches.v10_0.update_address_template_for_india
|
||||
erpnext.patches.v10_0.set_discount_amount
|
||||
erpnext.patches.v10_0.recalculate_gross_margin_for_project
|
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2017, Frappe and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
frappe.reload_doc('projects', 'doctype', 'project')
|
||||
for d in frappe.db.sql(""" select name from `tabProject` where
|
||||
ifnull(total_consumed_material_cost, 0 ) > 0 and ifnull(total_billed_amount, 0) > 0""", as_dict=1):
|
||||
doc = frappe.get_doc("Project", d.name)
|
||||
doc.calculate_gross_margin()
|
||||
doc.db_set('gross_margin', doc.gross_margin)
|
||||
doc.db_set('per_gross_margin', doc.per_gross_margin)
|
@ -236,9 +236,13 @@ class Project(Document):
|
||||
self.update_purchase_costing()
|
||||
self.update_sales_amount()
|
||||
self.update_billed_amount()
|
||||
self.calculate_gross_margin()
|
||||
|
||||
self.gross_margin = flt(self.total_billed_amount) - (flt(self.total_costing_amount) + flt(self.total_expense_claim) + flt(self.total_purchase_cost))
|
||||
def calculate_gross_margin(self):
|
||||
expense_amount = (flt(self.total_costing_amount) + flt(self.total_expense_claim)
|
||||
+ flt(self.total_purchase_cost) + flt(self.get('total_consumed_material_cost', 0)))
|
||||
|
||||
self.gross_margin = flt(self.total_billed_amount) - expense_amount
|
||||
if self.total_billed_amount:
|
||||
self.per_gross_margin = (self.gross_margin / flt(self.total_billed_amount)) *100
|
||||
|
||||
|
@ -82,6 +82,7 @@ class StockEntry(StockController):
|
||||
if self.purchase_order and self.purpose == "Subcontract":
|
||||
self.update_purchase_order_supplied_items()
|
||||
self.make_gl_entries_on_cancel()
|
||||
self.update_cost_in_project()
|
||||
|
||||
def validate_purpose(self):
|
||||
valid_purposes = ["Material Issue", "Material Receipt", "Material Transfer", "Material Transfer for Manufacture",
|
||||
@ -107,8 +108,8 @@ class StockEntry(StockController):
|
||||
se.docstatus = 1 and se.project = %s and sed.parent = se.name
|
||||
and (sed.t_warehouse is null or sed.t_warehouse = '')""", self.project, as_list=1)
|
||||
|
||||
if amount:
|
||||
frappe.db.set_value('Project', self.project, 'total_consumed_material_cost', amount[0][0])
|
||||
amount = amount[0][0] if amount else 0
|
||||
frappe.db.set_value('Project', self.project, 'total_consumed_material_cost', amount)
|
||||
|
||||
def validate_item(self):
|
||||
stock_items = self.get_stock_items()
|
||||
|
Loading…
x
Reference in New Issue
Block a user