Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][report] Buying amount for product bundle in Gross Profit report #4277

Merged
merged 1 commit into from Nov 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions erpnext/accounts/report/gross_profit/gross_profit.py
Expand Up @@ -98,11 +98,17 @@ def process(self):

row.base_amount = flt(row.base_net_amount)

product_bundles = self.product_bundles.get(row.parenttype, {}).get(row.parent, frappe._dict())

if row.update_stock:
product_bundles = self.product_bundles.get(row.parenttype, {}).get(row.parent, frappe._dict())
elif row.dn_detail:
product_bundles = self.product_bundles.get("Delivery Note", {})\
.get(row.delivery_note, frappe._dict())
row.item_row = row.dn_detail

# get buying amount
if row.item_code in product_bundles:
row.buying_amount = self.get_buying_amount_from_product_bundle(row, product_bundles[row.item_code])
row.buying_amount = self.get_buying_amount_from_product_bundle(row,
product_bundles[row.item_code])
else:
row.buying_amount = self.get_buying_amount(row, row.item_code)

Expand Down Expand Up @@ -142,7 +148,6 @@ def collapse_group(self):
new_row.qty += row.qty
new_row.buying_amount += row.buying_amount
new_row.base_amount += row.base_amount
# new_row.allocated_amount += (row.allocated_amount or 0) if new_row.allocated_amount else 0

new_row.gross_profit = new_row.base_amount - new_row.buying_amount
new_row.gross_profit_percent = ((new_row.gross_profit / new_row.base_amount) * 100.0) \
Expand All @@ -158,9 +163,9 @@ def skip_row(self, row, product_bundles):

def get_buying_amount_from_product_bundle(self, row, product_bundle):
buying_amount = 0.0
for bom_item in product_bundle:
if bom_item.get("parent_detail_docname")==row.item_row:
buying_amount += self.get_buying_amount(row, bom_item.item_code)
for packed_item in product_bundle:
if packed_item.get("parent_detail_docname")==row.item_row:
buying_amount += self.get_buying_amount(row, packed_item.item_code)

return buying_amount

Expand All @@ -176,14 +181,14 @@ def get_buying_amount(self, row, item_code):
else:
my_sle = self.sle.get((item_code, row.warehouse))
if (row.update_stock or row.dn_detail) and my_sle:
parenttype, parent, item_row = row.parenttype, row.parent, row.item_row
parenttype, parent = row.parenttype, row.parent
if row.dn_detail:
parenttype, parent, item_row = "Delivery Note", row.delivery_note, row.dn_detail
parenttype, parent = "Delivery Note", row.delivery_note

for i, sle in enumerate(my_sle):
# find the stock valution rate from stock ledger entry
if sle.voucher_type == parenttype and parent == sle.voucher_no and \
sle.voucher_detail_no == item_row:
sle.voucher_detail_no == row.item_row:
previous_stock_value = len(my_sle) > i+1 and \
flt(my_sle[i+1].stock_value) or 0.0
return previous_stock_value - flt(sle.stock_value)
Expand Down