<s> from datetime import datetime <EOL> from dimagi . utils . parsing import json_format_datetime <EOL> def balance_ota_block ( sp , section_id , product_amounts , datestring ) : <EOL> return """<STR_LIT>""" . format ( <EOL> sp_id = sp . case_id , <EOL> section_id = section_id , <EOL> long_date = datestring , <EOL> product_block = products_xml ( product_amounts ) , <EOL> ) <EOL> def submission_wrap ( instance_id , products , user , sp_id , sp2_id , insides , timestamp = None , <EOL> date_formatter = json_format_datetime ) : <EOL> timestamp = timestamp or datetime . utcnow ( ) <EOL> date_string = date_formatter ( timestamp ) <EOL> insides = insides ( ) if callable ( insides ) else insides <EOL> return ( """<STR_LIT>""" % insides ) . format ( <EOL> sp_id = sp_id , <EOL> sp2_id = sp2_id , <EOL> product0 = products [ <NUM_LIT:0> ] . _id , <EOL> product1 = products [ <NUM_LIT:1> ] . _id , <EOL> product2 = products [ <NUM_LIT:2> ] . _id , <EOL> user_id = user . _id , <EOL> instance_id = instance_id , <EOL> username = user . username , <EOL> long_date = date_string , <EOL> ) <EOL> def products_xml ( product_amount_tuples ) : <EOL> return '<STR_LIT>' . join ( [ <EOL> '<STR_LIT>' . format ( <EOL> id = p , quantity = amt , <EOL> ) for p , amt in product_amount_tuples <EOL> ] ) <EOL> def _enumerated_products_xml ( product_amount_tuples , section_id = '<STR_LIT>' ) : <EOL> return '<STR_LIT>' . join ( [ <EOL> """<STR_LIT>""" . format ( id = p , section_id = section_id , quantity = amt ) for p , amt in product_amount_tuples <EOL> ] ) <EOL> def balance_submission ( product_amounts , section_id = '<STR_LIT>' ) : <EOL> return """<STR_LIT>""" % { '<STR_LIT>' : products_xml ( product_amounts ) , '<STR_LIT>' : section_id } <EOL> def balance_enumerated ( product_amounts , section_id = '<STR_LIT>' ) : <EOL> return """<STR_LIT>""" % { '<STR_LIT>' : _enumerated_products_xml ( product_amounts , section_id ) , '<STR_LIT>' : section_id } <EOL> def transfer_dest_only ( product_amounts ) : <EOL> return """<STR_LIT>""" % { '<STR_LIT>' : products_xml ( product_amounts ) } <EOL> def transfer_source_only ( product_amounts ) : <EOL> return """<STR_LIT>""" % { '<STR_LIT>' : products_xml ( product_amounts ) } <EOL> def transfer_both ( product_amounts ) : <EOL> return """<STR_LIT>""" % { '<STR_LIT>' : products_xml ( product_amounts ) } <EOL> def receipts_enumerated ( product_amounts ) : <EOL> return """<STR_LIT>""" % { '<STR_LIT>' : _enumerated_products_xml ( product_amounts ) } <EOL> def balance_first ( balance_amounts , transfer_amounts ) : <EOL> return '<STR_LIT>' % ( balance_submission ( balance_amounts ) , transfer_dest_only ( transfer_amounts ) ) <EOL> def transfer_first ( transfer_amounts , balance_amounts ) : <EOL> return '<STR_LIT>' % ( transfer_dest_only ( transfer_amounts ) , balance_submission ( balance_amounts ) ) </s>
