summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_api/controllers/api_v1/stock_picking.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py
index 2ec1ec2a..92bc91bb 100644
--- a/indoteknik_api/controllers/api_v1/stock_picking.py
+++ b/indoteknik_api/controllers/api_v1/stock_picking.py
@@ -254,3 +254,105 @@ class StockPicking(controller.Controller):
}
)
+
+ @http.route(prefix + 'locator/picking', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_picking_by_name(self, **kw):
+ name = str(kw.get('name'))
+ if not name:
+ return Response(
+ json.dumps({'status': 'error', 'message': 'Field name is required'}),
+ content_type='application/json',
+ status=400
+ )
+
+ picking = request.env['stock.picking'].search([('name', 'ilike', name)], limit=1)
+ if 'BU/INPUT/' in name:
+ move_dest = picking.move_ids_without_package[0]
+ picking = move_dest.move_dest_ids[0].picking_id
+
+ if not picking:
+ return Response(
+ json.dumps({'status': 'error', 'message': f'Picking {name} not found'}),
+ content_type='application/json',
+ status=404
+ )
+
+ lines = []
+ for move in picking.move_line_ids_without_package:
+ lines.append({
+ 'move_id': move.id,
+ 'product_id': move.product_id.id,
+ 'product_name': move.product_id.display_name,
+ 'product_uom_qty': move.product_uom_qty,
+ 'qty_done': move.qty_done,
+ 'uom_name': move.product_uom_id.name,
+ 'source_location': move.location_id.complete_name,
+ 'dest_location': move.location_dest_id.complete_name,
+ })
+
+ data = {
+ 'status': 'success',
+ 'picking': {
+ 'id': picking.id,
+ 'name': picking.name,
+ 'type_code': picking.picking_type_id.code,
+ 'source_location': picking.location_id.complete_name,
+ 'dest_location': picking.location_dest_id.complete_name,
+ 'state': picking.state,
+ 'lines': lines,
+ }
+ }
+
+ return self.response(data)
+
+ @http.route('/api/v1/locator/picking/update', auth='public', methods=['POST'], csrf=False)
+ @controller.Controller.must_authorized()
+ def update_picking_lines(self, **payload):
+ picking_id = payload.get('picking_id')
+ updates = payload.get('lines', [])
+
+ picking = request.env['stock.picking'].sudo().browse(picking_id)
+ if not picking.exists():
+ return {'status': 'error', 'message': 'Picking not found'}
+
+ for line in updates:
+ move = request.env['stock.move'].sudo().browse(line['move_id'])
+ if not move.exists():
+ continue
+
+ for move_line in move.move_line_ids:
+ move_line.qty_done = line.get('qty_done', move_line.qty_done)
+ if 'location_id' in line:
+ move_line.location_id = line['location_id']
+ if 'location_dest_id' in line:
+ move_line.location_dest_id = line['location_dest_id']
+
+ return {'status': 'success', 'message': 'Picking updated'}
+
+ @http.route('/api/v1/locator/picking/validate', auth='public', methods=['POST'], csrf=False)
+ @controller.Controller.must_authorized()
+ def validate_picking(self, **payload):
+ picking_id = payload.get('picking_id')
+ picking = request.env['stock.picking'].sudo().browse(picking_id)
+ if not picking.exists():
+ return {'status': 'error', 'message': 'Picking not found'}
+
+ try:
+ backorder = picking._create_backorder()
+ except Exception:
+ backorder = None
+
+ picking.button_validate()
+
+ result = {
+ 'status': 'success',
+ 'picking_name': picking.name,
+ 'validated': True,
+ 'backorder_created': bool(backorder),
+ }
+
+ if backorder:
+ result['backorder_name'] = backorder.name
+
+ return result