summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-10-16 10:29:16 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-10-16 10:29:16 +0700
commit0f11923903736a7ccbfc6df815103f890d55d7e9 (patch)
treefae1174a4f58be9adcc82c2c205295033d22f808
parent53e39ccf1780beda4f27ae2e67566d57ac915654 (diff)
add state reserve on stock.picking
-rw-r--r--indoteknik_custom/models/approval_unreserve.py5
-rw-r--r--indoteknik_custom/models/stock_picking.py18
-rw-r--r--indoteknik_custom/views/stock_picking.xml1
3 files changed, 22 insertions, 2 deletions
diff --git a/indoteknik_custom/models/approval_unreserve.py b/indoteknik_custom/models/approval_unreserve.py
index 88409c37..85dfffff 100644
--- a/indoteknik_custom/models/approval_unreserve.py
+++ b/indoteknik_custom/models/approval_unreserve.py
@@ -31,12 +31,12 @@ class ApprovalUnreserve(models.Model):
if not self.picking_id:
raise ValidationError("Picking is required")
- stock_move = self.env['stock.move'].search([('picking_id', '=', self.picking_id.id), ('state', '=', 'assigned')])
+ stock_move = self.env['stock.move'].search([('picking_id', '=', self.picking_id.id), ('state', 'in', ['assigned', 'partially_available'])])
if not stock_move:
raise ValidationError("Picking is not found")
- for move in stock_move:
+ for move in stock_move:
self.approval_line.create({
'approval_id': self.id,
'move_id': move.id
@@ -86,6 +86,7 @@ class ApprovalUnreserve(models.Model):
})
# Trigger the unreserve function
self._trigger_unreserve()
+ self.picking_id.check_state_reserve()
def action_reject(self, reason):
if self.env.user.id != self.user_id.id:
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 14190474..33e577bc 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -101,6 +101,13 @@ class StockPicking(models.Model):
('no', 'Nothing to Invoice')
], string='Invoice Status', related="sale_id.invoice_status")
+ state_reserve = fields.Selection([
+ ('waiting', 'Waiting For Fullfilment'),
+ ('ready', 'Ready to Ship'),
+ ('done', 'Done'),
+ ('cancel', 'Cancelled'),
+ ], string='Status Reserve', readonly=True, tracking=True, help="The current state of the stock picking.")
+
@api.constrains('driver_departure_date')
def constrains_driver_departure_date(self):
self.date_doc_kirim = self.driver_departure_date
@@ -134,9 +141,18 @@ class StockPicking(models.Model):
res = super(StockPicking, self).do_unreserve()
current_time = datetime.datetime.utcnow()
self.date_unreserve = current_time
+ self.check_state_reserve()
return res
+ def check_state_reserve(self):
+ self.state_reserve = 'ready'
+
+ for line in self.move_ids_without_package:
+ if line.product_uom_qty > line.reserved_availability:
+ self.state_reserve = 'waiting'
+ break
+
def _create_approval_notification(self, approval_role):
title = 'Warning'
message = f'Butuh approval sales untuk unreserved'
@@ -275,6 +291,7 @@ class StockPicking(models.Model):
current_time = datetime.datetime.utcnow()
self.real_shipping_id = self.sale_id.real_shipping_id
self.date_availability = current_time
+ self.check_state_reserve()
return res
def ask_approval(self):
@@ -421,6 +438,7 @@ class StockPicking(models.Model):
res = super(StockPicking, self).button_validate()
self.calculate_line_no()
self.date_done = datetime.datetime.utcnow()
+ self.state_reserve = 'done'
return res
@api.model
diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml
index 899d29eb..af1af563 100644
--- a/indoteknik_custom/views/stock_picking.xml
+++ b/indoteknik_custom/views/stock_picking.xml
@@ -16,6 +16,7 @@
<field name="driver_arrival_date" optional="hide"/>
<field name="note_logistic" optional="hide"/>
<field name="note" optional="hide"/>
+ <field name="state_reserve" optional="hide"/>
</field>
<field name="partner_id" position="after">
<field name="purchase_representative_id"/>