Skip to content

Commit ae5d6d3

Browse files
authored
Merge branch 'diamoerp-staging' into backport-790-to-diamoerp-staging
2 parents 369fdbe + 1298de1 commit ae5d6d3

File tree

81 files changed

+1490
-393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1490
-393
lines changed

erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py

+45-16
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,29 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
232232

233233
if transaction.unallocated_amount == 0:
234234
frappe.throw(_("This bank transaction is already fully reconciled"))
235-
total_amount = 0
235+
236+
# total_amount = 0
237+
236238
for voucher in vouchers:
237239
voucher['payment_entry'] = frappe.get_doc(voucher['payment_doctype'], voucher['payment_name'])
238-
total_amount += get_paid_amount(frappe._dict({
239-
'payment_document': voucher['payment_doctype'],
240-
'payment_entry': voucher['payment_name'],
241-
}), transaction.currency, company_account)
240+
# total_amount += get_paid_amount(frappe._dict({
241+
# 'payment_document': voucher['payment_doctype'],
242+
# 'payment_entry': voucher['payment_name'],
243+
# }), transaction.currency, company_account)
242244

243-
if total_amount > transaction.unallocated_amount:
244-
frappe.throw(_("The Sum Total of Amounts of All Selected Vouchers Should be Less than the Unallocated Amount of the Bank Transaction"))
245+
# if total_amount > transaction.unallocated_amount:
246+
# frappe.throw(_("The Sum Total of Amounts of All Selected Vouchers Should be Less than the Unallocated Amount of the Bank Transaction"))
245247
account = frappe.db.get_value("Bank Account", transaction.bank_account, "account")
246248

247249
for voucher in vouchers:
248250
gl_entry = frappe.db.get_value("GL Entry", dict(account=account, voucher_type=voucher['payment_doctype'], voucher_no=voucher['payment_name']), ['credit', 'debit'], as_dict=1)
249-
gl_amount, transaction_amount = (gl_entry.credit, transaction.deposit) if gl_entry.credit > 0 else (gl_entry.debit, transaction.withdrawal)
250-
allocated_amount = gl_amount if gl_amount >= transaction_amount else transaction_amount
251+
gl_amount = gl_entry.credit if gl_entry.credit > 0 else gl_entry.debit
252+
transaction_amount = transaction.deposit if transaction.deposit > 0 else transaction.withdrawal
253+
# gl_amount, transaction_amount = (gl_entry.credit, transaction.deposit) if gl_entry.credit > 0 else (gl_entry.debit, transaction.withdrawal)
254+
reconcilied_amount = transaction.get_reconcilied_amount(voucher['payment_entry'].doctype, voucher['payment_entry'].name)
255+
not_reconcilied = round((gl_amount - reconcilied_amount), 2)
256+
# allocated_amount = gl_amount if gl_amount >= transaction_amount else transaction_amount
257+
allocated_amount = not_reconcilied if not_reconcilied <= transaction_amount else transaction_amount
251258

