diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-11-20 11:39:53 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-11-20 11:39:53 +0700 |
| commit | 1c8ecb8d4532e73e3cf5e5ea74e0a2ff1ca95939 (patch) | |
| tree | 0244e6e180e1c5e0767070c74d110f4baa876e5a | |
| parent | cc3b79a25e277bd360fdcf34eed1f26bdc44204e (diff) | |
add validation if qty_done > qty_onhand
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 7649ef12..5e868edd 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1061,7 +1061,7 @@ class SaleOrder(models.Model): if not partner.customer_type: partner.customer_type = self.customer_type if not partner.user_id: - partner.user_id = self.user_id + partner.user_id = self.user_id.id # if not partner.sppkp or not partner.npwp or not partner.email or partner.customer_type: # partner.customer_type = self.customer_type diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 464e728a..52e70367 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -522,12 +522,31 @@ class StockPicking(models.Model): and quant.inventory_quantity < line.product_uom_qty ): raise UserError('Quantity reserved lebih besar dari quantity onhand di product') + + def check_qty_done_stock(self): + for line in self.move_line_ids_without_package: + def check_qty_per_inventory(self, product, location): + quant = self.env['stock.quant'].search([ + ('product_id', '=', product.id), + ('location_id', '=', location.id), + ]) + if quant: + return quant.quantity + + return 0 + + qty_onhand = check_qty_per_inventory(self, line.product_id, line.location_id) + if line.qty_done > qty_onhand: + raise UserError('Quantity Done melebihi Quantity Onhand') def button_validate(self): if not self.env.user.is_logistic_approver and self.env.context.get('active_model') == 'stock.picking': if self.origin and 'Return of' in self.origin: raise UserError("Button ini hanya untuk Logistik") + + if self.picking_type_code == 'internal': + self.check_qty_done_stock() if self._name != 'stock.picking': return super(StockPicking, self).button_validate() |
