initial version of script
parent
9f86b9fc07
commit
1e4a213bd7
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import fulcrmpy.apiv2
|
||||||
|
import settings
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
def __main__():
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
now_s = now.strftime( "%Y%m%d_%H%M%S" )
|
||||||
|
now_fulcrm = now.strftime( "%Y-%m-%dT%H:%M:%S.%f" )
|
||||||
|
|
||||||
|
fulcrm = fulcrmpy.apiv2.APIv2( settings.FULCRM_USER, settings.FULCRM_API_KEY )
|
||||||
|
fulcrm_data = {}
|
||||||
|
for taxtype in fulcrm.get_many( "taxtype/", no_d = True ):
|
||||||
|
fulcrm_data[ taxtype[ 's' ] ] = taxtype
|
||||||
|
|
||||||
|
api_data = requests.get( settings.VATLAYER_API_URL ).json()
|
||||||
|
if not api_data[ 'success' ]:
|
||||||
|
return
|
||||||
|
for ( country_code, country_data ) in api_data[ 'rates' ].items():
|
||||||
|
standard_name = "vatmoss_%s_standard" % ( country_code, )
|
||||||
|
taxtype_name = "VATMOSS %s %.1f%%" % ( country_code, country_data[ 'standard_rate' ] )
|
||||||
|
if standard_name in fulcrm_data:
|
||||||
|
fulcrm_rate = fulcrm_data[ standard_name ]
|
||||||
|
if ( "%0.2f" % ( fulcrm_rate[ "rate" ] * 100.0 ) ) != ( "%0.2f" % country_data[ 'standard_rate' ] ):
|
||||||
|
print( "RATE CHANGE: %s standard from %0.2f to %0.2f" % ( country_code, fulcrm_data[ 'rate' ] * 100, country_data[ 'standard_rate' ] ) )
|
||||||
|
fulcrm.patch( fulcrm_rate[ 'url' ], { "archived": now_fulcrm,
|
||||||
|
"s": "%s_%s" % ( standard_name, now_s ),
|
||||||
|
},
|
||||||
|
no_d = True )
|
||||||
|
fulcrm.post( 'taxtype/',
|
||||||
|
{ "s": standard_name,
|
||||||
|
"rate": country_data[ 'standard_rate' ] / 100.0,
|
||||||
|
"name": taxtype_name,
|
||||||
|
},
|
||||||
|
no_d = True )
|
||||||
|
elif ( fulcrm_rate[ 'name' ] != taxtype_name ):
|
||||||
|
print( 'NAME CHANGE: "%s" to "%s"' % ( fulcrm_rate[ 'name' ], taxtype_name ) )
|
||||||
|
fulcrm.patch( fulcrm_rate[ 'url' ], { 'name': taxtype_name }, no_d = True )
|
||||||
|
else:
|
||||||
|
print( 'MISSING RATE: "%s"' % ( taxtype_name, ) )
|
||||||
|
fulcrm.post( 'taxtype',
|
||||||
|
{ "s": standard_name,
|
||||||
|
"rate": country_data[ 'standard_rate' ] / 100.0,
|
||||||
|
"name": taxtype_name,
|
||||||
|
},
|
||||||
|
no_d = True )
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
__main__()
|
Loading…
Reference in New Issue