summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/report_stock_forecasted.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-02-28 14:07:47 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-02-28 14:07:47 +0700
commit00b6739e4f4228c1cc66de0ef63312bc633ae21f (patch)
tree85f8fc83d4030878893599abb2a949e5d478e3e7 /indoteknik_custom/models/report_stock_forecasted.py
parent0738a192409687790c16c757f85fe440cb1f377d (diff)
parent46a7cc5601ceab2a7a6cdf4d74e0fa26ce13ab8a (diff)
Merge branch 'production' into purchasing-job
Diffstat (limited to 'indoteknik_custom/models/report_stock_forecasted.py')
-rw-r--r--indoteknik_custom/models/report_stock_forecasted.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py
new file mode 100644
index 00000000..48a17095
--- /dev/null
+++ b/indoteknik_custom/models/report_stock_forecasted.py
@@ -0,0 +1,45 @@
+from odoo import api, models
+
+class ReplenishmentReport(models.AbstractModel):
+ _inherit = 'report.stock.report_product_product_replenishment'
+
+ @api.model
+ def _get_report_lines(self, product_template_ids, product_variant_ids, wh_location_ids):
+ lines = super(ReplenishmentReport, self)._get_report_lines(product_template_ids, product_variant_ids, wh_location_ids)
+
+ result_dict = {}
+
+ for line in lines:
+ product_id = line.get('product', {}).get('id')
+ query = [('product_id', '=', product_id)]
+ document_out = line.get('document_out')
+ order_id = document_out.id if document_out else None
+
+ if order_id:
+ result = self._calculate_result(line)
+ result_dict.setdefault(order_id, []).append(result)
+
+ for order_id, results in result_dict.items():
+ sale_order_lines = self.env['sale.order.line'].search([('order_id', '=', order_id)])
+
+ concatenated_result = ' ,'.join(results)
+
+ for sale_order_line in sale_order_lines:
+ sale_order_line.reserved_from = concatenated_result
+
+ return lines
+
+ def _calculate_result(self, line):
+ if line['document_in']:
+ return str(line["document_in"].name)
+ elif line['reservation'] and not line['document_in']:
+ return 'Reserved from stock'
+ elif line['replenishment_filled']:
+ if line['document_out']:
+ return 'Inventory On Hand'
+ else:
+ return 'Free Stock'
+ else:
+ return 'Not Available'
+
+