feat: Adds API for backorder confirmation flow

Implements the API calls necessary to handle backorder confirmations.

This enables the application to manage scenarios where the received product quantity is less than requested. It provides functions to:
- Generate the backorder confirmation popup.
- Process the confirmation to create a backorder.
- Process the confirmation to cancel the backorder.
This commit is contained in:
mandreshope 2025-08-02 20:40:08 +03:00
parent b4a73f1bad
commit 4c18b05e18

View File

@ -401,4 +401,159 @@ class ApiCalls {
return false; 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<int?> 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<String, dynamic>;
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<bool> 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<String, dynamic>;
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<bool> 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<String, dynamic>;
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;
}
}
} }