summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2025-12-22 14:43:47 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2025-12-22 14:43:47 +0700
commit175b10a298185a724b7c0f8d0d25beec38b4f0e1 (patch)
treebd826a385d92cc58948f717228d2b334081fc713
parentfe9056c55bc206a02e52b58baf1881271cf098f8 (diff)
<Miqdad> add message post when adding and removing product in check
product
-rwxr-xr-xfixco_custom/models/stock_picking.py47
1 files changed, 37 insertions, 10 deletions
diff --git a/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py
index e4ed1b5..5c83ac8 100755
--- a/fixco_custom/models/stock_picking.py
+++ b/fixco_custom/models/stock_picking.py
@@ -594,6 +594,7 @@ class CheckProduct(models.Model):
_name = 'check.product'
_description = 'Check Product'
_order = 'picking_id, id'
+ _inherit = ['mail.thread', 'mail.activity.mixin']
picking_id = fields.Many2one(
'stock.picking',
@@ -644,29 +645,41 @@ class CheckProduct(models.Model):
self.quantity = 1
def unlink(self):
- # Get all affected pickings before deletion
- pickings = self.mapped('picking_id')
+ picking_map = {}
+ for line in self:
+ picking_map.setdefault(line.picking_id, []).append({
+ 'product': line.product_id.display_name,
+ 'qty': line.quantity,
+ })
- # Store product_ids that will be deleted
+ pickings = self.mapped('picking_id')
deleted_product_ids = self.mapped('product_id')
- # Perform the deletion
result = super(CheckProduct, self).unlink()
- # After deletion, update moves for affected pickings
for picking in pickings:
- # For products that were completely removed (no remaining check.product lines)
+ if picking in picking_map:
+ product_list = picking_map[picking]
+
+ picking.message_post(
+ body=(
+ "<b>Product Dihapus dari Check Product</b><br/>"
+ "%s"
+ ) % "<br/>".join(
+ "- %s" % product for product in product_list
+ ),
+ subtype_xmlid='mail.mt_note',
+ )
+
remaining_product_ids = picking.check_product_lines.mapped('product_id')
removed_product_ids = deleted_product_ids - remaining_product_ids
- # Set quantity_done to 0 for moves of completely removed products
moves_to_reset = picking.move_ids_without_package.filtered(
lambda move: move.product_id in removed_product_ids
)
for move in moves_to_reset:
move.quantity_done = 0.0
- # Also sync remaining products in case their totals changed
self._sync_check_product_to_moves(picking)
return result
@@ -684,12 +697,26 @@ class CheckProduct(models.Model):
else:
record.status = 'Done'
+
+ @api.model
def create(self, vals):
- # Create the record
record = super(CheckProduct, self).create(vals)
- # Ensure uniqueness after creation
+
+ if record.product_id and record.picking_id:
+ record.picking_id.message_post(
+ body=(
+ "<b>Check Product Berhasil</b><br/>"
+ "Product: %s<br/>"
+ ) % (
+ record.product_id.display_name,
+ ),
+ message_type='comment',
+ subtype_xmlid='mail.mt_note',
+ )
+
if not self.env.context.get('skip_consolidate'):
record.with_context(skip_consolidate=True)._consolidate_duplicate_lines()
+
return record
def write(self, vals):