diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-19 13:05:31 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-19 13:05:31 +0700 |
| commit | 32724232b991afaff527cf5ff9e58a2cad7ea824 (patch) | |
| tree | a2f1dfef6f34390cce274bc1a099381797285627 /indoteknik_custom/models/tukar_guling.py | |
| parent | 1542b2373ef4cff98ded7c9bbf426e18b5524162 (diff) | |
<miqdad> Fix sequence
Diffstat (limited to 'indoteknik_custom/models/tukar_guling.py')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 08b862a7..7bcf5e80 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -160,23 +160,34 @@ class TukarGuling(models.Model): @api.model def create(self, vals): + # Generate sequence number if not vals.get('name') or vals['name'] == 'New': - vals['name'] = self.env['ir.sequence'].next_by_code('tukar.guling') or 'New' + # Pastikan sequence code 'tukar.guling' ada + sequence = self.env['ir.sequence'].search([('code', '=', 'tukar.guling')], limit=1) + if sequence: + vals['name'] = sequence.next_by_id() + else: + # Fallback jika sequence belum dibuat + vals['name'] = self.env['ir.sequence'].next_by_code('tukar.guling') or 'PTG-00001' + # Auto-fill origin from operations if not vals.get('origin') and vals.get('operations'): picking = self.env['stock.picking'].browse(vals['operations']) if picking.origin: vals['origin'] = picking.origin + return super(TukarGuling, self).create(vals) def copy(self, default=None): if default is None: default = {} - if 'name' not in default: - default.update({ - 'name': self.env['ir.sequence'].next_by_code(self._name) or 'New', - }) + # Generate new sequence untuk duplicate + sequence = self.env['ir.sequence'].search([('code', '=', 'tukar.guling')], limit=1) + if sequence: + default['name'] = sequence.next_by_id() + else: + default['name'] = self.env['ir.sequence'].next_by_code('tukar.guling') or 'PTG-COPY' default.update({ 'state': 'draft', @@ -191,7 +202,6 @@ class TukarGuling(models.Model): line.sequence = (i + 1) * 10 return new_record - def write(self, vals): if 'operations' in vals and not vals.get('origin'): picking = self.env['stock.picking'].browse(vals['operations']) @@ -352,6 +362,21 @@ class TukarGuling(models.Model): }) for line in self.line_ids ] }) + for line in self.line_ids: + move = ort_picking.move_ids_without_package.filtered( + lambda m: m.product_id == line.product_id + )[:1] + + if move: + self.env['stock.move.line'].create({ + 'move_id': move.id, + 'picking_id': ort_picking.id, + 'product_id': line.product_id.id, + 'product_uom_id': line.product_uom.id, + 'qty_done': line.product_uom_qty, # Ambil dari return.picking.line.quantity + 'location_id': location_customer.id, + 'location_dest_id': location_dest_id, + }) ort_picking.action_confirm() ort_picking.action_assign() |
