summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_move.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/stock_move.py')
-rw-r--r--indoteknik_custom/models/stock_move.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py
index 1da2befe..8f8ba66f 100644
--- a/indoteknik_custom/models/stock_move.py
+++ b/indoteknik_custom/models/stock_move.py
@@ -186,6 +186,56 @@ class StockMoveLine(models.Model):
line_no = fields.Integer('No', default=0)
note = fields.Char('Note')
manufacture = fields.Many2one('x_manufactures', string="Brands", related="product_id.x_manufacture", store=True)
+ outstanding_qty = fields.Float(
+ string='Outstanding Qty',
+ compute='_compute_delivery_line_status',
+ store=False
+ )
+ delivery_status = fields.Selection([
+ ('none', 'No Movement'),
+ ('partial', 'Partial'),
+ ('partial_final', 'Partial Final'),
+ ('full', 'Full'),
+ ], string='Delivery Status', compute='_compute_delivery_line_status', store=False)
+
+ @api.depends('qty_done', 'product_uom_qty', 'picking_id.state')
+ def _compute_delivery_line_status(self):
+ for line in self:
+ line.outstanding_qty = 0.0
+ line.delivery_status = 'none'
+
+ picking = line.picking_id
+ if not picking or picking.picking_type_id.code != 'outgoing':
+ continue
+
+ total_qty = line.move_id.product_uom_qty or 0
+ done_qty = line.qty_done or 0
+
+ line.outstanding_qty = max(total_qty - done_qty, 0)
+
+ if total_qty == 0:
+ continue
+
+ if done_qty == 0:
+ line.delivery_status = 'none'
+ elif done_qty > 0:
+ has_other_out = self.env['stock.picking'].search_count([
+ ('group_id', '=', picking.group_id.id),
+ ('name', 'ilike', 'BU/OUT'),
+ ('id', '!=', picking.id),
+ ('state', '=', 'done'),
+ ])
+ if has_other_out and done_qty == total_qty:
+ line.delivery_status = 'partial_final'
+ elif not has_other_out and done_qty >= total_qty:
+ line.delivery_status = 'full'
+ elif has_other_out and done_qty < total_qty:
+ line.delivery_status = 'partial'
+ elif done_qty < total_qty:
+ line.delivery_status = 'partial'
+ else:
+ line.delivery_status = 'none'
+
# Ambil uom dari stock move
@api.model