diff options
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 1c573371..8c650fc5 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -306,28 +306,30 @@ class PurchaseOrder(models.Model): Forecast.search([('order_id','=',po.id)]).unlink() - product_ids = po.order_line.mapped('product_id').ids + product_ids = po.order_line.mapped('product_id') if not product_ids: continue - data = report._get_report_data(product_variant_ids=product_ids) + for product in product_ids: - for l in data.get('lines', []): - doc = l.get('document_in') + data = report._get_report_data(product_variant_ids=[product.id]) - if doc and doc._name == 'purchase.order' and doc.id == po.id: - doc_out = l.get('document_out') + for l in data.get('lines', []): + doc = l.get('document_in') - Forecast.create({ - 'order_id': po.id, - 'product_id': l['product']['id'], - 'quantity': l['quantity'], - 'sale_order': doc_out.display_name if doc_out else '', - 'sale_order_id': doc_out.id if doc_out else '', - 'is_late': bool(l.get('is_late')), - 'replenishment_filled': bool(l.get('replenishment_filled')), - }) - + if doc and doc._name == 'purchase.order' and doc.id == po.id: + doc_out = l.get('document_out') + + Forecast.create({ + 'order_id': po.id, + 'product_id': l['product']['id'], + 'quantity': l['quantity'], + 'sale_order': doc_out.display_name if doc_out else '', + 'sale_order_id': doc_out.id if doc_out else '', + 'is_late': bool(l.get('is_late')), + 'replenishment_filled': bool(l.get('replenishment_filled')), + }) + def _get_altama_token(self, source='auto'): ICP = self.env['ir.config_parameter'].sudo() TokenLog = self.env['token.log'].sudo() @@ -685,17 +687,17 @@ class PurchaseOrder(models.Model): rec.sync_date_planned_to_so() def sync_date_planned_to_so(self): - for line in self.order_sales_match_line: - other_sales_match = self.env['purchase.order.sales.match'].search([ + for line in self.forecast_line_ids: + forecast = self.env['sale.forecast.coverage'].search([ # ('product_id', '=', line.product_id.id), - ('sale_id', '=', line.sale_id.id), + ('purchase_order_id', '=', line.order_id.id), # ('sale_line_id', '=', line.sale_line_id.id) ]) - dates = [d for d in other_sales_match.mapped('purchase_order_id.date_planned') if d] + dates = [d for d in line.mapped('order_id.date_planned') if d] if dates: date_planned = max(dates) - line.sale_id.write({'et_products': date_planned, 'reason_change_date_planned': line.purchase_order_id.reason_change_date_planned}) + forecast.sale_id.write({'et_products': date_planned, 'reason_change_date_planned': line.order_id.reason_change_date_planned}) @api.depends('name') def _compute_bu_related_count(self): @@ -1583,7 +1585,7 @@ class PurchaseOrder(models.Model): if '/PJ/' in self.name: price_change_detected = any(line.price_unit_before for line in self.order_line) if price_change_detected: - if self.order_sales_match_line: + if self.forecast_line_ids: if self.total_percent_margin <= 15.0: raise UserError("Approval Pimpinan diperlukan jika terdapat perubahan Unit Price pada PO Line dan Memiliki Margin <= 15%") @@ -1681,7 +1683,7 @@ class PurchaseOrder(models.Model): # return self.action_view_related_bu() if self.partner_id.id == 5571 and not self.revisi_po: self.action_create_order_altama() - + return res def _remove_product_bom(self): @@ -1867,10 +1869,10 @@ class PurchaseOrder(models.Model): so_line.purchase_price = line.price_unit def re_calculate_from_apo(self): - for line in self.order_sales_match_line: + for line in self.forecast_line_ids: order_line = self.env['purchase.order.line'].search([ ('product_id', '=', line.product_id.id), - ('order_id', '=', line.purchase_order_id.id) + ('order_id', '=', line.order_id.id) ], limit=1) line.sale_line_id.purchase_price = order_line.price_unit |
