diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-10 13:52:31 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-10 13:52:31 +0700 |
| commit | aa623e5fd60c9e34c92f9aaa70941895349ae54c (patch) | |
| tree | d7b8b5240dd6dc65aa287c2ea18f807dfc8deb8a /fixco_custom/models | |
| parent | 1a539061cffc5d515301997273fe0258e8fa595e (diff) | |
approval (bang rafly, jason) kalo dia ubah ubah qty di po yang hasil beli nya melebihi max stock
Diffstat (limited to 'fixco_custom/models')
| -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): |
