From 0f11923903736a7ccbfc6df815103f890d55d7e9 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 16 Oct 2024 10:29:16 +0700 Subject: add state reserve on stock.picking --- indoteknik_custom/models/stock_picking.py | 18 ++++++++++++++++++ 1 file changed, 18 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 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 -- cgit v1.2.3 From ec04fe1b46e846633108b889f2a4d4cdbbb6ff1e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 16 Oct 2024 11:55:56 +0700 Subject: cr state reserve --- indoteknik_custom/models/stock_picking.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (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 33e577bc..1b2baea7 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -141,17 +141,23 @@ class StockPicking(models.Model): res = super(StockPicking, self).do_unreserve() current_time = datetime.datetime.utcnow() self.date_unreserve = current_time - self.check_state_reserve() + # 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 + do = self.search([ + ('state', 'not in', ['cancel', 'draft', 'done']), + ('picking_type_code', '=', 'outgoing') + ]) + + for rec in do: + rec.state_reserve = 'ready' + + for line in rec.move_ids_without_package: + if line.product_uom_qty > line.reserved_availability: + rec.state_reserve = 'waiting' + break def _create_approval_notification(self, approval_role): title = 'Warning' @@ -291,7 +297,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() + # self.check_state_reserve() return res def ask_approval(self): -- cgit v1.2.3