diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-03-13 16:24:13 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-03-13 16:24:13 +0700 |
| commit | d3e3a8abf0ae382442c16a7ac6091c7bb872313f (patch) | |
| tree | 52ce38f2497b89dc11ca3ae3b1d9f39fb2afc78e /indoteknik_custom/models/report_stock_forecasted.py | |
| parent | 00b6739e4f4228c1cc66de0ef63312bc633ae21f (diff) | |
change request purchasing job
Diffstat (limited to 'indoteknik_custom/models/report_stock_forecasted.py')
| -rw-r--r-- | indoteknik_custom/models/report_stock_forecasted.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/indoteknik_custom/models/report_stock_forecasted.py b/indoteknik_custom/models/report_stock_forecasted.py index 48a17095..7ae93fda 100644 --- a/indoteknik_custom/models/report_stock_forecasted.py +++ b/indoteknik_custom/models/report_stock_forecasted.py @@ -6,26 +6,37 @@ class ReplenishmentReport(models.AbstractModel): @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 + product_id = line.get('product', {}).get('id') + query = [('product_id', '=', product_id)] if order_id: result = self._calculate_result(line) - result_dict.setdefault(order_id, []).append(result) + quantity = line.get('quantity', 0) + result_dict.setdefault(order_id, []).append((result, quantity)) for order_id, results in result_dict.items(): sale_order_lines = self.env['sale.order.line'].search([('order_id', '=', order_id)]) + sales_order = self.env['sale.order'].browse(order_id) + + for result, quantity in results: + fullfillment = self.env['sales.order.fullfillment'].search([('sales_order_id', '=', sales_order.id), ('product_id', '=', product_id)]) + if fullfillment: + fullfillment.reserved_from = result + fullfillment.qty_fullfillment = quantity + continue + + fullfillment.create({ + 'sales_order_id': sales_order.id, + 'product_id': product_id, + 'reserved_from': result, + 'qty_fullfillment': quantity, + }) - concatenated_result = ' ,'.join(results) - - for sale_order_line in sale_order_lines: - sale_order_line.reserved_from = concatenated_result return lines |
