From 5005eebb8fdd82db1e65a1d3de715d8bb5a63b32 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 10 Jan 2024 11:10:50 +0700 Subject: IU minus inventory validation --- indoteknik_custom/models/stock_picking.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_custom/models/stock_picking.py') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index a5e533b1..0c810ef7 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -281,6 +281,17 @@ class StockPicking(models.Model): self.is_internal_use = self.picking_type_id.is_internal_use return + def validation_minus_onhand_quantity(self): + bu_location_id = 57 + for line in self.move_line_ids_without_package: + quant = self.env['stock.quant'].search([ + ('product_id', '=', line.product_id.id), + ('location_id', '=', bu_location_id) + ]) + + if quant and quant.inventory_quantity < line.product_uom_qty: + raise UserError('Quantity reserved lebih besar dari quantity onhand di product') + def button_validate(self): if self._name != 'stock.picking': return super(StockPicking, self).button_validate() @@ -314,6 +325,8 @@ class StockPicking(models.Model): if not self.date_reserved: current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.date_reserved = current_time + + self.validation_minus_onhand_quantity() res = super(StockPicking, self).button_validate() self.calculate_line_no() -- cgit v1.2.3