Skip to content

Commit

Permalink
Merge pull request #6 from agritheory/test_setup
Browse files Browse the repository at this point in the history
Test setup
  • Loading branch information
agritheory authored Aug 5, 2022
2 parents 121932a + 219ea34 commit 62363ce
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 154 deletions.
30 changes: 2 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,7 @@ nano site_config.json
"developer_mode": 1
```

Restore the database
Setup demo data or test data
```
mysql -u root -p {{ site name }} < {{data base file path}}.sql
bench execute 'check_run.check_run.doctype.check_run.test_data.create_test_data'
```
Set a new password for the local Administrator that is not the same as the production Administrator password
```
bench set-admin-password {{local password}}
```

Migrate, build and get the site ready
```
bench start
```
In a new terminal window
```
bench update
```
### Testing
#### Running Cypress tests
To set up local Cypress tests;
```bash
cd apps/check_run
yarn
```
Additional steps may be required on WSL, use Nicky's guide:
https://nickymeuleman.netlify.app/blog/gui-on-wsl2-cypress

```bash
yarn run cypress open
```
2 changes: 1 addition & 1 deletion check_run/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__version__ = '0.0.1'
__version__ = '13.0.0'

13 changes: 6 additions & 7 deletions check_run/check_run/doctype/check_run/check_run.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"pay_to_account",
"section_break_9",
"check_run_table",
"html_15",
"transactions",
"amended_from",
"print_count",
Expand All @@ -48,6 +47,7 @@
"allow_on_submit": 1,
"fieldname": "initial_check_number",
"fieldtype": "Int",
"in_list_view": 1,
"label": "Initial Check Number"
},
{
Expand All @@ -74,6 +74,7 @@
"allow_in_quick_entry": 1,
"fieldname": "company",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Company",
"options": "Company",
"remember_last_selected_value": 1,
Expand All @@ -94,6 +95,7 @@
"default": "company.default_payable_account",
"fieldname": "pay_to_account",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Accounts Payable",
"options": "Account",
"remember_last_selected_value": 1,
Expand Down Expand Up @@ -123,6 +125,8 @@
{
"fieldname": "check_run_date",
"fieldtype": "Date",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Check Run Date"
},
{
Expand All @@ -149,16 +153,11 @@
{
"fieldname": "check_run_table",
"fieldtype": "HTML"
},
{
"default": "<span></span>",
"fieldname": "html_15",
"fieldtype": "HTML"
}
],
"is_submittable": 1,
"links": [],
"modified": "2022-07-10 16:16:03.289288",
"modified": "2022-08-03 16:34:50.373207",
"modified_by": "Administrator",
"module": "Check Run",
"name": "Check Run",
Expand Down
33 changes: 12 additions & 21 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 @@ -106,9 +107,8 @@ def ach_only(self):
def create_payment_entries(self, transactions):
check_count = 0
_transactions = []
account_currency = frappe.get_value('Account', self.pay_to_account, 'account_currency')
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 @@ -119,27 +119,23 @@ def create_payment_entries(self, transactions):
pe = frappe.new_doc("Payment Entry")
pe.payment_type = "Pay"
pe.posting_date = nowdate()
project = self.get_dimensions_from_references(group, 'project')
if project != 'None' and project:
pe.project = project
cost_center = self.get_dimensions_from_references(group, 'cost_center')
if cost_center != 'None' and project:
pe.cost_center = cost_center
pe.mode_of_payment = group[0].mode_of_payment
pe.company = self.company
pe.paid_from = gl_account
pe.paid_to = self.pay_to_account
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':
pe.reference_no = int(self.initial_check_number) + check_count
check_count += 1
else:
pe.reference_no = self.name

for reference in group:
if not reference:
continue
Expand All @@ -158,17 +154,15 @@ def create_payment_entries(self, transactions):
pe.base_received_amount = total_amount
pe.paid_amount = total_amount
pe.base_paid_amount = total_amount
pe.paid_from_account_currency = account_currency
pe.paid_to_account_currency = account_currency
pe.target_exchange_rate = 1.0
pe.source_exchange_rate = 1.0
print(pe.as_json())
pe.save()
pe.submit()
for reference in _references:
reference.payment_entry = pe.name
_transactions.append(reference)
return _transactions


def get_dimensions_from_references(self, references, dimension):
dimensions, default_dimensions = get_dimensions(with_cost_center_and_project=True)
parents = [reference.get('name') for reference in references if reference]
Expand Down Expand Up @@ -275,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 @@ -296,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 @@ -311,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
63 changes: 31 additions & 32 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 All @@ -62,8 +62,14 @@
class="mop-onclick"
:data-mop-index="i"
>

<ADropdown ref="dropdowns" v-model="state.transactions[i].mode_of_payment" :items="modeOfPaymentNames" v-if="state.docstatus < 1" :transactionIndex="i" :isOpen="state.transactions[i].mopIsOpen" @isOpenChanged="val => state.transactions[i].mopIsOpen = val"/>
<ADropdown
ref="dropdowns"
v-model="state.transactions[i].mode_of_payment"
:items="modeOfPaymentNames"
v-if="state.docstatus < 1" :transactionIndex="i"
:isOpen="state.transactions[i].mopIsOpen"
@isOpenChanged="val => state.transactions[i].mopIsOpen = val"
/>

<span v-else>{{ transactions[i].mode_of_payment }}</span>
</td>
Expand All @@ -74,13 +80,13 @@
type="checkbox"
class="input-with-feedback checkrun-check-box"
data-fieldtype="Check"
@change="onPayChange()"
@change="onPayChange(i)"
:data-checkbox-index="i"
v-model="item.pay"
: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 @@ -115,63 +121,57 @@ 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()
},
onPayChange() {
onPayChange(selectedRow) {
cur_frm.doc.amount_check_run = cur_frm.check_run_state.check_run_total()
cur_frm.refresh_field("amount_check_run")
this.markDirty()
if(this.transactions[selectedRow].pay && !this.transactions[selectedRow].mode_of_payment){
frappe.show_alert(__('Please add a Mode of Payment for this row'))
}
},
checkPay() {
if(this.state.docstatus >= 1 || !this.transactions.length) {
return
}
this.transactions[this.state.selectedRow].pay = !this.transactions[this.state.selectedRow].pay
this.onPayChange()
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 @@ -193,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)
Loading

0 comments on commit 62363ce

Please sign in to comment.