summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindoteknik_custom/models/purchase_order.py52
-rwxr-xr-xindoteknik_custom/models/sale_order.py10
2 files changed, 33 insertions, 29 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
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 6c69bb15..22e4460c 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -524,6 +524,7 @@ class SaleOrder(models.Model):
'forecast_qty': l.get('quantity'),
'receipt_date': receipt_date,
'document_in_name': supply_name,
+ 'purchase_order_id': doc_in.id,
'reservation': bool(l.get('reservation')),
'is_late': bool(l.get('is_late')),
'replenishment_filled': bool(l.get('replenishment_filled')),
@@ -572,7 +573,7 @@ class SaleOrder(models.Model):
'delivery_date': l.get('delivery_date'),
'document_in_name': doc_in.display_name if doc_in else '',
'document_in_model': doc_in._name if doc_in else '',
- 'document_in_id': doc_in.id if doc_in else False,
+ 'purchase_order_id': doc_in.id if doc_in else '',
'document_out_exists': bool(doc_out),
'reservation': bool(l.get('reservation')),
'is_late': bool(l.get('is_late')),
@@ -596,9 +597,9 @@ class SaleOrder(models.Model):
late = '⚠️' if l['is_late'] else ''
# ==== SUPPLY STATUS LOGIC ====
- if l['document_in_id']:
+ if l['purchase_order_id']:
supply_html = f"""
- <a href="/web#id={l['document_in_id']}&model={l['document_in_model']}&view_type=form"
+ <a href="/web#id={l['purchase_order_id']}&model={l['document_in_model']}&view_type=form"
class="font-weight-bold">
{l['document_in_name']}
</a>
@@ -2666,7 +2667,7 @@ class SaleOrder(models.Model):
user = self.env.user
is_sales_admin = user.id in (3401, 20, 3988, 17340)
if is_sales_admin:
- order.approval_status = 'pengajuan0'
+ order.approval_status = 'pengajuan1'
order.message_post(body="Mengajukan approval ke Sales")
return self._create_approval_notification('Sales')
@@ -4026,6 +4027,7 @@ class SaleForecastCoverage(models.Model):
sale_line_id = fields.Many2one('sale.order.line', index=True)
product_id = fields.Many2one('product.product')
+ purchase_order_id = fields.Many2one('purchase.order')
so_qty = fields.Float()
reserved_qty = fields.Float()