Skip to content

Commit

Permalink
Merge pull request #792 from fproldan/diamoerp-staging
Browse files Browse the repository at this point in the history
Release 1.8
  • Loading branch information
fproldan authored Aug 31, 2023
2 parents 15b78a2 + f19825e commit 237e379
Show file tree
Hide file tree
Showing 71 changed files with 1,461 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,29 @@ def reconcile_vouchers(bank_transaction_name, vouchers):

if transaction.unallocated_amount == 0:
frappe.throw(_("This bank transaction is already fully reconciled"))
total_amount = 0

# total_amount = 0

for voucher in vouchers:
voucher['payment_entry'] = frappe.get_doc(voucher['payment_doctype'], voucher['payment_name'])
total_amount += get_paid_amount(frappe._dict({
'payment_document': voucher['payment_doctype'],
'payment_entry': voucher['payment_name'],
}), transaction.currency, company_account)
# total_amount += get_paid_amount(frappe._dict({
# 'payment_document': voucher['payment_doctype'],
# 'payment_entry': voucher['payment_name'],
# }), transaction.currency, company_account)

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

for voucher in vouchers:
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)
gl_amount, transaction_amount = (gl_entry.credit, transaction.deposit) if gl_entry.credit > 0 else (gl_entry.debit, transaction.withdrawal)
allocated_amount = gl_amount if gl_amount >= transaction_amount else transaction_amount
gl_amount = gl_entry.credit if gl_entry.credit > 0 else gl_entry.debit
transaction_amount = transaction.deposit if transaction.deposit > 0 else transaction.withdrawal
# gl_amount, transaction_amount = (gl_entry.credit, transaction.deposit) if gl_entry.credit > 0 else (gl_entry.debit, transaction.withdrawal)
reconcilied_amount = transaction.get_reconcilied_amount(voucher['payment_entry'].doctype, voucher['payment_entry'].name)
not_reconcilied = round((gl_amount - reconcilied_amount), 2)
# allocated_amount = gl_amount if gl_amount >= transaction_amount else transaction_amount
allocated_amount = not_reconcilied if not_reconcilied <= transaction_amount else transaction_amount

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

def get_queries(bank_account, company, transaction, document_types):
# get queries to get matching vouchers
amount_condition = "=" if "exact_match" in document_types else "<="
amount_condition = "=" if "exact_match" in document_types else None
account_from_to = "paid_to" if transaction.deposit > 0 else "paid_from"
queries = []

Expand Down Expand Up @@ -341,6 +348,11 @@ def get_pe_matching_query(amount_condition, account_from_to, transaction):
currency_field = "paid_to_account_currency as currency"
else:
currency_field = "paid_from_account_currency as currency"

amount_filter = "True"
if amount_condition:
amount_filter = f"paid_amount {amount_condition} %(amount)s"

return f"""
SELECT
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
Expand All @@ -358,7 +370,7 @@ def get_pe_matching_query(amount_condition, account_from_to, transaction):
FROM
`tabPayment Entry`
WHERE
paid_amount {amount_condition} %(amount)s
{amount_filter}
AND docstatus = 1
AND payment_type IN (%(payment_type)s, 'Internal Transfer')
AND ifnull(clearance_date, '') = ""
Expand All @@ -373,8 +385,12 @@ def get_je_matching_query(amount_condition, transaction):
# So one bank could have both types of bank accounts like asset and liability
# So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
return f"""

amount_filter = ""
if amount_condition:
amount_filter = f"AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s"

return f"""
SELECT
(CASE WHEN je.cheque_no=%(reference_no)s THEN 1 ELSE 0 END
+ 1) AS rank ,
Expand All @@ -396,13 +412,17 @@ def get_je_matching_query(amount_condition, transaction):
WHERE
(je.clearance_date is null or je.clearance_date='0000-00-00')
AND jea.account = %(bank_account)s
AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s
{amount_filter}
AND je.docstatus = 1
"""


def get_si_matching_query(amount_condition):
# get matchin sales invoice query
amount_filter = ""
if amount_condition:
amount_filter = f"AND sip.amount {amount_condition} %(amount)s"

