diff --git a/lib/backend/api/api_calls.dart b/lib/backend/api/api_calls.dart index 29f26a4..5e53122 100644 --- a/lib/backend/api/api_calls.dart +++ b/lib/backend/api/api_calls.dart @@ -401,4 +401,159 @@ class ApiCalls { return false; } } + + /// If the requested quantity of the product to be received is greater than + /// the quantity actually received, + /// a confirmation popup must be displayed. + /// The user will then need to perform two actions: + /// choose whether or not to create a backorder. + /// Therefore, this function must be called to generate this confirmation. + /// This function returns the `ID of the backorder` confirmation popup, + /// which must be used to perform the next action, + /// either with or without a backorder. + static Future createBackorderConfirmation({ + required int stockPickingId, + }) async { + try { + final response = await dioService.post( + path: '/web/dataset/call_kw/stock.picking/button_validate', + data: { + "jsonrpc": "2.0", + "method": "call", + "params": { + "model": "stock.backorder.confirmation", + "method": "create", + "args": [ + { + "pick_ids": [ + [ + 6, + 0, + [ + stockPickingId, // stock picking id + ], + ], + ], + "backorder_confirmation_line_ids": [ + [ + 0, + 0, + { + "picking_id": stockPickingId, // stock picking id + //"to_backorder": false // true = avec reliquat / false = sans reliquat + }, + ], + ], + }, + ], + "kwargs": {}, + }, + }, + ); + if (response.statusCode == 200) { + final data = response.data as Map; + if (data.containsKey('result')) { + return data['result']; + } else { + return null; + } + } else { + debugPrint('Erreur réseau: ${response.statusCode}'); + return null; + } + } catch (e) { + debugPrint('Erreur lors de la requête: $e'); + return null; + } + } + + static Future withBackorder({ + required int stockPickingId, + required int createBackorderConfirmationId, + }) async { + try { + final response = await dioService.post( + path: '/web/dataset/call_kw/stock.picking/button_validate', + data: { + "jsonrpc": "2.0", + "method": "call", + "params": { + "model": "stock.backorder.confirmation", + "method": "process", + "args": [ + [ + createBackorderConfirmationId, // id popup backorder confirmation reponse -> create popup reliquat + ], + ], + "kwargs": { + "context": { + "button_validate_picking_ids": [ + stockPickingId, // picking id] + ], + }, + }, + }, + }, + ); + if (response.statusCode == 200) { + final data = response.data as Map; + if (data.containsKey('result')) { + return data['result']; + } else { + return false; + } + } else { + debugPrint('Erreur réseau: ${response.statusCode}'); + return false; + } + } catch (e) { + debugPrint('Erreur lors de la requête: $e'); + return false; + } + } + + static Future withoutBackorder({ + required int stockPickingId, + required int createBackorderConfirmationId, + }) async { + try { + final response = await dioService.post( + path: '/web/dataset/call_kw/stock.picking/button_validate', + data: { + "jsonrpc": "2.0", + "method": "call", + "params": { + "model": "stock.backorder.confirmation", + "method": "process_cancel_backorder", + "args": [ + [ + createBackorderConfirmationId, // id popup backorder confirmation reponse -> create popup reliquat + ], + ], + "kwargs": { + "context": { + "button_validate_picking_ids": [ + stockPickingId, // stock picking id + ], + }, + }, + }, + }, + ); + if (response.statusCode == 200) { + final data = response.data as Map; + if (data.containsKey('result')) { + return data['result']; + } else { + return false; + } + } else { + debugPrint('Erreur réseau: ${response.statusCode}'); + return false; + } + } catch (e) { + debugPrint('Erreur lors de la requête: $e'); + return false; + } + } }