mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-12 17:51:20 +00:00
Merge pull request #44585 from blaggacao/fix/old-data-from-2009-in-migration
fix: migration; make it resilient against old, non-conforming data
This commit is contained in:
@@ -26,33 +26,42 @@ def execute():
|
|||||||
updated_tax_details = {}
|
updated_tax_details = {}
|
||||||
needs_update = False
|
needs_update = False
|
||||||
|
|
||||||
for item, tax_data in json.loads(doc.item_wise_tax_detail).items():
|
try:
|
||||||
if isinstance(tax_data, list) and len(tax_data) == 2:
|
item_iterator = json.loads(doc.item_wise_tax_detail).items()
|
||||||
updated_tax_details[item] = ItemWiseTaxDetail(
|
except AttributeError as e:
|
||||||
tax_rate=tax_data[0],
|
# This is stale data from 2009 found in a database
|
||||||
tax_amount=tax_data[1],
|
if isinstance(json.loads(doc.item_wise_tax_detail), int | float):
|
||||||
# can't be reliably reconstructed since it depends on the tax type
|
needs_update = False
|
||||||
# (actual, net, previous line total, previous line net, etc)
|
|
||||||
net_amount=0.0,
|
|
||||||
)
|
|
||||||
needs_update = True
|
|
||||||
# intermediate patch version of the originating PR
|
|
||||||
elif isinstance(tax_data, list) and len(tax_data) == 3:
|
|
||||||
updated_tax_details[item] = ItemWiseTaxDetail(
|
|
||||||
tax_rate=tax_data[0],
|
|
||||||
tax_amount=tax_data[1],
|
|
||||||
net_amount=tax_data[2],
|
|
||||||
)
|
|
||||||
needs_update = True
|
|
||||||
elif isinstance(tax_data, str):
|
|
||||||
updated_tax_details[item] = ItemWiseTaxDetail(
|
|
||||||
tax_rate=flt(tax_data),
|
|
||||||
tax_amount=0.0,
|
|
||||||
net_amount=0.0,
|
|
||||||
)
|
|
||||||
needs_update = True
|
|
||||||
else:
|
else:
|
||||||
updated_tax_details[item] = tax_data
|
raise e
|
||||||
|
else:
|
||||||
|
for item, tax_data in item_iterator:
|
||||||
|
if isinstance(tax_data, list) and len(tax_data) == 2:
|
||||||
|
updated_tax_details[item] = ItemWiseTaxDetail(
|
||||||
|
tax_rate=tax_data[0],
|
||||||
|
tax_amount=tax_data[1],
|
||||||
|
# can't be reliably reconstructed since it depends on the tax type
|
||||||
|
# (actual, net, previous line total, previous line net, etc)
|
||||||
|
net_amount=0.0,
|
||||||
|
)
|
||||||
|
needs_update = True
|
||||||
|
# intermediate patch version of the originating PR
|
||||||
|
elif isinstance(tax_data, list) and len(tax_data) == 3:
|
||||||
|
updated_tax_details[item] = ItemWiseTaxDetail(
|
||||||
|
tax_rate=tax_data[0],
|
||||||
|
tax_amount=tax_data[1],
|
||||||
|
net_amount=tax_data[2],
|
||||||
|
)
|
||||||
|
needs_update = True
|
||||||
|
elif isinstance(tax_data, str):
|
||||||
|
updated_tax_details[item] = ItemWiseTaxDetail(
|
||||||
|
tax_rate=flt(tax_data),
|
||||||
|
tax_amount=0.0,
|
||||||
|
net_amount=0.0,
|
||||||
|
)
|
||||||
|
needs_update = True
|
||||||
|
else:
|
||||||
|
updated_tax_details[item] = tax_data
|
||||||
|
|
||||||
if needs_update:
|
if needs_update:
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
|
|||||||
Reference in New Issue
Block a user