return f"""
SELECT
( CASE WHEN si.customer = %(party)s THEN 1 ELSE 0 END
Expand All @@ -425,12 +445,16 @@ def get_si_matching_query(amount_condition):
sip.parent = si.name
WHERE (sip.clearance_date is null or sip.clearance_date='0000-00-00')
AND sip.account = %(bank_account)s
AND sip.amount {amount_condition} %(amount)s
{amount_filter}
AND si.docstatus = 1
"""

def get_pi_matching_query(amount_condition):
# get matching purchase invoice query
amount_filter = "True"
if amount_condition:
amount_filter = f"paid_amount {amount_condition} %(amount)s"

return f"""
SELECT
( CASE WHEN supplier = %(party)s THEN 1 ELSE 0 END
Expand All @@ -447,7 +471,7 @@ def get_pi_matching_query(amount_condition):
FROM
`tabPurchase Invoice`
WHERE
paid_amount {amount_condition} %(amount)s
{amount_filter}
AND docstatus = 1
AND is_paid = 1
AND ifnull(clearance_date, '') = ""
Expand All @@ -460,6 +484,11 @@ def get_ec_matching_query(bank_account, company, amount_condition):
filters={"default_account": bank_account}, fields=["parent"])]
mode_of_payments = '(\'' + '\', \''.join(mode_of_payments) + '\' )'
company_currency = get_company_currency(company)

amount_filter = "True"
if amount_condition:
amount_filter = f"total_sanctioned_amount {amount_condition} %(amount)s"

return f"""
SELECT
( CASE WHEN employee = %(party)s THEN 1 ELSE 0 END
Expand All @@ -476,7 +505,7 @@ def get_ec_matching_query(bank_account, company, amount_condition):
FROM
`tabExpense Claim`
WHERE
total_sanctioned_amount {amount_condition} %(amount)s
{amount_filter}
AND docstatus = 1
AND is_paid = 1
AND ifnull(clearance_date, '') = ""
Expand Down
28 changes: 25 additions & 3 deletions erpnext/accounts/doctype/bank_transaction/bank_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ def clear_simple_entry(self, payment_entry, for_cancel=False):
return

clearance_date = self.date if not for_cancel else None
frappe.db.set_value(
payment_entry.payment_document, payment_entry.payment_entry,
"clearance_date", clearance_date)

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)
gl_amount = gl_entry.credit if gl_entry.credit > 0 else gl_entry.debit

if self.get_reconcilied_amount(payment_entry.payment_document, payment_entry.payment_entry) >= gl_amount:
frappe.db.set_value(payment_entry.payment_document, payment_entry.payment_entry, "clearance_date", clearance_date)

def clear_sales_invoice(self, payment_entry, for_cancel=False):
clearance_date = self.date if not for_cancel else None
Expand All @@ -77,6 +80,25 @@ def clear_sales_invoice(self, payment_entry, for_cancel=False):
),
"clearance_date", clearance_date)

def get_reconcilied_amount(self, payment_document, payment_entry):
if self.withdrawal > 0:
select = "sum(bt.withdrawal) as sum"
else:
select = "sum(bt.deposit) as sum"

amount = frappe.db.sql(f"""
select {select}
from `tabBank Transaction` as bt, `tabBank Transaction Payments` as btp
where bt.name = btp.parent
and btp.payment_entry = '{payment_entry}'
and btp.payment_document = '{payment_document}'
group by btp.payment_entry
""", as_dict=1)

if not len(amount):
return 0
return amount[0]['sum']

