Skip to content

Commit

Permalink
BAH-3549 | Refactor. Product Reorder List report vendor fi… (#117)
Browse files Browse the repository at this point in the history
* [Karthi] | BAH-3549 | Refactor. Product Reorder List report vendor filter issue has been fixed.

* [Karthi] | BAH-3549 | Refactor. Reorder report issue has been fixed.

* [Karthi] | BAH-3549 | Refactor. Reorder report issue has been fixed.
  • Loading branch information
karthikeyansp91 authored Mar 25, 2024
1 parent 89c1abb commit 261036b
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions bahmni_reports/report/product_reorder_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,28 @@ def get_xlsx_report(self, data, response):
sheet.write(5, 7, "Status", format2)
sheet.set_column('H:H', 38)

if rec_obj.product_id:
product_obj = self.env['product.product'].search([('type', '=', 'product'),('id','in', list(i.id for i in rec_obj.product_id))])
if rec_obj.product_id and rec_obj.vendor_id:
product_obj = self.env['product.product'].search([('type', '=', 'product'),('id', 'in', [i.id for i in rec_obj.product_id] if rec_obj.product_id else self.env['product.product'].search([]).ids),
('seller_ids.partner_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
elif rec_obj.vendor_id:
product_obj = self.env['product.product'].search([('type', '=', 'product'),
('seller_ids.partner_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
elif rec_obj.product_id:
product_obj = self.env['product.product'].search([('type', '=', 'product'),('id', 'in', [i.id for i in rec_obj.product_id] if rec_obj.product_id else self.env['product.product'].search([]).ids)])
else:
product_obj = self.env['product.product'].search([('type', '=', 'product')])
product_obj = self.env['product.product'].search([('type', '=', 'product')])

row_num = 6
s_no = 1
total_qty =0

for product_data in sorted(product_obj, key=lambda x: x.name,reverse=False):
if rec_obj.status == 'all':
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id),
('supplier_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
if rec_obj.status == 'all':
if rec_obj.vendor_id:
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id),
('vendor_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
else:
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id)])
if reorder_data:
qty_on_hand = reorder_data.qty_on_hand
lst_price = reorder_data.product_id.lst_price
Expand All @@ -126,24 +135,27 @@ def get_xlsx_report(self, data, response):
qty_to_order = 0
supplier_name = '-'
status = 'No Min Stock & Reorder Rule'
if reorder_data:
sheet.write(row_num, 0, s_no, format12_a)
sheet.write(row_num, 1, product_data.name, format12)
sheet.write(row_num, 2, "{:.2f}".format(qty_on_hand), format12_b)
sheet.write(row_num, 3, "{:.2f}".format(lst_price), format12_b)
sheet.write(row_num, 4, "{:.2f}".format(product_min_qty), format12_b)
sheet.write(row_num, 5, "{:.2f}".format(qty_to_order), format12_b)
sheet.write(row_num, 6, supplier_name , format12)
sheet.write(row_num, 7, status, format12)

row_num += 1
if reorder_data:
total_qty += reorder_data.qty_on_hand
s_no += 1
sheet.write(row_num, 0, s_no, format12_a)
sheet.write(row_num, 1, product_data.name, format12)
sheet.write(row_num, 2, "{:.2f}".format(qty_on_hand), format12_b)
sheet.write(row_num, 3, "{:.2f}".format(lst_price), format12_b)
sheet.write(row_num, 4, "{:.2f}".format(product_min_qty), format12_b)
sheet.write(row_num, 5, "{:.2f}".format(qty_to_order), format12_b)
sheet.write(row_num, 6, supplier_name , format12)
sheet.write(row_num, 7, status, format12)

row_num += 1
if reorder_data:
total_qty += reorder_data.qty_on_hand
s_no += 1

elif rec_obj.status == 'available':
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id),
('supplier_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
if rec_obj.vendor_id:
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id),
('vendor_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
else:
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id)])
if reorder_data:
if reorder_data.qty_on_hand > reorder_data.product_min_qty:
status = 'Stock Available'
Expand All @@ -166,7 +178,7 @@ def get_xlsx_report(self, data, response):
elif rec_obj.status == 'nil':

reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id),
('supplier_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
('vendor_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
if not reorder_data:
qty_on_hand = 0
lst_price = 0
Expand All @@ -190,8 +202,11 @@ def get_xlsx_report(self, data, response):
else:
pass
elif rec_obj.status == 'reorder':
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id),
('supplier_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
if rec_obj.vendor_id:
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id),
('vendor_id', 'in', [i.id for i in rec_obj.vendor_id] if rec_obj.vendor_id else self.env['res.partner'].search([('active', '=', True),('supplier_rank', '>', 0)]).ids)])
else:
reorder_data = self.env['stock.warehouse.orderpoint'].search([('product_id', '=', product_data.id)])
if reorder_data:
if reorder_data.qty_on_hand < reorder_data.product_min_qty:
status = 'Order To Be Placed'
Expand Down

0 comments on commit 261036b

Please sign in to comment.