@@ -6,8 +6,10 @@ use crate::{
6
6
use super :: { RequisitionTransferProcessor , RequisitionTransferProcessorRecord } ;
7
7
use chrono:: Utc ;
8
8
use repository:: {
9
- ActivityLogType , ApprovalStatusType , EqualFilter , ItemRow , NumberRowType , RepositoryError ,
10
- Requisition , RequisitionLine , RequisitionLineRow , RequisitionLineRowRepository , RequisitionRow ,
9
+ indicator_value:: { IndicatorValueFilter , IndicatorValueRepository } ,
10
+ ActivityLogType , ApprovalStatusType , EqualFilter , IndicatorValueRow ,
11
+ IndicatorValueRowRepository , ItemRow , NumberRowType , RepositoryError , Requisition ,
12
+ RequisitionLine , RequisitionLineRow , RequisitionLineRowRepository , RequisitionRow ,
11
13
RequisitionRowRepository , RequisitionStatus , RequisitionType , StorageConnection , StoreFilter ,
12
14
StoreRepository ,
13
15
} ;
@@ -95,6 +97,33 @@ impl RequisitionTransferProcessor for CreateResponseRequisitionProcessor {
95
97
requisition_line_row_repository. upsert_one ( line) ?;
96
98
}
97
99
100
+ let customer_name_id = StoreRepository :: new ( connection)
101
+ . query_by_filter (
102
+ StoreFilter :: new ( ) . id ( EqualFilter :: equal_to ( & request_requisition. store_row . id ) ) ,
103
+ ) ?
104
+ . pop ( )
105
+ . ok_or ( RepositoryError :: NotFound ) ?
106
+ . name_row
107
+ . id ;
108
+
109
+ let generate_indicator_value_input = GenerateTransferIndicatorInput {
110
+ customer_store_id : request_requisition. store_row . id . clone ( ) ,
111
+ supplier_store_id : record_for_processing. other_party_store_id . clone ( ) ,
112
+ customer_name_id,
113
+ period_id : request_requisition. period . clone ( ) . map ( |p| p. id ) ,
114
+ } ;
115
+
116
+ let new_indicator_values = generate_response_requisition_indicator_values (
117
+ connection,
118
+ generate_indicator_value_input,
119
+ ) ?;
120
+
121
+ let indicator_value_repository = IndicatorValueRowRepository :: new ( connection) ;
122
+
123
+ for value in new_indicator_values. iter ( ) {
124
+ indicator_value_repository. upsert_one ( value) ?;
125
+ }
126
+
98
127
let result = format ! (
99
128
"requisition ({}) lines ({:?}) source requisition ({})" ,
100
129
new_response_requisition. id,
@@ -243,3 +272,38 @@ fn generate_response_requisition_lines(
243
272
244
273
Ok ( response_lines)
245
274
}
275
+
276
+ struct GenerateTransferIndicatorInput {
277
+ customer_store_id : String ,
278
+ supplier_store_id : String ,
279
+ customer_name_id : String ,
280
+ period_id : Option < String > ,
281
+ }
282
+
283
+ fn generate_response_requisition_indicator_values (
284
+ connection : & StorageConnection ,
285
+ input : GenerateTransferIndicatorInput ,
286
+ ) -> Result < Vec < IndicatorValueRow > , RepositoryError > {
287
+ if let Some ( period_id) = input. period_id {
288
+ let supplier_store_id = input. supplier_store_id . clone ( ) ;
289
+ let filter = IndicatorValueFilter :: new ( )
290
+ . store_id ( EqualFilter :: equal_to ( & input. customer_store_id ) )
291
+ . customer_name_id ( EqualFilter :: equal_to ( & input. customer_name_id ) )
292
+ . period_id ( EqualFilter :: equal_to ( & period_id) ) ;
293
+
294
+ let request_indicator_values =
295
+ IndicatorValueRepository :: new ( connection) . query_by_filter ( filter) ?;
296
+
297
+ let response_indicator_values = request_indicator_values
298
+ . into_iter ( )
299
+ . map ( |v| IndicatorValueRow {
300
+ id : uuid ( ) ,
301
+ store_id : supplier_store_id. clone ( ) ,
302
+ ..v. indicator_value_row
303
+ } )
304
+ . collect ( ) ;
305
+
306
+ return Ok ( response_indicator_values) ;
307
+ }
308
+ Ok ( vec ! [ ] )
309
+ }
0 commit comments