importer working with reduced rates and all
This commit is contained in:
parent
1e4a213bd7
commit
05c34fcdaa
90
vat2ful
90
vat2ful
@ -5,6 +5,58 @@ import fulcrmpy.apiv2
|
||||
import settings
|
||||
import datetime
|
||||
|
||||
reduced_map = { "accommodation": "accommodation",
|
||||
"admission to cultural events": "cultural_event",
|
||||
"admission to entertainment events": "entertainment_event",
|
||||
"admission to sporting events": "sporting_event",
|
||||
"advertising": "advertising",
|
||||
"agricultural supplies": "argi_supplies",
|
||||
"baby foodstuffs": "baby_food",
|
||||
"bikes": "bike",
|
||||
"books": "book",
|
||||
"childrens clothing": "clothing_child",
|
||||
"domestic fuel": "fuel_domestic",
|
||||
"domestic services": "services_domestic",
|
||||
"e-books": "ebook",
|
||||
"foodstuffs": "food",
|
||||
"hotels": "hotel",
|
||||
"medical": "medical",
|
||||
"newspapers": "news",
|
||||
"passenger transport": "transport",
|
||||
"pharmaceuticals": "pharma",
|
||||
"property renovations": "renovation",
|
||||
"restaurants": "restaurant",
|
||||
"social housing": "social_housing",
|
||||
"water": "water",
|
||||
"wine": "wine",
|
||||
}
|
||||
|
||||
def check_or_update( fulcrm, country_code, rate, taxtype_name, slug, archived, archived_suffix, fulcrm_rate ):
|
||||
if fulcrm_rate is not None:
|
||||
if ( "%0.2f" % ( fulcrm_rate[ "rate" ] * 100.0 ) ) != ( "%0.2f" % rate ):
|
||||
print( "RATE CHANGE: %s standard from %0.2f to %0.2f" % ( country_code, fulcrm_data[ 'rate' ] * 100, rate ) )
|
||||
fulcrm.patch( fulcrm_rate[ 'url' ], { "archived": archived,
|
||||
"s": "%s_%s" % ( slug, archived_suffix ),
|
||||
},
|
||||
no_d = True )
|
||||
fulcrm.post( 'taxtype/',
|
||||
{ "s": slug,
|
||||
"rate": 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": slug,
|
||||
"rate": rate / 100.0,
|
||||
"name": taxtype_name,
|
||||
},
|
||||
no_d = True )
|
||||
|
||||
def __main__():
|
||||
now = datetime.datetime.now()
|
||||
now_s = now.strftime( "%Y%m%d_%H%M%S" )
|
||||
@ -19,33 +71,17 @@ def __main__():
|
||||
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 )
|
||||
slug = "vatmoss_%s_standard" % ( country_code, )
|
||||
taxtype_name = "%s VAT @ %.1f%%" % ( country_code, country_data[ 'standard_rate' ] )
|
||||
check_or_update( fulcrm, country_code, country_data[ 'standard_rate' ], taxtype_name, slug, now_fulcrm, now_s, fulcrm_data.get( slug, None ) )
|
||||
|
||||
if country_data[ 'reduced_rates' ]:
|
||||
for ( reduced_name, reduced_rate ) in country_data[ 'reduced_rates' ].items():
|
||||
reduced_slug = reduced_map[ reduced_name ]
|
||||
slug = "vatmoss_%s_reduced_%s" % ( country_code, reduced_slug )
|
||||
taxtype_name = "%s (%s) VAT @ %.1f%%" % ( country_code, reduced_name, country_data[ 'standard_rate' ] )
|
||||
check_or_update( fulcrm, country_code, reduced_rate, taxtype_name, slug, now_fulcrm, now_s, fulcrm_data.get( slug, None ) )
|
||||
print( "vat2ful: COMPLETED" )
|
||||
|
||||
if __name__ == '__main__':
|
||||
__main__()
|
||||
|
Loading…
x
Reference in New Issue
Block a user