summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-09-26 15:05:22 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-09-26 15:05:22 +0700
commit5e1a6dc4d2bb04a36fcaef023fb9894336ebd4f6 (patch)
tree93f8e486adac1e1370eff799792c640bfc1deae4
parentbe5ae68ee9c9d55611cfbb8243feeee886bc95fd (diff)
cr unreserve
-rw-r--r--indoteknik_custom/models/approval_unreserve.py53
-rw-r--r--indoteknik_custom/views/approval_unreserve.xml4
2 files changed, 31 insertions, 26 deletions
diff --git a/indoteknik_custom/models/approval_unreserve.py b/indoteknik_custom/models/approval_unreserve.py
index e617e11a..88409c37 100644
--- a/indoteknik_custom/models/approval_unreserve.py
+++ b/indoteknik_custom/models/approval_unreserve.py
@@ -24,6 +24,7 @@ class ApprovalUnreserve(models.Model):
picking_id = fields.Many2one('stock.picking', string="Picking", tracking=True)
user_id = fields.Many2one('res.users', string="User", readonly=True, tracking=True)
rejection_reason = fields.Text(string="Rejection Reason", tracking=True)
+ reason = fields.Text(string="Reason", tracking=True)
@api.constrains('picking_id')
def create_move_id_line(self):
@@ -99,38 +100,33 @@ class ApprovalUnreserve(models.Model):
def _trigger_unreserve(self):
stock_move_obj = self.env['stock.move']
-
+
for line in self.approval_line:
- # Step 1: Unreserve the product from the current picking
move = stock_move_obj.browse(line.move_id.id)
move._do_unreserve(product=line.product_id, quantity=line.unreserve_qty)
+ original_sale_id = move.picking_id.sale_id
+
+ product_name = line.product_id.display_name
+ unreserved_qty = line.unreserve_qty
+
if line.dest_picking_id:
+ dest_sale_id = line.dest_picking_id.sale_id
line.dest_picking_id.action_assign()
- # Step 2: Update existing stock move in dest_picking_id
- # if line.dest_picking_id:
- # dest_move = stock_move_obj.search([
- # ('picking_id', '=', line.dest_picking_id.id),
- # ('product_id', '=', line.product_id.id),
- # ('state', 'not in', ['cancel', 'done']) # Only draft or assigned moves can be updated
- # ], limit=1)
-
- # if dest_move:
- # # Add the unreserved quantity to the existing stock move
- # dest_move.write({
- # 'product_uom_qty': dest_move.product_uom_qty + line.unreserve_qty
- # })
-
- # # If the move is in draft state, confirm it and reserve the product
- # if dest_move.state == 'draft':
- # dest_move._action_confirm()
- # dest_move._action_assign() # Reserve the product
-
- # else:
- # # If no move is found, raise an error or handle accordingly
- # raise UserError(f"No stock move found for product {line.product_id.display_name} in the destination picking.")
-
+ if original_sale_id:
+ message = (
+ f"Barang {product_name} sebanyak {unreserved_qty} dipindahkan ke SO {dest_sale_id.name}"
+ if dest_sale_id else
+ f"Barang {product_name} sebanyak {unreserved_qty} dipindahkan ke picking tujuan."
+ )
+ original_sale_id.message_post(body=message)
+ else:
+ if original_sale_id:
+ message = f"Barang {product_name} sebanyak {unreserved_qty} ter unreserve."
+ original_sale_id.message_post(body=message)
+
+
class ApprovalUnreserveLine(models.Model):
_name = 'approval.unreserve.line'
_description = 'Approval Unreserve Line'
@@ -139,5 +135,12 @@ class ApprovalUnreserveLine(models.Model):
approval_id = fields.Many2one('approval.unreserve', string='Approval Reference', required=True, ondelete='cascade', index=True, copy=False)
move_id = fields.Many2one('stock.move', string="Stock Move", required=True)
product_id = fields.Many2one('product.product', string="Product", related='move_id.product_id', readonly=True)
+ sales_id = fields.Many2one('res.users', string="Sales", readonly=True, tracking=True)
unreserve_qty = fields.Float(string="Quantity to Unreserve")
dest_picking_id = fields.Many2one('stock.picking', string="Destination Picking", tracking=True)
+
+
+ @api.onchange('dest_picking_id')
+ def onchange_dest_picking_id(self):
+ if self.dest_picking_id:
+ self.sales_id = self.dest_picking_id.sale_id.user_id.id
diff --git a/indoteknik_custom/views/approval_unreserve.xml b/indoteknik_custom/views/approval_unreserve.xml
index 52de785b..317b5276 100644
--- a/indoteknik_custom/views/approval_unreserve.xml
+++ b/indoteknik_custom/views/approval_unreserve.xml
@@ -9,7 +9,7 @@
<field name="request_date"/>
<field name="picking_id"/>
<field name="state"/>
- <field name="approved_by"/>
+ <field name="user_id"/>
</tree>
</field>
</record>
@@ -22,6 +22,7 @@
<field name="move_id"/>
<field name="product_id"/>
<field name="dest_picking_id"/>
+ <field name="sales_id"/>
<field name="unreserve_qty"/>
</tree>
</field>
@@ -46,6 +47,7 @@
<field name="user_id" readonly="1"/>
<field name="state" readonly="1"/>
<field name="approved_by" readonly="1"/>
+ <field name="reason"/>
</group>
</group>
<notebook>