summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fixco_custom/models/shipment_group.py6
-rwxr-xr-xfixco_custom/models/stock_picking.py47
-rw-r--r--fixco_custom/views/shipment_group.xml24
3 files changed, 56 insertions, 21 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py
index a2d90f0..01e0f6b 100644
--- a/fixco_custom/models/shipment_group.py
+++ b/fixco_custom/models/shipment_group.py
@@ -35,6 +35,12 @@ class ShipmentGroup(models.Model):
picking_lines = fields.One2many('picking.line', 'shipment_id', string='Picking Lines', auto_join=True)
related_count = fields.Integer(compute='_compute_related_count', string='Related Count')
receipt = fields.Char(string='Receipt', related='picking_lines.scan_receipt')
+ total_line = fields.Integer(string='Total Line', compute='_compute_total_line')
+
+ @api.depends('picking_lines')
+ def _compute_total_line(self):
+ for rec in self:
+ rec.total_line = len(rec.picking_lines)
def sync_product_to_picking_line(self):
for shipment in self:
diff --git a/fixco_custom/models/stock_picking.py b/fixco_custom/models/stock_picking.py
index 3610179..ffa5f4a 100755
--- a/fixco_custom/models/stock_picking.py
+++ b/fixco_custom/models/stock_picking.py
@@ -625,6 +625,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',
@@ -675,29 +676,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
@@ -715,12 +728,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):
diff --git a/fixco_custom/views/shipment_group.xml b/fixco_custom/views/shipment_group.xml
index 3edc432..4aae314 100644
--- a/fixco_custom/views/shipment_group.xml
+++ b/fixco_custom/views/shipment_group.xml
@@ -6,6 +6,7 @@
<field name="arch" type="xml">
<tree default_order="create_date desc">
<field name="number"/>
+ <field name="total_line" readonly="1"/>
</tree>
</field>
</record>
@@ -16,15 +17,15 @@
<field name="arch" type="xml">
<form>
<header>
- <button name="get_status"
- string="Get Status"
- type="object"
- class="oe_highlight"
+ <button name="get_status"
+ string="Get Status"
+ type="object"
+ class="oe_highlight"
/>
- <button name="sync_product_to_picking_line"
- string="Sync Picking Line"
- type="object"
- class="oe_highlight"
+ <button name="sync_product_to_picking_line"
+ string="Sync Picking Line"
+ type="object"
+ class="oe_highlight"
/>
</header>
<sheet>
@@ -38,6 +39,7 @@
<group>
<group>
<field name="number" readonly="1"/>
+ <field name="total_line" readonly="1"/>
</group>
</group>
<notebook>
@@ -51,7 +53,7 @@
<field name="order_reference" optional="hide"/>
<field name="status"/>
</tree>
- </field>
+ </field>
</page>
<page string="Line">
<field name="shipment_line">
@@ -62,7 +64,7 @@
<field name="order_reference" optional="hide"/>
<field name="picking_id"/>
</tree>
- </field>
+ </field>
</page>
</notebook>
</sheet>
@@ -83,7 +85,7 @@
<field name="receipt"/>
</search>
</field>
- </record>
+ </record>
<record id="shipment_group_action" model="ir.actions.act_window">
<field name="name">Shipment Group</field>