From aa623e5fd60c9e34c92f9aaa70941895349ae54c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 10 Dec 2025 13:52:31 +0700 Subject: approval (bang rafly, jason) kalo dia ubah ubah qty di po yang hasil beli nya melebihi max stock --- fixco_custom/models/purchase_order.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'fixco_custom') diff --git a/fixco_custom/models/purchase_order.py b/fixco_custom/models/purchase_order.py index 7646656..01fa001 100644 --- a/fixco_custom/models/purchase_order.py +++ b/fixco_custom/models/purchase_order.py @@ -348,9 +348,32 @@ class PurchaseOrder(models.Model): def button_confirm(self): + if self.env.user.id not in [12, 10, 2, 15]: + self.check_buffer_stock() + if self.source == 'manual' and self.env.user.id not in [12, 10, 2, 15]: + raise UserError(_("Anda tidak memiliki akses untuk melakukan konfirmasi PO manual")) res = super(PurchaseOrder, self).button_confirm() - self.action_create_order_altama() + if self.partner_id.id == 270: + self.action_create_order_altama() + return res + + def check_buffer_stock(self): + insufficient_products = [] + + for line in self.order_line: + manage_stock = self.env['manage.stock'].search([ + ('product_id', '=', line.product_id.id) + ], limit=1) + + if manage_stock and line.product_qty > manage_stock.buffer_stock: + insufficient_products.append( + f"- {line.product_id.display_name} (qty: {line.product_qty}, buffer: {manage_stock.buffer_stock})" + ) + + if insufficient_products: + message = "Melebihi stock buffer untuk produk berikut:\n\n" + "\n".join(insufficient_products) + raise UserError(message) @api.onchange('shipping_cost') def _onchange_shipping_cost(self): -- cgit v1.2.3