Skip to content

Commit

Permalink
wip: quick entry improvements, general refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
agritheory committed Aug 3, 2022
1 parent 121932a commit eaf4cfe
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 94 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
24 changes: 8 additions & 16 deletions check_run/check_run/doctype/check_run/check_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ 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):
_group = list(_group)
Expand All @@ -119,16 +118,12 @@ 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'
Expand All @@ -139,36 +134,33 @@ def create_payment_entries(self, transactions):
check_count += 1
else:
pe.reference_no = self.name

for reference in group:
if not reference:
continue
pe.append('references', {
"reference_doctype": reference.doctype,
"reference_name": reference.name or reference.ref_number,
"due_date": reference.get("due_date"),
"outstanding_amount": flt(reference.amount),
"allocated_amount": flt(reference.amount),
"total_amount": flt(reference.amount),
"outstanding_amount": flt(reference.outstanding_amount),
"allocated_amount": flt(reference.outstanding_amount),
"total_amount": flt(reference.outstanding_amount),
})
total_amount += reference.amount
total_amount += reference.outstanding_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
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
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
53 changes: 18 additions & 35 deletions check_run/public/js/check_run/check_run_quick_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ frappe.ui.form.CheckRunQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
init: function (doctype, after_insert) {
this._super(doctype, after_insert)
},
render_dialog: function () {
render_dialog: function() {
this.mandatory = this.get_fields()
this._super()
this.dialog.$wrapper.find('.btn-secondary').hide()
Expand All @@ -23,40 +23,12 @@ frappe.ui.form.CheckRunQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
}
}
}
frappe.db.get_value('Bank Account', {
company: frappe.defaults.get_default('company'),
is_default: 1,
is_company_account: 1
}, 'name')
.then(r => {
this.dialog.fields_dict["bank_account"].set_value(r.message.name)
})
frappe.db.get_value('Company', {
name: frappe.defaults.get_default('company'),
}, 'default_payable_account')
.then(r => {
this.dialog.fields_dict["pay_to_account"].set_value(r.message.default_payable_account)
})
this.dialog.fields_dict["company"].df.onchange = () => {
const values = dialog.get_values()
if(!values.company){ return }
frappe.db.get_value('Bank Account', {
company: values.company,
is_default: 1,
is_company_account: 1
}, 'name')
.then(r => {
this.dialog.fields_dict["bank_account"].set_value(r.message.name)
})
frappe.db.get_value('Company', {
company: values.company,
}, 'default_payable_account')
.then(r => {
this.dialog.fields_dict["pay_to_account"].set_value(r.message.default_payable_account)
})
this.default_accounts()
}
this.default_accounts()
},
get_fields: () => {
get_fields: function() {
return [
{
label: __("Company"),
Expand All @@ -66,7 +38,7 @@ frappe.ui.form.CheckRunQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
reqd: 1,
},
{
label: __("Paid From (Bank Account)"),
label: __("Paid From (Bank Account"),
fieldname: "bank_account",
fieldtype: "Link",
options: "Bank Account",
Expand All @@ -84,12 +56,23 @@ frappe.ui.form.CheckRunQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
register_primary_action: function() {
const me = this
this.dialog.set_primary_action(__('Start Check Run'), () => {
const values = me.dialog.get_values()
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, payable_account: values.pay_to_account }
{ company: values.company, bank_account: values.bank_account }
).then(r => {
frappe.set_route("Form", "Check Run", r)
})
})
},
default_accounts: function() {
let company = this.dialog.fields_dict.company.get_value()
frappe.db.get_value('Company', company, 'default_payable_account')
.then(r => {
this.dialog.fields_dict["pay_to_account"].set_value(r.message.default_payable_account)
})
frappe.db.get_value('Bank Account', {company: company, is_default: 1, is_company_account: 1}, 'name')
.then(r => {
this.dialog.fields_dict["bank_account"].set_value(r.message.name)
})
}
})
40 changes: 33 additions & 7 deletions check_run/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ 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():
Expand All @@ -61,9 +62,26 @@ def create_test_data():
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),
'company': frappe.defaults.get_defaults().get('company'),
'company_account': frappe.get_value("Account",
{"account_type": "Bank", "company": frappe.defaults.get_defaults().get('company'), "is_group": 0}),
})
create_bank_and_bank_account(settings)
create_suppliers(settings)
create_items(settings)
create_invoices(settings)
config_expense_claim(settings)
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():
def create_bank_and_bank_account(settings):
if not frappe.db.exists('Mode of Payment', 'ACH/EFT'):
mop = frappe.new_doc('Mode of Payment')
mop.mode_of_payment = 'ACH/EFT'
Expand Down Expand Up @@ -94,12 +112,16 @@ def create_bank_and_bank_account():
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()

def create_suppliers():
def create_suppliers(settings):
for supplier in suppliers + tax_authority:
biz = frappe.new_doc("Supplier")
biz.supplier_name = supplier[0]
Expand All @@ -110,7 +132,7 @@ def create_suppliers():
biz.default_price_list = "Standard Buying"
biz.save()

def create_items():
def create_items(settings):
for supplier in suppliers + tax_authority:
item = frappe.new_doc("Item")
item.item_code = item.item_name = supplier[1]
Expand All @@ -124,7 +146,7 @@ def create_items():
item.append("item_defaults", {"company": settings.company, "default_warehouse": "", "default_supplier": supplier[0]})
item.save()

def create_invoices():
def create_invoices(settings):
# first month - already paid
for supplier in suppliers:
pi = frappe.new_doc('Purchase Invoice')
Expand Down Expand Up @@ -183,7 +205,7 @@ def create_invoices():
pi.submit()


def config_expense_claim():
def config_expense_claim(settings):
try:
travel_expense_account = frappe.get_value('Account', {'account_name': 'Travel Expenses', 'company': settings.company})
travel = frappe.get_doc('Expense Claim Type', 'Travel')
Expand All @@ -203,7 +225,7 @@ def config_expense_claim():
pta.save()


def create_employees():
def create_employees(settings):
for employee_number in range(1, 13):
emp = frappe.new_doc('Employee')
emp.first_name = "Test"
Expand All @@ -222,7 +244,7 @@ def create_employees():
emp.save()


def create_expense_claim():
def create_expense_claim(settings):
# first month - paid
ec = frappe.new_doc('Expense Claim')
ec.employee = "Test Employee 2"
Expand Down Expand Up @@ -272,7 +294,11 @@ def create_expense_claim():
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

0 comments on commit eaf4cfe

Please sign in to comment.