diff options
| -rw-r--r-- | fixco_custom/models/purchase_order.py | 25 |
1 files changed, 24 insertions, 1 deletions
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): |
