diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-06-16 14:37:23 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-06-16 14:37:23 +0700 |
| commit | 4a65f46a5b7fd1bc48bc04cbf456119332fff0fe (patch) | |
| tree | 97219770248095c25a673d44dd8d0053d792a0f2 /fixco_custom/models/shipment_group.py | |
| parent | 55936047e729cadcd462a57c7838f77f7c57ee1a (diff) | |
uangmuka penjualan and cr schema shipment group
Diffstat (limited to 'fixco_custom/models/shipment_group.py')
| -rw-r--r-- | fixco_custom/models/shipment_group.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py index 71d7981..5f6c315 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -13,6 +13,58 @@ class ShipmentGroup(models.Model): number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True) shipment_line = fields.One2many('shipment.group.line', 'shipment_id', string='Shipment Group Lines', auto_join=True) + scan_invoice = fields.Char(string="Scan Invoice Marketplace") + + @api.onchange('scan_invoice') + def _onchange_scan_invoice(self): + if self.scan_invoice: + result = self.add_lines_from_scan(self.scan_invoice) + self.scan_invoice = False # Reset field setelah scan + return result + + def add_lines_from_scan(self, scan_value): + self.ensure_one() + picking = self.env['stock.picking'].search([ + ('invoice_mp', '=', scan_value) + ], limit=1) + + if not picking: + return { + 'warning': { + 'title': 'Not Found', + 'message': f'No picking found with invoice: {scan_value}' + } + } + + # Cek duplikat + existing_lines = self.shipment_line.filtered(lambda l: l.picking_id == picking) + if existing_lines: + return { + 'warning': { + 'title': 'Duplicate', + 'message': 'This picking has already been added to the shipment group' + } + } + + # Buat line untuk setiap move + created_lines = [] + for move in picking.move_ids_without_package: + line = self.env['shipment.group.line'].create({ + 'shipment_id': self.id, + 'product_id': move.product_id.id, + 'carrier': picking.carrier, + 'invoice_marketplace': picking.invoice_mp, + 'picking_id': picking.id, + }) + created_lines.append(line.id) + + return { + 'effect': { + 'fadeout': 'slow', + 'message': f'Added {len(created_lines)} products from {picking.name}', + 'type': 'rainbow_man', + } + } @api.model def create(self, vals): |