252259
transaction.append("payment_entries", {
253260
"payment_document": voucher['payment_entry'].doctype,
@@ -308,7 +315,7 @@ def check_matching(bank_account, company, transaction, document_types):
308315

309316
def get_queries(bank_account, company, transaction, document_types):
310317
# get queries to get matching vouchers
311-
amount_condition = "=" if "exact_match" in document_types else "<="
318+
amount_condition = "=" if "exact_match" in document_types else None
312319
account_from_to = "paid_to" if transaction.deposit > 0 else "paid_from"
313320
queries = []
314321

@@ -341,6 +348,11 @@ def get_pe_matching_query(amount_condition, account_from_to, transaction):
341348
currency_field = "paid_to_account_currency as currency"
342349
else:
343350
currency_field = "paid_from_account_currency as currency"
351+
352+
amount_filter = "True"
353+
if amount_condition:
354+
amount_filter = f"paid_amount {amount_condition} %(amount)s"
355+
344356
return f"""
345357
SELECT
346358
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
@@ -358,7 +370,7 @@ def get_pe_matching_query(amount_condition, account_from_to, transaction):
358370
FROM
359371
`tabPayment Entry`
360372
WHERE
361-
paid_amount {amount_condition} %(amount)s
373+
{amount_filter}
362374
AND docstatus = 1
363375
AND payment_type IN (%(payment_type)s, 'Internal Transfer')
364376
AND ifnull(clearance_date, '') = ""
@@ -373,8 +385,12 @@ def get_je_matching_query(amount_condition, transaction):
373385
# So one bank could have both types of bank accounts like asset and liability
374386
# So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type
375387
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
376-
return f"""
377388

389+
amount_filter = ""
390+
if amount_condition:
391+
amount_filter = f"AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s"
392+
393+
return f"""
378394
SELECT
379395
(CASE WHEN je.cheque_no=%(reference_no)s THEN 1 ELSE 0 END
380396
+ 1) AS rank ,
@@ -396,13 +412,17 @@ def get_je_matching_query(amount_condition, transaction):
396412
WHERE
397413
(je.clearance_date is null or je.clearance_date='0000-00-00')
398414
AND jea.account = %(bank_account)s
399-
AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s
415+
{amount_filter}
400416
AND je.docstatus = 1
401417
"""
402418

403419

404420
def get_si_matching_query(amount_condition):
405421
# get matchin sales invoice query
422+
amount_filter = ""
423+
if amount_condition:
424+
amount_filter = f"AND sip.amount {amount_condition} %(amount)s"
425+
406426
return f"""
407427
SELECT
408428
( CASE WHEN si.customer = %(party)s THEN 1 ELSE 0 END
@@ -425,12 +445,16 @@ def get_si_matching_query(amount_condition):
425445
sip.parent = si.name
426446
WHERE (sip.clearance_date is null or sip.clearance_date='0000-00-00')
427447
AND sip.account = %(bank_account)s
428-
AND sip.amount {amount_condition} %(amount)s
448+
{amount_filter}
429449
AND si.docstatus = 1
430450
"""
431451

432452
def get_pi_matching_query(amount_condition):
433453
# get matching purchase invoice query
454+
amount_filter = "True"
455+
if amount_condition:
456+
amount_filter = f"paid_amount {amount_condition} %(amount)s"
457+
434458
return f"""
435459
SELECT
436460
( CASE WHEN supplier = %(party)s THEN 1 ELSE 0 END
@@ -447,7 +471,7 @@ def get_pi_matching_query(amount_condition):
447471
FROM
448472
`tabPurchase Invoice`
449473
WHERE
450-
paid_amount {amount_condition} %(amount)s
474+
{amount_filter}
451475
AND docstatus = 1
452476
AND is_paid = 1
453477
AND ifnull(clearance_date, '') = ""
@@ -460,6 +484,11 @@ def get_ec_matching_query(bank_account, company, amount_condition):
460484
filters={"default_account": bank_account}, fields=["parent"])]
461485
mode_of_payments = '(\'' + '\', \''.join(mode_of_payments) + '\' )'
462486
company_currency = get_company_currency(company)
487+
488+
amount_filter = "True"
489+
if amount_condition:
490+
amount_filter = f"total_sanctioned_amount {amount_condition} %(amount)s"
491+
463492
return f"""
464493
SELECT
465494
( CASE WHEN employee = %(party)s THEN 1 ELSE 0 END
@@ -476,7 +505,7 @@ def get_ec_matching_query(bank_account, company, amount_condition):
476505
FROM
477506
`tabExpense Claim`
478507
WHERE
479-
total_sanctioned_amount {amount_condition} %(amount)s
508+
{amount_filter}
480509
AND docstatus = 1
481510
AND is_paid = 1
482511
AND ifnull(clearance_date, '') = ""

erpnext/accounts/doctype/bank_transaction/bank_transaction.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ def clear_simple_entry(self, payment_entry, for_cancel=False):
6363
return
6464

6565
clearance_date = self.date if not for_cancel else None
66-
frappe.db.set_value(
67-
payment_entry.payment_document, payment_entry.payment_entry,
68-
"clearance_date", clearance_date)
66+
67+
gl_entry = frappe.db.get_value("GL Entry", dict(voucher_type=payment_entry.payment_document, voucher_no=payment_entry.payment_entry), ['credit', 'debit'], as_dict=1)
68+
gl_amount = gl_entry.credit if gl_entry.credit > 0 else gl_entry.debit
69+
70+
if self.get_reconcilied_amount(payment_entry.payment_document, payment_entry.payment_entry) >= gl_amount:
71+
frappe.db.set_value(payment_entry.payment_document, payment_entry.payment_entry, "clearance_date", clearance_date)
6972

7073
def clear_sales_invoice(self, payment_entry, for_cancel=False):
7174
clearance_date = self.date if not for_cancel else None
@@ -77,6 +80,25 @@ def clear_sales_invoice(self, payment_entry, for_cancel=False):
7780
),
7881
"clearance_date", clearance_date)
7982

83+
def get_reconcilied_amount(self, payment_document, payment_entry):
84+
if self.withdrawal > 0:
85+
select = "sum(bt.withdrawal) as sum"
86+
else:
87+
select = "sum(bt.deposit) as sum"
88+
89+
amount = frappe.db.sql(f"""
90+
select {select}
91+
from `tabBank Transaction` as bt, `tabBank Transaction Payments` as btp
92+
where bt.name = btp.parent
93+
and btp.payment_entry = '{payment_entry}'
94+
and btp.payment_document = '{payment_document}'
95+
group by btp.payment_entry
96+
""", as_dict=1)
97+
98+
if not len(amount):
99+
return 0
100+
return amount[0]['sum']
101+
80102
def get_reconciled_bank_transactions(payment_entry):
81103
reconciled_bank_transactions = frappe.get_all(
82104
'Bank Transaction Payments',

erpnext/accounts/doctype/cierre_de_caja/cierre_de_caja.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def get_totals(self):
3636
accounts = self.get_accounts(True)
3737
positive_entries_filter = [['creation', '>=', self.period_start_date], ['creation', '<=', self.period_end_date], ['paid_to', 'in', accounts], ['docstatus', '=', '1']]
3838
negative_entries_filter = [['creation', '>=', self.period_start_date], ['creation', '<=', self.period_end_date], ['paid_from', 'in', accounts], ['docstatus', '=', '1']]
39-
positive_payment_entries = frappe.db.get_all("Payment Entry", filters=positive_entries_filter, fields=["total_allocated_amount"])
40-
negative_payment_entries = frappe.db.get_all("Payment Entry", filters=negative_entries_filter, fields=["total_allocated_amount"])
41-
total_cash_cheque = sum(payment_entry['total_allocated_amount'] for payment_entry in positive_payment_entries) + sum(payment_entry['total_allocated_amount'] * -1 for payment_entry in negative_payment_entries)
39+
positive_payment_entries = frappe.db.get_all("Payment Entry", filters=positive_entries_filter, fields=["paid_amount"])
40+
negative_payment_entries = frappe.db.get_all("Payment Entry", filters=negative_entries_filter, fields=["paid_amount"])
41+
total_cash_cheque = sum(payment_entry['paid_amount'] for payment_entry in positive_payment_entries) + sum(payment_entry['paid_amount'] * -1 for payment_entry in negative_payment_entries)
4242
totals['total_cash_cheque'] = total_cash_cheque
4343
return totals
4444

@@ -61,9 +61,9 @@ def get_expected_amount(mode_of_payment, period_start_date, period_end_date, own
6161
account = frappe.db.get_value("Mode of Payment Account", {"parent": mode_of_payment, "company": company}, "default_account")
6262
positive_entries_filter = [['creation', '>=', period_start_date], ['creation', '<=', period_end_date], ['paid_to', '=', account], ['docstatus', '=', '1']]
6363
negative_entries_filter = [['creation', '>=', period_start_date], ['creation', '<=', period_end_date], ['paid_from', '=', account], ['docstatus', '=', '1']]
64-
positive_payment_entries = frappe.db.get_all("Payment Entry", filters=positive_entries_filter, fields=["total_allocated_amount"])
65-
negative_payment_entries = frappe.db.get_all("Payment Entry", filters=negative_entries_filter, fields=["total_allocated_amount"])
66-
return sum(payment_entry['total_allocated_amount'] for payment_entry in positive_payment_entries) + sum(payment_entry['total_allocated_amount'] * -1 for payment_entry in negative_payment_entries)
64+
positive_payment_entries = frappe.db.get_all("Payment Entry", filters=positive_entries_filter, fields=["paid_amount"])
65+
negative_payment_entries = frappe.db.get_all("Payment Entry", filters=negative_entries_filter, fields=["paid_amount"])
66+
return sum(payment_entry['paid_amount'] for payment_entry in positive_payment_entries) + sum(payment_entry['paid_amount'] * -1 for payment_entry in negative_payment_entries)
6767

6868

6969
@frappe.whitelist()

erpnext/accounts/doctype/purchase_invoice/purchase_invoice_dashboard.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_data():
1212
'Payment Request': 'reference_name',
1313
'Landed Cost Voucher': 'receipt_document',
1414
'Purchase Invoice': 'return_against',
15-
'Auto Repeat': 'reference_document'
15+
'Auto Repeat': 'reference_document',
1616
},
1717
'internal_links': {
1818
'Purchase Order': ['items', 'purchase_order'],

erpnext/accounts/doctype/subscription/subscription.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ def cancel_subscription(self):
624624
to_prorate = frappe.db.get_single_value('Subscription Settings', 'prorate')
625625
self.status = 'Cancelled'
626626
self.cancelation_date = nowdate()
627-
if to_generate_invoice:
628-
self.generate_invoice(prorate=to_prorate)
627+
# if to_generate_invoice:
628+
# self.generate_invoice(prorate=to_prorate)
629629
self.save()
630630

631631
def restart_subscription(self):

erpnext/accounts/party.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
6363
currency = party.default_currency if party.get("default_currency") else get_company_currency(company)
6464

6565
party_address, shipping_address = set_address_details(party_details, party, party_type, doctype, company, party_address, company_address, shipping_address)
66-
set_contact_details(party_details, party, party_type)
66+
set_contact_details(party_details, party, party_type, doctype)
6767
set_other_values(party_details, party, party_type)
6868
set_price_list(party_details, party, party_type, price_list, pos_profile)
6969

@@ -134,8 +134,8 @@ def set_address_details(party_details, party, party_type, doctype=None, company=
134134
def get_regional_address_details(party_details, doctype, company):
135135
pass
136136

137-
def set_contact_details(party_details, party, party_type):
138-
party_details.contact_person = get_default_contact(party_type, party.name)
137+
def set_contact_details(party_details, party, party_type, doctype):
138+
party_details.contact_person = get_default_contact(party_type, party.name, doctype)
139139

140140
if not party_details.contact_person:
141141
party_details.update({
@@ -652,11 +652,16 @@ def get_partywise_advanced_payment_amount(party_type, posting_date = None, futur
652652
if data:
653653
return frappe._dict(data)
654654

655-
def get_default_contact(doctype, name):
655+
def get_default_contact(doctype, name, document_doctype=None):
656656
"""
657657
Returns default contact for the given doctype and name.
658658
Can be ordered by `contact_type` to either is_primary_contact or is_billing_contact.
659659
"""
660+
order_by = 'ORDER BY is_primary_contact DESC, is_billing_contact DESC'
661+
662+
if document_doctype and document_doctype in ['Sales Invoice', 'Sales Order', 'Purchase Invoice', 'Purchase Order']:
663+
order_by = 'ORDER BY is_billing_contact DESC, is_primary_contact DESC'
664+
660665
out = frappe.db.sql("""
661666
SELECT dl.parent, c.is_primary_contact, c.is_billing_contact
662667
FROM `tabDynamic Link` dl
@@ -665,8 +670,8 @@ def get_default_contact(doctype, name):
665670
dl.link_doctype=%s AND
666671
dl.link_name=%s AND
667672
dl.parenttype = "Contact"
668-
ORDER BY is_primary_contact DESC, is_billing_contact DESC
669-
""", (doctype, name))
673+
{order_by}
674+
""".format(order_by=order_by), (doctype, name))
670675
if out:
671676
try:
672677
return out[0][0]

erpnext/accounts/report/accounts_receivable/accounts_receivable.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
22
// License: GNU General Public License v3. See license.txt
33

4+
if (frappe.boot.single_types.includes("Persat Settings")) {
5+
var family = {
6+
"fieldname": "familia",
7+
"label": __("Familia"),
8+
"fieldtype": "Link",
9+
"options": "Customer"
10+
}
11+
} else {
12+
var family = {
13+
"fieldname": "familia",
14+
"label": __("Familia"),
15+
"fieldtype": "Link",
16+
"options": "Customer",
17+
"hidden": 1
18+
}
19+
}
420
frappe.query_reports["Accounts Receivable"] = {
521
"filters": [
622
{
@@ -66,6 +82,7 @@ frappe.query_reports["Accounts Receivable"] = {
6682
}
6783
}
6884
},
85+
family,
6986
{
7087
"fieldname": "ageing_based_on",
7188
"label": __("Ageing Based On"),

erpnext/accounts/report/accounts_receivable/accounts_receivable.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ def get_data(self):
9797
def init_voucher_balance(self):
9898
# build all keys, since we want to exclude vouchers beyond the report date
9999
for gle in self.gl_entries:
100+
101+
if frappe.get_hooks('accounts_receivable_family_column') and gle.party_type == 'Customer':
102+
familia = frappe.get_value('Customer', gle.party, 'familia')
103+
else:
104+
familia = None
105+
100106
# get the balance object for voucher_type
101107
key = (gle.voucher_type, gle.voucher_no, gle.party)
102108
if not key in self.voucher_balance:
@@ -114,7 +120,8 @@ def init_voucher_balance(self):
114120
invoiced_in_account_currency = 0.0,
115121
paid_in_account_currency = 0.0,
116122
credit_note_in_account_currency = 0.0,
117-
outstanding_in_account_currency = 0.0
123+
outstanding_in_account_currency = 0.0,
124+
familia = familia
118125
)
119126
self.get_invoices(gle)
120127

@@ -231,7 +238,7 @@ def build_data(self):
231238
row.outstanding_in_account_currency = flt(row.invoiced_in_account_currency - row.paid_in_account_currency - \
232239
row.credit_note_in_account_currency, self.currency_precision)
233240
row.invoice_grand_total = row.invoiced
234-
241+
235242
if frappe.get_hooks('accounts_receivable_usd_column') and row.outstanding != 0.0:
236243
if row['voucher_type'] == "Payment Entry":
237244
currency_field = "paid_to_account_currency"
@@ -736,6 +743,10 @@ def add_customer_filters(self, conditions, values):
736743
conditions.append("party in (select name from tabCustomer where default_sales_partner=%s)")
737744
values.append(self.filters.get("sales_partner"))
738745

746+
if self.filters.get("familia"):
747+
conditions.append("party in (select name from tabCustomer where familia=%s)")
748+
values.append(self.filters.get("familia"))
749+
739750
def add_supplier_filters(self, conditions, values):
740751
if self.filters.get("supplier_group"):
741752
conditions.append("""party in (select name from tabSupplier
@@ -803,6 +814,9 @@ def get_columns(self):
803814
self.add_column(label=_(self.party_type), fieldname='party',
804815
fieldtype='Link', options=self.party_type, width=180)
805816

817+
if frappe.get_hooks('accounts_receivable_family_column') and self.party_type == 'Customer':
818+
self.add_column(_("Familia"), fieldname='familia', fieldtype='Link', options='Customer')
819+
806820
if self.party_naming_by == "Naming Series":
807821
self.add_column(_('{0} Name').format(self.party_type),
808822
fieldname = scrub(self.party_type) + '_name', fieldtype='Data')

erpnext/accounts/report/balance_sheet/balance_sheet.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"filters": [],
1010
"idx": 2,
1111
"is_standard": "Yes",
12-
"modified": "2022-12-06 15:43:22.678305",
12+
"modified": "2022-12-06 16:43:22.678305",
1313
"modified_by": "Administrator",
1414
"module": "Accounts",
1515
"name": "Balance Sheet",
@@ -24,9 +24,6 @@
2424
},
2525
{
2626
"role": "Accounts Manager"
27-
},
28-
{
29-
"role": "Auditor"
3027
}
3128
]
3229
}

0 commit comments

Comments
 (0)