summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-11-29 10:05:58 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-11-29 10:05:58 +0700
commit8906f678c23090d70d16191dc1fe76e518e8e9d9 (patch)
treea98cb41a39064f692d764338177b84fd14bed82a /indoteknik_custom/models/purchase_order.py
parentd0bd4a82c923789a931f9433085f4219c6d7346a (diff)
parent0080b6b1da5f181cee32fae7bb5166ce65165374 (diff)
Merge branch 'production' into CR/quotation-noPo
# Conflicts: # indoteknik_custom/models/user_company_request.py
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py66
1 files changed, 61 insertions, 5 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index ef86bc61..9388ae4c 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -72,6 +72,8 @@ class PurchaseOrder(models.Model):
grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total')
total_margin_match = fields.Float(string='Total Margin Match', compute='_compute_total_margin_match')
approve_by = fields.Many2one('res.users', string='Approve By')
+ exclude_incoming = fields.Boolean(string='Exclude Incoming', default=False,
+ help='Centang jika tidak mau masuk perhitungan Incoming Qty')
def _compute_total_margin_match(self):
for purchase in self:
@@ -583,10 +585,29 @@ class PurchaseOrder(models.Model):
picking.scheduled_date = self.date_planned
picking.date_deadline = self.date_planned
+ def _check_qty_plafon_product(self):
+ for line in self.order_line:
+ if not line.product_id:
+ continue
+ # test = line.product_uom_qty
+ # test2 = line.product_id.plafon_qty
+ # test3 = test2 + line.product_uom_qty
+ if line.product_uom_qty > line.product_id.plafon_qty + line.product_uom_qty and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
+ raise UserError('Product '+line.product_id.name+' melebihi plafon, harus Approval MD')
+
+ def check_different_vendor_so_po(self):
+ vendor_po = self.partner_id.id
+ for line in self.order_line:
+ if not line.so_line_id:
+ continue
+ if line.so_line_id.vendor_id.id != vendor_po and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
+ raise UserError("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)+")")
+
def button_confirm(self):
res = super(PurchaseOrder, self).button_confirm()
current_time = datetime.now()
self.check_ppn_mix()
+ self.check_different_vendor_so_po()
# self.check_data_vendor()
if self.amount_untaxed >= 50000000 and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
@@ -635,7 +656,8 @@ class PurchaseOrder(models.Model):
self.date_planned = delta_time
self.date_deadline_ref_date_planned()
self.unlink_purchasing_job_state()
-
+
+ self._check_qty_plafon_product()
return res
@@ -723,11 +745,12 @@ class PurchaseOrder(models.Model):
template.send_mail(self.id, force_send=True)
def po_approve(self):
- if self.amount_untaxed >= 50000000 and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
- raise UserError("Hanya Merchandiser yang bisa approve")
+ greater_than_plafon, message = self._get_msg_plafon_qty()
+ different_vendor_message = self.check_different_vendor_so() # Panggil fungsi check_different_vendor_so
+
if self.env.user.is_leader or self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
raise UserError("Bisa langsung Confirm")
- elif self.total_percent_margin == self.total_so_percent_margin and self.matches_so:
+ elif self.total_percent_margin == self.total_so_percent_margin and self.matches_so and not greater_than_plafon and not different_vendor_message:
raise UserError("Bisa langsung Confirm")
else:
reason = ''
@@ -740,13 +763,46 @@ class PurchaseOrder(models.Model):
reason += 'not link with pj and reorder, '
if not self.matches_so:
reason += 'not link with so, '
+ # Check Plafon Qty and Get Message every Line Product
+ if greater_than_plafon:
+ reason += message
+ # Check for Different Vendor Message
+ if different_vendor_message:
+ reason += different_vendor_message
+
# Post a highlighted message to lognote
self.message_post(
body=f"<div style='background-color: #fdf2e9; border: 1px solid #f5c6cb; padding: 10px;'>"
- f"<b>Note (Pinned):</b><br>{reason}</div>",
+ f"<b>Note (Pinned):</b><br>{reason}</div>",
subtype_id=self.env.ref("mail.mt_note").id
)
+
+ def check_different_vendor_so(self):
+ vendor_po = self.partner_id.id
+ message = ''
+ for line in self.order_line:
+ if not line.so_line_id:
+ continue
+ if line.so_line_id.vendor_id.id != vendor_po:
+ product_code = line.product_id.display_name or 'Unknown'
+ message += (f"Produk {product_code} memiliki vendor berbeda dengan SO "
+ f"(Vendor PO: {self.partner_id.name}, Vendor SO: {line.so_line_id.vendor_id.name}), ")
+ return message if message else None
+
+ def _get_msg_plafon_qty(self):
+ message = ''
+ greater_than_plafon = False
+ for line in self.order_line:
+ if not line.product_id:
+ continue
+ if line.product_uom_qty > line.product_id.plafon_qty:
+ message = (message + '\n'+line.product_id.default_code + ' melebihi plafon ('
+ + str(line.product_id.plafon_qty) + ') vs Qty PO ('+str(line.product_uom_qty)+')'
+ + ', ')
+ greater_than_plafon = True
+ return greater_than_plafon, message
+
def re_calculate(self):
if self.from_apo:
self.re_calculate_from_apo()