def get_reconciled_bank_transactions(payment_entry):
reconciled_bank_transactions = frappe.get_all(
'Bank Transaction Payments',
Expand Down
17 changes: 11 additions & 6 deletions erpnext/accounts/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
currency = party.default_currency if party.get("default_currency") else get_company_currency(company)

party_address, shipping_address = set_address_details(party_details, party, party_type, doctype, company, party_address, company_address, shipping_address)
set_contact_details(party_details, party, party_type)
set_contact_details(party_details, party, party_type, doctype)
set_other_values(party_details, party, party_type)
set_price_list(party_details, party, party_type, price_list, pos_profile)

Expand Down Expand Up @@ -134,8 +134,8 @@ def set_address_details(party_details, party, party_type, doctype=None, company=
def get_regional_address_details(party_details, doctype, company):
pass

def set_contact_details(party_details, party, party_type):
party_details.contact_person = get_default_contact(party_type, party.name)
def set_contact_details(party_details, party, party_type, doctype):
party_details.contact_person = get_default_contact(party_type, party.name, doctype)

if not party_details.contact_person:
party_details.update({
Expand Down Expand Up @@ -652,11 +652,16 @@ def get_partywise_advanced_payment_amount(party_type, posting_date = None, futur
if data:
return frappe._dict(data)

def get_default_contact(doctype, name):
def get_default_contact(doctype, name, document_doctype=None):
"""
Returns default contact for the given doctype and name.
Can be ordered by `contact_type` to either is_primary_contact or is_billing_contact.
"""
order_by = 'ORDER BY is_primary_contact DESC, is_billing_contact DESC'

if document_doctype and document_doctype in ['Sales Invoice', 'Sales Order', 'Purchase Invoice', 'Purchase Order']:
order_by = 'ORDER BY is_billing_contact DESC, is_primary_contact DESC'

out = frappe.db.sql("""
SELECT dl.parent, c.is_primary_contact, c.is_billing_contact
FROM `tabDynamic Link` dl
Expand All @@ -665,8 +670,8 @@ def get_default_contact(doctype, name):
dl.link_doctype=%s AND
dl.link_name=%s AND
dl.parenttype = "Contact"
ORDER BY is_primary_contact DESC, is_billing_contact DESC
""", (doctype, name))
{order_by}
""".format(order_by=order_by), (doctype, name))
if out:
try:
return out[0][0]
Expand Down
17 changes: 17 additions & 0 deletions erpnext/accounts/report/accounts_receivable/accounts_receivable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt

if (frappe.boot.single_types.includes("Persat Settings")) {
var family = {
"fieldname": "familia",
"label": __("Familia"),
"fieldtype": "Link",
"options": "Customer"
}
} else {
var family = {
"fieldname": "familia",
"label": __("Familia"),
"fieldtype": "Link",
"options": "Customer",
"hidden": 1
}
}
frappe.query_reports["Accounts Receivable"] = {
"filters": [
{
Expand Down Expand Up @@ -66,6 +82,7 @@ frappe.query_reports["Accounts Receivable"] = {
}
}
},
family,
{
"fieldname": "ageing_based_on",
"label": __("Ageing Based On"),
Expand Down
18 changes: 16 additions & 2 deletions erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def get_data(self):
def init_voucher_balance(self):
# build all keys, since we want to exclude vouchers beyond the report date
for gle in self.gl_entries:

if frappe.get_hooks('accounts_receivable_family_column') and gle.party_type == 'Customer':
familia = frappe.get_value('Customer', gle.party, 'familia')
else:
familia = None

# get the balance object for voucher_type
key = (gle.voucher_type, gle.voucher_no, gle.party)
if not key in self.voucher_balance:
Expand All @@ -114,7 +120,8 @@ def init_voucher_balance(self):
invoiced_in_account_currency = 0.0,
paid_in_account_currency = 0.0,
credit_note_in_account_currency = 0.0,
outstanding_in_account_currency = 0.0
outstanding_in_account_currency = 0.0,
familia = familia
)
self.get_invoices(gle)

Expand Down Expand Up @@ -231,7 +238,7 @@ def build_data(self):
row.outstanding_in_account_currency = flt(row.invoiced_in_account_currency - row.paid_in_account_currency - \
row.credit_note_in_account_currency, self.currency_precision)
row.invoice_grand_total = row.invoiced

if frappe.get_hooks('accounts_receivable_usd_column') and row.outstanding != 0.0:
if row['voucher_type'] == "Payment Entry":
currency_field = "paid_to_account_currency"
Expand Down Expand Up @@ -736,6 +743,10 @@ def add_customer_filters(self, conditions, values):
conditions.append("party in (select name from tabCustomer where default_sales_partner=%s)")
values.append(self.filters.get("sales_partner"))

if self.filters.get("familia"):
conditions.append("party in (select name from tabCustomer where familia=%s)")
values.append(self.filters.get("familia"))

def add_supplier_filters(self, conditions, values):
if self.filters.get("supplier_group"):
conditions.append("""party in (select name from tabSupplier
Expand Down Expand Up @@ -803,6 +814,9 @@ def get_columns(self):
self.add_column(label=_(self.party_type), fieldname='party',
fieldtype='Link', options=self.party_type, width=180)

if frappe.get_hooks('accounts_receivable_family_column') and self.party_type == 'Customer':
self.add_column(_("Familia"), fieldname='familia', fieldtype='Link', options='Customer')

if self.party_naming_by == "Naming Series":
self.add_column(_('{0} Name').format(self.party_type),
fieldname = scrub(self.party_type) + '_name', fieldtype='Data')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

data = {
'modules': [
'HR Asistencia y Vacaciones'
'HR Asistencia, Vacaciones y Rendimiento de Gastos'
],
}
7 changes: 0 additions & 7 deletions erpnext/domains/hr_reclutamiento_capacitacion_gastos.py

This file was deleted.

5 changes: 2 additions & 3 deletions erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@
'RMA': 'erpnext.domains.rma',
'Retail Avanzado': 'erpnext.domains.retail_avanzado',
'Servicios Google': 'erpnext.domains.servicios_google',
'HR Asistencia y Vacaciones': 'erpnext.domains.hr_asistencia_vacaciones',
'HR Reclutamiento, Capacitacion y Gastos': 'erpnext.domains.hr_reclutamiento_capacitacion_gastos',
'Build': 'erpnext.domains.build',
'Pagos360': 'erpnext.domains.pagos360',
'Mercadolibre': 'erpnext.domains.mercadolibre',
Expand All @@ -128,7 +126,8 @@
'Compreahora': 'erpnext.domains.compreahora',
'Usuario de Ventas Reducido': 'erpnext.domains.usuario_ventas_reducido',
'Usuario de Soporte Reducido': 'erpnext.domains.usuario_soporte_reducido',
'Usuario de Proyecto Reducido':'erpnext.domains.usuario_proyecto_reducido',
'Usuario de Proyecto Reducido': 'erpnext.domains.usuario_proyecto_reducido',
'HR Asistencia, Vacaciones y Rendimiento de Gastos': 'erpnext.domains.hr_asistencia_vacaciones_rendimiento_gastos',
}

website_generators = ["Item Group", "Website Item", "BOM", "Sales Partner",
Expand Down
4 changes: 2 additions & 2 deletions erpnext/hr/doctype/appraisal/appraisal.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2021-05-12 20:01:58.902166",
"modified": "2021-05-12 21:01:58.902166",
"modified_by": "Administrator",
"module": "HR",
"name": "Appraisal",
Expand Down Expand Up @@ -246,7 +246,7 @@
"write": 1
}
],
"restrict_to_domain": "HR Reclutamiento, Capacitacion y Gastos",
"restrict_to_domain": "HR Asistencia, Vacaciones y Rendimiento de Gastos",
"search_fields": "status, employee, employee_name",
"sort_field": "modified",
"sort_order": "DESC",
Expand Down
4 changes: 2 additions & 2 deletions erpnext/hr/doctype/appraisal_template/appraisal_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"icon": "icon-file-text",
"idx": 1,
"links": [],
"modified": "2021-05-12 20:01:59.271381",
"modified": "2021-05-12 21:01:59.271381",
"modified_by": "Administrator",
"module": "HR",
"name": "Appraisal Template",
Expand All @@ -67,7 +67,7 @@
"role": "Employee"
}
],
"restrict_to_domain": "HR Reclutamiento, Capacitacion y Gastos",
"restrict_to_domain": "HR Asistencia, Vacaciones y Rendimiento de Gastos",
"sort_field": "modified",
"sort_order": "DESC"
}
Loading

0 comments on commit 237e379

Please sign in to comment.