Skip to content

Commit

Permalink
wip: testing and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
agritheory committed Aug 5, 2022
1 parent ba6029a commit 219ea34
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 75 deletions.
25 changes: 12 additions & 13 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def ach_only(self):
ach_only.ach_only = False
ach_only.print_checks_only = False
return ach_only
# TODO: refactor to use bank flag on MoPs
if any([t.get('mode_of_payment') == 'Check' for t in transactions]):
ach_only.ach_only = False
if any([t.get('mode_of_payment') in ('ACH/EFT', 'ECheck') for t in transactions]):
Expand All @@ -107,7 +108,7 @@ def create_payment_entries(self, transactions):
check_count = 0
_transactions = []
gl_account = frappe.get_value('Bank Account', self.bank_account, 'account')
for party_ref, _group in groupby(transactions, key=lambda x: x.party_ref):
for party, _group in groupby(transactions, key=lambda x: x.party):
_group = list(_group)
# split checks in groups of 5 if first reference is a check
groups = list(zip_longest(*[iter(_group)] * 5)) if _group[0].mode_of_payment == 'Check' else [_group]
Expand All @@ -125,8 +126,8 @@ def create_payment_entries(self, transactions):
pe.paid_to_account_currency = frappe.db.get_value("Account", self.bank_account, "account_currency")
pe.paid_from_account_currency = pe.paid_to_account_currency
pe.reference_date = self.check_run_date
pe.party = party_ref
pe.party_type = 'Supplier' if group[0].doctype == 'Purchase Invoice' else 'Employee'
pe.party_type = group[0].party_type
pe.party = group[0].party
pe.check_run = self.name
total_amount = 0
if pe.mode_of_payment == 'Check':
Expand All @@ -142,17 +143,18 @@ def create_payment_entries(self, transactions):
"reference_doctype": reference.doctype,
"reference_name": reference.name or reference.ref_number,
"due_date": reference.get("due_date"),
"outstanding_amount": flt(reference.outstanding_amount),
"allocated_amount": flt(reference.outstanding_amount),
"total_amount": flt(reference.outstanding_amount),
"outstanding_amount": flt(reference.amount),
"allocated_amount": flt(reference.amount),
"total_amount": flt(reference.amount),
})
total_amount += reference.outstanding_amount
total_amount += reference.amount
reference.check_number = pe.reference_no
_references.append(reference)
pe.received_amount = total_amount
pe.base_received_amount = total_amount
pe.paid_amount = total_amount
pe.base_paid_amount = total_amount
print(pe.as_json())
pe.save()
pe.submit()
for reference in _references:
Expand Down Expand Up @@ -267,7 +269,6 @@ def get_entries(doc):
`tabPurchase Invoice`.name,
`tabPurchase Invoice`.bill_no AS ref_number,
`tabPurchase Invoice`.supplier_name AS party,
`tabPurchase Invoice`.supplier AS party_ref,
`tabPurchase Invoice`.outstanding_amount AS amount,
`tabPurchase Invoice`.due_date,
`tabPurchase Invoice`.posting_date,
Expand All @@ -288,7 +289,6 @@ def get_entries(doc):
`tabExpense Claim`.name,
`tabExpense Claim`.name AS ref_number,
`tabExpense Claim`.employee_name AS party,
`tabExpense Claim`.employee AS party_ref,
`tabExpense Claim`.grand_total AS amount,
`tabExpense Claim`.posting_date AS due_date,
`tabExpense Claim`.posting_date,
Expand All @@ -303,13 +303,12 @@ def get_entries(doc):
UNION (
SELECT
'Journal Entry' AS doctype,
`tabJournal Entry Account`.party_type,
`tabJournal Entry`.name,
`tabJournal Entry`.name AS ref_number,
`tabJournal Entry Account`.party AS party,
`tabJournal Entry Account`.party AS party_ref,
`tabJournal Entry Account`.party_type,
`tabJournal Entry Account`.party,
`tabJournal Entry Account`.credit_in_account_currency AS amount,
`tabJournal Entry`.due_date AS due_date,
`tabJournal Entry`.due_date,
`tabJournal Entry`.posting_date,
COALESCE(`tabJournal Entry`.mode_of_payment, '\n') AS mode_of_payment
FROM `tabJournal Entry`, `tabJournal Entry Account`
Expand Down
43 changes: 16 additions & 27 deletions check_run/public/js/check_run/CheckRun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<td style="text-align: left">{{ item.party }}</td>
<td>
<a
:href="transactionUrl(i)"
:href="transactionUrl(item)"
target="_blank"
>
{{ item.ref_number || item.name}}
Expand Down Expand Up @@ -86,7 +86,7 @@
:id="item.id" />Pay
</td>
<td v-else>
<a :href="paymentEntryUrl(i)" target="_blank">
<a :href="paymentEntryUrl(item)" target="_blank">
{{ item.check_number }}</a></td>
</tr>
</template>
Expand Down Expand Up @@ -121,32 +121,27 @@ export default {
cur_frm.check_run_state.transactions.forEach(row => { row.pay = val })
cur_frm.doc.amount_check_run = cur_frm.check_run_state.check_run_total()
cur_frm.refresh_field("amount_check_run")
cur_frm.dirty();
cur_frm.dirty()
}
},
methods: {
transactionUrl: transactionId => {
if(!this.transactions) {
return ""
}
return encodeURI(frappe.urllib.get_base_url() + "/app/" + this.transactions[transactionId].doctype.toLowerCase().replace(" ", "-") + "/" + this.transactions[transactionId].name)
transactionUrl: transaction => {
return encodeURI(`${frappe.urllib.get_base_url()}/app/${transaction.doctype.toLowerCase().replace(" ", "-")}/${transaction.name}`)
},
paymentEntryUrl: transactionId => {
if(!this.transactions) {
return "";
}
return encodeURI(frappe.urllib.get_base_url() + "/app/payment-entry/" + this.transactions[i].payment_entry );
paymentEntryUrl: transaction => {
if(transaction.payment_entry) { return "" }
return encodeURI(`${frappe.urllib.get_base_url()}/app/payment-entry/${transaction.payment_entry}`)
},
sortTransactions(key) {
this.transactions.sort((a, b) => (a[key] > b[key] ? this.sort_order[key] : this.sort_order[key] * -1));
this.sort_order[key] *= -1;
this.transactions.sort((a, b) => (a[key] > b[key] ? this.sort_order[key] : this.sort_order[key] * -1))
this.sort_order[key] *= -1
},
partyIsInFilter(party) {
return cur_frm.check_run_state.party_filter.length < 1 || party.toLowerCase().includes(cur_frm.check_run_state.party_filter.toLowerCase());
return cur_frm.check_run_state.party_filter.length < 1 || party.toLowerCase().includes(cur_frm.check_run_state.party_filter.toLowerCase())
},
toggleShowPartyFilter() {
cur_frm.check_run_state.party_filter = "";
cur_frm.check_run_state.show_party_filter = !cur_frm.check_run_state.show_party_filter;
cur_frm.check_run_state.party_filter = ""
cur_frm.check_run_state.show_party_filter = !cur_frm.check_run_state.show_party_filter
},
markDirty() {
cur_frm.dirty()
Expand All @@ -155,7 +150,6 @@ export default {
cur_frm.doc.amount_check_run = cur_frm.check_run_state.check_run_total()
cur_frm.refresh_field("amount_check_run")
this.markDirty()
console.log(this.transactions[selectedRow].pay == true)
if(this.transactions[selectedRow].pay && !this.transactions[selectedRow].mode_of_payment){
frappe.show_alert(__('Please add a Mode of Payment for this row'))
}
Expand All @@ -168,20 +162,16 @@ export default {
this.onPayChange(this.state.selectedRow)
},
openMopWithSearch(keycode) {
if(!this.transactions.length) {
return
}
this.$refs.dropdowns[this.state.selectedRow].openWithSearch()
}
},
beforeMount() {
let amountInCheckRun = 0.0
this.moment = moment;
this.format_currency = format_currency;
cur_frm.check_run_component = this;
this.moment = moment
this.format_currency = format_currency
cur_frm.check_run_component = this
}
}
</script>
Expand All @@ -203,5 +193,4 @@ export default {
.table tr.selectedRow {
background-color: var(--yellow-highlight-color);
}
</style>
10 changes: 5 additions & 5 deletions check_run/public/js/check_run/check_run.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ check_run.mount_table = frm => {
show_party_filter: false,
check_run_total: function() {
return this.transactions.reduce((partialSum, t) => {
return t.pay ? partialSum + t.amount : partialSum;
return t.pay ? partialSum + t.amount : partialSum
}, 0);
},
selectedRow: 0,
mopsOpen: 0
})
if (frm.$check_run instanceof Vue) {
frm.$check_run.$destroy();
frm.$check_run.$destroy()
}
$('#check-run-vue').remove()
$(frm.fields_dict['check_run_table'].wrapper).html($("<div id='check-run-vue'></div>").get(0));
Expand Down Expand Up @@ -71,7 +71,7 @@ check_run.keyDownHandler = e => {
if(e.keyCode == 32 && check_run.frm.check_run_state.selectedRow != null && check_run.frm.check_run_state.transactions.length){
e.preventDefault()
if(check_run.frm.check_run_component) {
check_run.frm.check_run_component.checkPay();
check_run.frm.check_run_component.checkPay()
}
}

Expand All @@ -81,5 +81,5 @@ check_run.keyDownHandler = e => {

}

window.removeEventListener('keydown', check_run.keyDownHandler);
window.addEventListener('keydown', check_run.keyDownHandler);
window.removeEventListener('keydown', check_run.keyDownHandler)
window.addEventListener('keydown', check_run.keyDownHandler)
2 changes: 1 addition & 1 deletion check_run/public/js/check_run/check_run_quick_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ frappe.ui.form.CheckRunQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
this.dialog.set_primary_action(__('Start Check Run'), () => {
let values = me.dialog.get_values()
frappe.xcall("check_run.check_run.doctype.check_run.check_run.check_for_draft_check_run",
{ company: values.company, bank_account: values.bank_account }
{ company: values.company, bank_account: values.bank_account, payable_account: values.pay_to_account }
).then(r => {
frappe.set_route("Form", "Check Run", r)
})
Expand Down
31 changes: 2 additions & 29 deletions check_run/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@ def before_test():
("Local Tax Authority", "Payroll Taxes", "Check", 0.00),
]

<<<<<<< Updated upstream:check_run/test_setup.py
settings = frappe._dict({})

def create_test_data():
settings.day = datetime.date(int(frappe.defaults.get_defaults().get('fiscal_year')), 1 ,1)
settings.company = frappe.defaults.get_defaults().get('company')
company_account = frappe.get_value("Account", {"account_type": "Bank", "company": settings.company, "is_group": 0})
settings.company_account = update_account_number(company_account, 'Primary Checking', account_number="1201", from_descendant=False)
payroll_account = frappe.get_value('Account', {'account_name': 'Payroll Payable'})
frappe.db.set_value('Account', payroll_account, 'account_type', 'Payable')
create_bank_and_bank_account()
create_suppliers()
create_items()
create_invoices()
config_expense_claim()
create_employees()
create_expense_claim()
create_payroll_journal_entry()
=======
def create_test_data():
settings = frappe._dict({
'day': datetime.date(int(frappe.defaults.get_defaults().get('fiscal_year')), 1 ,1),
Expand All @@ -78,7 +59,6 @@ def create_test_data():
create_employees(settings)
create_expense_claim(settings)
create_payroll_journal_entry(settings)
>>>>>>> Stashed changes:check_run/check_run/doctype/check_run/test_data.py


def create_bank_and_bank_account(settings):
Expand Down Expand Up @@ -112,11 +92,7 @@ def create_bank_and_bank_account(settings):
doc.company = settings.company
opening_balance = 10000.00
doc.append("accounts", {"account": settings.company_account, "debit_in_account_currency": opening_balance})
<<<<<<< Updated upstream:check_run/test_setup.py
retained_earnings = frappe.get_value('Account', {'account_name': "Retained Earnings"})
=======
retained_earnings = frappe.get_value('Account', {'account_name': "Retained Earnings", 'company': settings.company})
>>>>>>> Stashed changes:check_run/check_run/doctype/check_run/test_data.py
doc.append("accounts", {"account": retained_earnings, "credit_in_account_currency": opening_balance})
doc.save()
doc.submit()
Expand Down Expand Up @@ -294,11 +270,7 @@ def create_expense_claim(settings):
ec.submit()


<<<<<<< Updated upstream:check_run/test_setup.py
def create_payroll_journal_entry():
=======
def create_payroll_journal_entry(settings):
>>>>>>> Stashed changes:check_run/check_run/doctype/check_run/test_data.py
emps = frappe.get_list('Employee', {'company': settings.company})
cost_center = frappe.get_value('Company', settings.company, 'cost_center')
payroll_account = frappe.get_value('Account', {'company': settings.company, 'account_name': 'Payroll Payable', 'is_group': 0})
Expand Down Expand Up @@ -359,4 +331,5 @@ def create_payroll_journal_entry(settings):
'debit_in_account_currency': 0.0,
})
je.save()
je.submit()
je.submit()

0 comments on commit 219ea34

Please sign in to comment.