summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py48
1 files changed, 41 insertions, 7 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 18811b85..b34ec926 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -6,6 +6,7 @@ import logging
from pytz import timezone, utc
import io
import base64
+from odoo.tools import lazy_property
try:
from odoo.tools.misc import xlsxwriter
except ImportError:
@@ -115,6 +116,20 @@ class PurchaseOrder(models.Model):
compute='_compute_complete_bu_in_count'
)
+ show_description = fields.Boolean(
+ string='Show Description',
+ default=True
+ )
+
+ @api.onchange('show_description')
+ def onchange_show_description(self):
+ if self.show_description == True:
+ for line in self.order_line:
+ line.show_description = True
+ else:
+ for line in self.order_line:
+ line.show_description = False
+
def _compute_complete_bu_in_count(self):
for order in self:
if order.state not in ['done', 'cancel']:
@@ -137,7 +152,7 @@ class PurchaseOrder(models.Model):
def _compute_date_planned(self):
""" date_planned = the earliest date_planned across all order lines. """
for order in self:
- order.date_planned = False
+ order.date_planned = order.date_planned
@api.constrains('date_planned')
def constrains_date_planned(self):
@@ -183,8 +198,11 @@ class PurchaseOrder(models.Model):
# Ambil semua BU awal dari PO
base_bu = StockPicking.search([
+ '|',
+ '&',
('name', 'ilike', 'BU/'),
- ('origin', 'ilike', order.name)
+ ('group_id.id', '=', order.group_id.id),
+ ('origin', '=', order.name),
])
all_bu = base_bu
@@ -214,10 +232,12 @@ class PurchaseOrder(models.Model):
# Step 1: cari semua BU pertama (PUT, INT) yang berasal dari PO ini
base_bu = StockPicking.search([
+ '|',
+ '&',
('name', 'ilike', 'BU/'),
- ('origin', 'ilike', self.name)
+ ('group_id.id', '=', self.group_id.id),
+ ('origin', '=', self.name),
])
-
all_bu = base_bu
seen_names = set(base_bu.mapped('name'))
@@ -228,10 +248,10 @@ class PurchaseOrder(models.Model):
('origin', 'in', ['Return of %s' % name for name in seen_names])
])
next_names = set(next_bu.mapped('name'))
-
+
if not next_names - seen_names:
break
-
+
all_bu |= next_bu
seen_names |= next_names
@@ -1037,8 +1057,19 @@ class PurchaseOrder(models.Model):
message="Produk "+line.product_id.name+" memiliki vendor berbeda dengan SO (Vendor PO: "+str(self.partner_id.name)+", Vendor SO: "+str(line.so_line_id.vendor_id.name)+")",
sticky=True
)
+
+ def _check_assets_note(self):
+ for order in self:
+ # Cari apakah ada line dengan produk ID 614469 ('Assets Mesin & Peralatan')
+ asset_line = order.order_line.filtered(lambda l: l.product_id.id == 595346)
+ if asset_line and not order.notes:
+ raise UserError(_(
+ "%s berisi produk 'Assets Mesin & Peralatan'. "
+ "Harap isi Notes untuk menjelaskan kebutuhan dan divisi terkait."
+ ) % order.name)
def button_confirm(self):
+ self._check_assets_note()
# self._check_payment_term() # check payment term
res = super(PurchaseOrder, self).button_confirm()
current_time = datetime.now()
@@ -1066,8 +1097,11 @@ class PurchaseOrder(models.Model):
# sticky=True
# )
+ has_bom = self.product_bom_id.id
+ has_manufacturing = self.manufacturing_id.id
+
if not self.from_apo:
- if not self.matches_so and not self.env.user.is_purchasing_manager and not self.env.user.is_leader:
+ if not self.matches_so and not self.env.user.is_purchasing_manager and not self.env.user.is_leader and not has_bom and not has_manufacturing:
raise UserError("Tidak ada link dengan SO, harus di confirm oleh Purchasing Manager")
send_email = False