added bulk edit
This commit is contained in:
parent
6779cf89ec
commit
7be2112e2a
|
|
@ -1447,6 +1447,7 @@ def _build_import_lookups(settings):
|
||||||
cp_name,
|
cp_name,
|
||||||
cp_voen,
|
cp_voen,
|
||||||
getattr(row, "document_type", None) or "Payment Entry",
|
getattr(row, "document_type", None) or "Payment Entry",
|
||||||
|
getattr(row, "cost_center", None) or "",
|
||||||
))
|
))
|
||||||
|
|
||||||
voen_to_party = {}
|
voen_to_party = {}
|
||||||
|
|
@ -1498,7 +1499,7 @@ def _import_one_transaction(txn_data, settings, purpose_rules, purpose_threshold
|
||||||
purpose_only_rules = []
|
purpose_only_rules = []
|
||||||
counterparty_only_rules = []
|
counterparty_only_rules = []
|
||||||
for rule in purpose_rules:
|
for rule in purpose_rules:
|
||||||
keyword, pf, pt, rule_pt, cp_name, cp_voen, doc_type = rule
|
keyword, pf, pt, rule_pt, cp_name, cp_voen, doc_type, rule_cc = rule
|
||||||
has_keyword = bool(keyword)
|
has_keyword = bool(keyword)
|
||||||
has_cp = bool(cp_name or cp_voen)
|
has_cp = bool(cp_name or cp_voen)
|
||||||
if has_keyword and has_cp:
|
if has_keyword and has_cp:
|
||||||
|
|
@ -1517,41 +1518,45 @@ def _import_one_transaction(txn_data, settings, purpose_rules, purpose_threshold
|
||||||
|
|
||||||
def _match_purpose_rules(rules, check_counterparty):
|
def _match_purpose_rules(rules, check_counterparty):
|
||||||
best_score = 0
|
best_score = 0
|
||||||
best_pf = best_pt = best_doc_type = None
|
best_pf = best_pt = best_doc_type = best_cc = None
|
||||||
for keyword, pf, pt, rule_pt, cp_name, cp_voen, doc_type in rules:
|
for keyword, pf, pt, rule_pt, cp_name, cp_voen, doc_type, rule_cc in rules:
|
||||||
if rule_pt and rule_pt != payment_type:
|
if rule_pt and rule_pt != payment_type:
|
||||||
continue
|
continue
|
||||||
if check_counterparty and not _counterparty_matches(cp_name, cp_voen):
|
if check_counterparty and not _counterparty_matches(cp_name, cp_voen):
|
||||||
continue
|
continue
|
||||||
if keyword:
|
if keyword:
|
||||||
if keyword in purpose_lower:
|
if keyword in purpose_lower:
|
||||||
return pf, pt, doc_type
|
return pf, pt, doc_type, rule_cc
|
||||||
score = SequenceMatcher(None, purpose_lower, keyword).ratio()
|
score = SequenceMatcher(None, purpose_lower, keyword).ratio()
|
||||||
if score > best_score and score >= purpose_threshold:
|
if score > best_score and score >= purpose_threshold:
|
||||||
best_score = score
|
best_score = score
|
||||||
best_pf, best_pt, best_doc_type = pf, pt, doc_type
|
best_pf, best_pt, best_doc_type, best_cc = pf, pt, doc_type, rule_cc
|
||||||
else:
|
else:
|
||||||
return pf, pt, doc_type
|
return pf, pt, doc_type, rule_cc
|
||||||
return best_pf, best_pt, best_doc_type
|
return best_pf, best_pt, best_doc_type, best_cc
|
||||||
|
|
||||||
doc_type = "Payment Entry"
|
doc_type = "Payment Entry"
|
||||||
|
cost_center = ""
|
||||||
|
|
||||||
# Phase 1: rules with BOTH purpose keyword AND counterparty
|
# Phase 1: rules with BOTH purpose keyword AND counterparty
|
||||||
paid_from, paid_to, matched_doc_type = _match_purpose_rules(both_rules, check_counterparty=True)
|
paid_from, paid_to, matched_doc_type, matched_cc = _match_purpose_rules(both_rules, check_counterparty=True)
|
||||||
if matched_doc_type:
|
if matched_doc_type:
|
||||||
doc_type = matched_doc_type
|
doc_type = matched_doc_type
|
||||||
|
cost_center = matched_cc or ""
|
||||||
|
|
||||||
# Phase 2: rules with only purpose keyword
|
# Phase 2: rules with only purpose keyword
|
||||||
if not paid_from or not paid_to:
|
if not paid_from or not paid_to:
|
||||||
paid_from, paid_to, matched_doc_type = _match_purpose_rules(purpose_only_rules, check_counterparty=False)
|
paid_from, paid_to, matched_doc_type, matched_cc = _match_purpose_rules(purpose_only_rules, check_counterparty=False)
|
||||||
if matched_doc_type:
|
if matched_doc_type:
|
||||||
doc_type = matched_doc_type
|
doc_type = matched_doc_type
|
||||||
|
cost_center = matched_cc or ""
|
||||||
|
|
||||||
# Phase 3: rules with only counterparty
|
# Phase 3: rules with only counterparty
|
||||||
if not paid_from or not paid_to:
|
if not paid_from or not paid_to:
|
||||||
paid_from, paid_to, matched_doc_type = _match_purpose_rules(counterparty_only_rules, check_counterparty=True)
|
paid_from, paid_to, matched_doc_type, matched_cc = _match_purpose_rules(counterparty_only_rules, check_counterparty=True)
|
||||||
if matched_doc_type:
|
if matched_doc_type:
|
||||||
doc_type = matched_doc_type
|
doc_type = matched_doc_type
|
||||||
|
cost_center = matched_cc or ""
|
||||||
|
|
||||||
if not paid_from or not paid_to:
|
if not paid_from or not paid_to:
|
||||||
return {
|
return {
|
||||||
|
|
@ -1606,18 +1611,24 @@ def _import_one_transaction(txn_data, settings, purpose_rules, purpose_threshold
|
||||||
pf_party = (party_type, erp_party) if pf_type in party_accounts else (None, None)
|
pf_party = (party_type, erp_party) if pf_type in party_accounts else (None, None)
|
||||||
pt_party = (party_type, erp_party) if pt_type in party_accounts else (None, None)
|
pt_party = (party_type, erp_party) if pt_type in party_accounts else (None, None)
|
||||||
|
|
||||||
|
je_row_extra = {}
|
||||||
|
if cost_center:
|
||||||
|
je_row_extra["cost_center"] = cost_center
|
||||||
|
|
||||||
if payment_type == "Pay":
|
if payment_type == "Pay":
|
||||||
je.append("accounts", {
|
je.append("accounts", {
|
||||||
"account": paid_from,
|
"account": paid_from,
|
||||||
"credit_in_account_currency": amount,
|
"credit_in_account_currency": amount,
|
||||||
"party_type": pf_party[0],
|
"party_type": pf_party[0],
|
||||||
"party": pf_party[1],
|
"party": pf_party[1],
|
||||||
|
**je_row_extra,
|
||||||
})
|
})
|
||||||
je.append("accounts", {
|
je.append("accounts", {
|
||||||
"account": paid_to,
|
"account": paid_to,
|
||||||
"debit_in_account_currency": amount,
|
"debit_in_account_currency": amount,
|
||||||
"party_type": pt_party[0],
|
"party_type": pt_party[0],
|
||||||
"party": pt_party[1],
|
"party": pt_party[1],
|
||||||
|
**je_row_extra,
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
je.append("accounts", {
|
je.append("accounts", {
|
||||||
|
|
@ -1625,12 +1636,14 @@ def _import_one_transaction(txn_data, settings, purpose_rules, purpose_threshold
|
||||||
"debit_in_account_currency": amount,
|
"debit_in_account_currency": amount,
|
||||||
"party_type": pf_party[0],
|
"party_type": pf_party[0],
|
||||||
"party": pf_party[1],
|
"party": pf_party[1],
|
||||||
|
**je_row_extra,
|
||||||
})
|
})
|
||||||
je.append("accounts", {
|
je.append("accounts", {
|
||||||
"account": paid_to,
|
"account": paid_to,
|
||||||
"credit_in_account_currency": amount,
|
"credit_in_account_currency": amount,
|
||||||
"party_type": pt_party[0],
|
"party_type": pt_party[0],
|
||||||
"party": pt_party[1],
|
"party": pt_party[1],
|
||||||
|
**je_row_extra,
|
||||||
})
|
})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -1680,6 +1693,8 @@ def _import_one_transaction(txn_data, settings, purpose_rules, purpose_threshold
|
||||||
pe.remarks = purpose
|
pe.remarks = purpose
|
||||||
pe.party_type = party_type
|
pe.party_type = party_type
|
||||||
pe.party = erp_party
|
pe.party = erp_party
|
||||||
|
if cost_center:
|
||||||
|
pe.cost_center = cost_center
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pe.insert(ignore_permissions=True)
|
pe.insert(ignore_permissions=True)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
"column_break_1",
|
"column_break_1",
|
||||||
"paid_from",
|
"paid_from",
|
||||||
"paid_to",
|
"paid_to",
|
||||||
|
"cost_center",
|
||||||
"notes"
|
"notes"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
|
|
@ -69,6 +70,12 @@
|
||||||
"label": "Paid To (Account)",
|
"label": "Paid To (Account)",
|
||||||
"options": "Account"
|
"options": "Account"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "cost_center",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Cost Center",
|
||||||
|
"options": "Cost Center"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "notes",
|
"fieldname": "notes",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue