fix: Get Bundle Items

This commit is contained in:
GangaManoj
2021-08-25 15:33:53 +05:30
parent 13ae10b3a2
commit 3135d6dc6a

View File

@@ -436,7 +436,22 @@ class GrossProfitGenerator(object):
parents_index = 0 parents_index = 0
for index, row in enumerate(self.si_list): for index, row in enumerate(self.si_list):
if parents_index < len(parents) and row.parent == parents[parents_index]: if parents_index < len(parents) and row.parent == parents[parents_index]:
invoice = frappe._dict({ invoice = self.get_invoice_row(row)
self.si_list.insert(index, invoice)
parents_index += 1
else:
# skipping the bundle items rows
if not row.indent:
row.indent = 1.0
row.parent_invoice = row.parent
row.parent = row.item_code
if frappe.db.exists('Product Bundle', row.item_code):
self.add_bundle_items(row, index)
def get_invoice_row(self, row):
return frappe._dict({
'parent_invoice': "", 'parent_invoice': "",
'indent': 0.0, 'indent': 0.0,
'parent': row.parent, 'parent': row.parent,
@@ -461,21 +476,15 @@ class GrossProfitGenerator(object):
'base_net_amount': frappe.db.get_value('Sales Invoice', row.parent, 'base_net_total') 'base_net_amount': frappe.db.get_value('Sales Invoice', row.parent, 'base_net_total')
}) })
self.si_list.insert(index, invoice)
parents_index += 1
else:
# skipping the bundle items rows
if not row.indent:
row.indent = 1.0
row.parent_invoice = row.parent
row.parent = row.item_code
if frappe.db.exists('Product Bundle', row.item_code):
self.add_bundle_items(row, index)
def add_bundle_items(self, product_bundle, index): def add_bundle_items(self, product_bundle, index):
bundle_items = frappe.get_all( bundle_items = self.get_bundle_items(product_bundle)
for i, item in enumerate(bundle_items):
bundle_item = self.get_bundle_item_row(product_bundle, item)
self.si_list.insert((index+i+1), bundle_item)
def get_bundle_items(self, product_bundle):
return frappe.get_all(
'Product Bundle Item', 'Product Bundle Item',
filters = { filters = {
'parent': product_bundle.item_code 'parent': product_bundle.item_code
@@ -483,10 +492,10 @@ class GrossProfitGenerator(object):
fields = ['item_code', 'qty'] fields = ['item_code', 'qty']
) )
for i, item in enumerate(bundle_items): def get_bundle_item_row(self, product_bundle, item):
item_name, description, item_group, brand = self.get_bundle_item_details(item.item_code) item_name, description, item_group, brand = self.get_bundle_item_details(item.item_code)
bundle_item = frappe._dict({ return frappe._dict({
'parent_invoice': product_bundle.item_code, 'parent_invoice': product_bundle.item_code,
'indent': product_bundle.indent + 1, 'indent': product_bundle.indent + 1,
'parent': item.item_code, 'parent': item.item_code,
@@ -509,8 +518,6 @@ class GrossProfitGenerator(object):
'cost_center': product_bundle.cost_center 'cost_center': product_bundle.cost_center
}) })
self.si_list.insert((index+i+1), bundle_item)
def get_bundle_item_details(self, item_code): def get_bundle_item_details(self, item_code):
return frappe.db.get_value( return frappe.db.get_value(
'Item', 'Item',