diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-24 14:08:25 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-24 14:08:25 +0700 |
| commit | 1c42785d665f1b4d459e468d9c0428bc6f767954 (patch) | |
| tree | 66018f0a196315f3e4c116064d1f331c092662d5 /fixco_custom/models/stock_picking.py | |
| parent | 5dc0eb722ba306ed2e81acad1b6ba7457717af44 (diff) | |
| parent | 95bcefaef503bcbe787f71ff0aadd2aa2faa47d5 (diff) | |
Merge branch 'main' of bitbucket.org:altafixco/fixco-addons
merge
Diffstat (limited to 'fixco_custom/models/stock_picking.py')
| -rwxr-xr-x | fixco_custom/models/stock_picking.py | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py index 07425d2..6850b1e 100755 --- a/fixco_custom/models/stock_picking.py +++ b/fixco_custom/models/stock_picking.py @@ -645,6 +645,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', @@ -695,29 +696,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 @@ -735,12 +748,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): |
