1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
from odoo import models, fields, api, _
from odoo.exceptions import UserError
class StockPickingShipmentGroup(models.TransientModel):
_name = 'stock.picking.shipment_group'
_description = 'Stock Picking Shipment Group'
def create_shipment_group(self):
picking_ids = self.env.context.get('picking_ids')
if not picking_ids:
raise UserError("No stock picking selected.")
pickings = self.env['stock.picking'].browse(picking_ids)
# Validasi - semua carrier harus memiliki prefix yang sama
carriers = list(set(pickings.mapped('carrier'))) # Get unique carriers
if len(carriers) > 1:
prefixes = set()
for carrier in carriers:
if not carrier:
continue
prefix = carrier.split()[0] if ' ' in carrier else carrier
prefixes.add(prefix)
if len(prefixes) > 1:
different_carriers = "\n".join(f"- {c}" for c in sorted(carriers)) if carriers else "None"
raise UserError(
"Cannot group shipments with different carrier providers.\n"
f"Different carrier providers found:\n{different_carriers}\n\n"
"Please make sure all pickings have the same carrier provider."
)
shipment_group = self.env['shipment.group'].create({})
for picking in pickings:
if picking.shipment_group_id:
continue
if not picking.carrier or not picking.provider_name:
raise UserError("Harus hit api label ginee terlebih dahulu untuk mendapatkan ekspedisinya")
picking.shipment_group_id = shipment_group.id
for move in picking.move_ids_without_package:
self.env['shipment.group.line'].create({
'shipment_id': shipment_group.id,
'product_id': move.product_id.id,
'carrier': picking.carrier,
'invoice_marketplace': picking.invoice_mp,
'picking_id': picking.id,
})
return {
'type': 'ir.actions.act_window',
'res_model': 'shipment.group',
'view_mode': 'form',
'res_id': shipment_group.id,
'target': 'current',
}
|