fix(JW Import): Handle negative amounts properly
This commit is contained in:
parent
f3be72cda9
commit
75b009e250
@ -67,7 +67,7 @@ class JWImport(Document):
|
|||||||
if fieldname[-4:] == 'date':
|
if fieldname[-4:] == 'date':
|
||||||
val = get_datetime(parse_date(val)).date()
|
val = get_datetime(parse_date(val)).date()
|
||||||
elif fieldname == 'amount':
|
elif fieldname == 'amount':
|
||||||
val = re.sub('^[^.,\d]*', '', val)
|
val = re.sub('^[^-.,\d]*', '', val)
|
||||||
temp[fieldname] = val
|
temp[fieldname] = val
|
||||||
if (si_date and temp['invoice_date'] < si_date):
|
if (si_date and temp['invoice_date'] < si_date):
|
||||||
continue
|
continue
|
||||||
@ -383,6 +383,9 @@ def record_entries(doc):
|
|||||||
amnt = int(rec_amt*share.percentage)/100.0
|
amnt = int(rec_amt*share.percentage)/100.0
|
||||||
if s == 0: amnt = rec_amt - so_far
|
if s == 0: amnt = rec_amt - so_far
|
||||||
so_far += amnt
|
so_far += amnt
|
||||||
|
cred = 0.0; deb = amnt;
|
||||||
|
if (amnt < 0.0):
|
||||||
|
cred = -amnt; deb = 0.0;
|
||||||
if importer.dim_balance_account:
|
if importer.dim_balance_account:
|
||||||
imb_key = *((dim,share.get(dim))
|
imb_key = *((dim,share.get(dim))
|
||||||
for dim in rebalance_dims),
|
for dim in rebalance_dims),
|
||||||
@ -394,8 +397,8 @@ def record_entries(doc):
|
|||||||
party_type=rec.reference_doctype,
|
party_type=rec.reference_doctype,
|
||||||
party=rec.reference_doc,
|
party=rec.reference_doc,
|
||||||
account_currency=importer.justworks_currency,
|
account_currency=importer.justworks_currency,
|
||||||
debit_in_account_currency=amnt,
|
debit_in_account_currency=deb,
|
||||||
credit_in_account_currency=0.0,
|
credit_in_account_currency=cred,
|
||||||
user_remark=jea_remarks))
|
user_remark=jea_remarks))
|
||||||
rec.set('disposition', 'Duplicate')
|
rec.set('disposition', 'Duplicate')
|
||||||
# Should we emit a journal entry?
|
# Should we emit a journal entry?
|
||||||
@ -419,8 +422,8 @@ def record_entries(doc):
|
|||||||
# Now generate "other sides":
|
# Now generate "other sides":
|
||||||
if importer.dim_balance_account:
|
if importer.dim_balance_account:
|
||||||
for dimvec in current_dim_imbalance:
|
for dimvec in current_dim_imbalance:
|
||||||
if not current_dim_imbalance[dimvec] > 0.0:
|
amnt = current_dim_imbalance[dimvec]
|
||||||
continue
|
if amnt == 0.0: continue
|
||||||
jea = je.append('accounts', {})
|
jea = je.append('accounts', {})
|
||||||
jea.set('account',
|
jea.set('account',
|
||||||
importer.dim_balance_account)
|
importer.dim_balance_account)
|
||||||
@ -428,9 +431,10 @@ def record_entries(doc):
|
|||||||
jea.set(dim, val)
|
jea.set(dim, val)
|
||||||
jea.set('account_currency',
|
jea.set('account_currency',
|
||||||
importer.justworks_currency)
|
importer.justworks_currency)
|
||||||
jea.set('debit_in_account_currency', 0.0)
|
jea.set('debit_in_account_currency',
|
||||||
|
0.0 if amnt > 0.0 else -amnt)
|
||||||
jea.set('credit_in_account_currency',
|
jea.set('credit_in_account_currency',
|
||||||
current_dim_imbalance[dimvec])
|
amnt if amnt > 0.0 else 0.0)
|
||||||
jea.set('user_remark', standard_remark)
|
jea.set('user_remark', standard_remark)
|
||||||
oja = je.append('accounts', {})
|
oja = je.append('accounts', {})
|
||||||
oja.set('account',
|
oja.set('account',
|
||||||
@ -440,16 +444,19 @@ def record_entries(doc):
|
|||||||
oja.set('account_currency',
|
oja.set('account_currency',
|
||||||
importer.justworks_currency)
|
importer.justworks_currency)
|
||||||
oja.set('debit_in_account_currency',
|
oja.set('debit_in_account_currency',
|
||||||
current_dim_imbalance[dimvec])
|
amnt if amnt > 0.0 else 0.0)
|
||||||
oja.set('credit_in_account_currency', 0.0)
|
oja.set('credit_in_account_currency',
|
||||||
|
0.0 if amnt > 0.0 else -amnt)
|
||||||
oja.set('user_remark', standard_remark)
|
oja.set('user_remark', standard_remark)
|
||||||
bja = je.append('accounts', {})
|
bja = je.append('accounts', {})
|
||||||
bja.set('account', importer.jw_obligation_account)
|
bja.set('account', importer.jw_obligation_account)
|
||||||
for (dim,val) in standard_dims.items():
|
for (dim,val) in standard_dims.items():
|
||||||
bja.set(dim,val)
|
bja.set(dim,val)
|
||||||
bja.set('account_currency', importer.justworks_currency)
|
bja.set('account_currency', importer.justworks_currency)
|
||||||
bja.set('debit_in_account_currency', 0.0)
|
bja.set('debit_in_account_currency',
|
||||||
bja.set('credit_in_account_currency', current_total)
|
0.0 if current_total > 0.0 else -current_total)
|
||||||
|
bja.set('credit_in_account_currency',
|
||||||
|
current_total if current_total > 0.0 else 0.0)
|
||||||
bja.set('user_remark', 'Total Justworks expenses')
|
bja.set('user_remark', 'Total Justworks expenses')
|
||||||
je.insert()
|
je.insert()
|
||||||
if importer.auto_submit: je.submit()
|
if importer.auto_submit: je.submit()
|
||||||
|
Loading…
Reference in New Issue
Block a user