diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 043bc494946459e2596765903ef4bfee00388f0c..f7e6356ee0d1c52c27c3b6f8c3c7e4166e8fd14b 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -11,7 +11,7 @@ from erpnext.controllers.accounts_controller import get_taxes_and_charges from erpnext.controllers.sales_and_purchase_return import get_rate_for_return from erpnext.controllers.stock_controller import StockController from erpnext.stock.doctype.item.item import set_item_default -from erpnext.stock.get_item_details import get_bin_details, get_conversion_factor +from erpnext.stock.get_item_details import get_bin_details, get_conversion_factor, GROSS_PROFIT_CALCULATION_RULES from erpnext.stock.utils import get_incoming_rate, get_valuation_method @@ -688,8 +688,10 @@ class SellingController(StockController): def set_gross_profit(self): if self.doctype in ["Sales Order", "Quotation"]: for item in self.items: + gross_profit_calculation_rule = item.get("gross_profit_calculation_rule") or "Valuation Rate" # @dokos + gross_profit_calculation_field = GROSS_PROFIT_CALCULATION_RULES.get(gross_profit_calculation_rule) # @dokos item.gross_profit = flt( - ((flt(item.stock_uom_rate) - flt(item.valuation_rate)) * item.stock_qty), + ((flt(item.stock_uom_rate) - flt(item.get("unit_cost_price") or item.get(gross_profit_calculation_field))) * item.stock_qty), # @dokos self.precision("amount", item), ) @@ -718,6 +720,7 @@ class SellingController(StockController): total_gross_profit / total_cost * 100.0 if total_cost else 0.0, precision=self.precision("gross_profit_percentage"), ) + self.markup_percentage = flt( (total_selling_amount - total_cost) / total_selling_amount * 100.0 if total_selling_amount @@ -725,6 +728,7 @@ class SellingController(StockController): precision=self.precision("markup_percentage"), ) + def set_customer_address(self): address_dict = { "customer_address": "address_display", diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 1c481b795e20fb36538c7ebb9f7229aec406f576..8f1b62d4fffb39c886b5d0f225c952bb9e35db73 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1374,6 +1374,7 @@ def apply_price_list_on_item(args): item_details = get_price_list_rate(args, item_doc) item_details.update(get_pricing_rule_for_item(args)) + return item_details @@ -1472,16 +1473,15 @@ def get_valuation_rate(item_code, company, warehouse=None): def get_gross_profit(out): - gross_profit_calculation_rule = out.get("gross_profit_calculation_rule") or "Valuation Rate" - gross_profit_calculation_field = GROSS_PROFIT_CALCULATION_RULES.get(gross_profit_calculation_rule) + gross_profit_calculation_rule = out.get("gross_profit_calculation_rule") or "Valuation Rate" # @dokos + gross_profit_calculation_field = GROSS_PROFIT_CALCULATION_RULES.get(gross_profit_calculation_rule) # @dokos if out.get(gross_profit_calculation_field): + unit_cost_price = out.get(gross_profit_calculation_field) + flt(out.get("additional_costs_amount")) # @dokos out.update( { - "gross_profit": ((out.base_rate - out.get(gross_profit_calculation_field)) * out.stock_qty), - "base_unit_cost_price": out.get(gross_profit_calculation_field), - "unit_cost_price": ( - out.get(gross_profit_calculation_field) + flt(out.get("additional_costs_amount")) - ), + "gross_profit": ((out.base_rate - unit_cost_price) * out.stock_qty), # @dokos + "base_unit_cost_price": out.get(gross_profit_calculation_field), # @dokos + "unit_cost_price": unit_cost_price, # @dokos } )