Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diamoerp staging #878

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ <h5 class="text-center">
{% } %}
{% if(!filters.show_future_payments) { %}
<th style="width: 20%">{%= (filters.customer || filters.supplier) ? __("Remarks"): __("Party") %}</th>
{% if(report.report_name === "Accounts Receivable" && frappe.boot.single_types.includes("Persat Settings")) { %}
<th style="width: 20%">Familia</th>
{% } %}
{% } %}
<th style="width: 10%; text-align: right">{%= __("Invoiced Amount") %}</th>
{% if(!filters.show_future_payments) { %}
Expand Down Expand Up @@ -204,6 +207,10 @@ <h5 class="text-center">
</td>
{% } %}

{% if(report.report_name === "Accounts Receivable" && frappe.boot.single_types.includes("Persat Settings")) { %}
<td>{%= data[i]["familia"] %}</td>
{% } %}

<td style="text-align: right">
{%= format_currency(data[i]["invoiced"], data[i]["currency"]) %}</td>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ if (frappe.boot.single_types.includes("Persat Settings")) {
"fieldname": "familia",
"label": __("Familia"),
"fieldtype": "Link",
"options": "Customer"
"options": "Customer",
get_query: () => {
return {
filters: {
'es_familia': 1
}
};
}
}
var group_by_family = {
"fieldname": "group_by_family",
"label": __("Agrupar por Familia"),
"fieldtype": "Check",
get_query: () => {
return {
filters: {
'es_familia': 1
}
};
}
}
} else {
var family = {
Expand All @@ -16,6 +35,12 @@ if (frappe.boot.single_types.includes("Persat Settings")) {
"options": "Customer",
"hidden": 1
}
var group_by_family = {
"fieldname": "group_by_family",
"label": __("Agrupar por Familia"),
"fieldtype": "Check",
"hidden": 1
}
}
frappe.query_reports["Accounts Receivable"] = {
"filters": [
Expand Down Expand Up @@ -153,6 +178,7 @@ frappe.query_reports["Accounts Receivable"] = {
"label": __("Group By Customer"),
"fieldtype": "Check"
},
group_by_family,
{
"fieldname": "based_on_payment_terms",
"label": __("Based On Payment Terms"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def set_defaults(self):
self.previous_party=''
self.total_row_map = {}
self.skip_total_row = 1
elif self.filters.get('group_by_family'):
self.previous_family=''
self.total_family_row_map = {}
self.skip_total_row = 1

def get_data(self):
self.get_gl_entries()
Expand Down Expand Up @@ -106,6 +110,8 @@ def init_voucher_balance(self):
else:
familia = None

if self.filters.get('group_by_family') and not familia:
continue
# 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 @@ -130,9 +136,13 @@ def init_voucher_balance(self):

if self.filters.get('group_by_party'):
self.init_subtotal_row(gle.party)
elif self.filters.get('group_by_family'):
self.init_subtotal_family_row(familia)

if self.filters.get('group_by_party'):
self.init_subtotal_row('Total')
elif self.filters.get('group_by_family'):
self.init_subtotal_family_row('Total')

def get_invoices(self, gle):
if gle.voucher_type in ('Sales Invoice', 'Purchase Invoice'):
Expand All @@ -152,6 +162,16 @@ def init_subtotal_row(self, party):

for field in self.get_currency_fields():
self.total_row_map[party][field] = 0.0

def init_subtotal_family_row(self, familia):
if not self.total_family_row_map.get(familia):
self.total_family_row_map.setdefault(familia, {
'familia': familia,
'bold': 1
})

for field in self.get_currency_fields():
self.total_family_row_map[familia][field] = 0.0

def get_currency_fields(self):
return ['invoiced', 'paid', 'credit_note', 'outstanding', 'range1', 'range2', 'range3', 'range4', 'range5']
Expand Down Expand Up @@ -194,6 +214,12 @@ def update_sub_total_row(self, row, party):

for field in self.get_currency_fields():
total_row[field] += row.get(field, 0.0)

def update_sub_total_family_row(self, row, familia):
total_row = self.total_family_row_map.get(familia)

for field in self.get_currency_fields():
total_row[field] += row.get(field, 0.0)

def append_subtotal_row(self, party):
sub_total_row = self.total_row_map.get(party)
Expand All @@ -202,6 +228,14 @@ def append_subtotal_row(self, party):
self.data.append(sub_total_row)
self.data.append({})
self.update_sub_total_row(sub_total_row, 'Total')

def append_subtotal_family_row(self, familia):
sub_total_row = self.total_family_row_map.get(familia)

if sub_total_row:
self.data.append(sub_total_row)
self.data.append({})
self.update_sub_total_family_row(sub_total_row, 'Total')

def get_voucher_balance(self, gle):
if self.filters.get("sales_person"):
Expand Down Expand Up @@ -276,6 +310,8 @@ def build_data(self):
conversion_rate = get_exchange_rate("USD", vourcher_data[currency_field], nowdate(), exchange_type)
row.outstanding_original_currency = flt((row.outstanding / conversion_rate), self.currency_precision)

row['voucher_type'] = _(row['voucher_type'])

if frappe.get_hooks('accounts_receivable_usd_column') and row.outstanding == 0.0:
row.outstanding_original_currency = 0

Expand Down Expand Up @@ -306,6 +342,10 @@ def build_data(self):
self.append_subtotal_row(self.previous_party)
if self.data:
self.data.append(self.total_row_map.get('Total'))
elif self.filters.get('group_by_family'):
self.append_subtotal_family_row(self.previous_family)
if self.data:
self.data.append(self.total_family_row_map.get('Total'))

def append_row(self, row):
self.allocate_future_payments(row)
Expand All @@ -318,6 +358,11 @@ def append_row(self, row):
if self.previous_party and (self.previous_party != row.party):
self.append_subtotal_row(self.previous_party)
self.previous_party = row.party
elif self.filters.get('group_by_family'):
self.update_sub_total_family_row(row, row.familia)
if self.previous_family and (self.previous_family != row.familia):
self.append_subtotal_family_row(self.previous_family)
self.previous_family = row.familia

self.data.append(row)

Expand Down Expand Up @@ -652,7 +697,7 @@ def get_gl_entries(self):
doc_currency_fields = "debit_in_account_currency, credit_in_account_currency"

remarks = ", remarks" if self.filters.get("show_remarks") else ""

self.gl_entries = frappe.db.sql("""
select
name, posting_date, account, party_type, party, voucher_type, voucher_no, cost_center,
Expand Down Expand Up @@ -712,6 +757,8 @@ def get_cost_center_conditions(self, conditions):
def get_order_by_condition(self):
if self.filters.get('group_by_party'):
return "order by party, posting_date"
elif self.filters.get('group_by_family'):
return "order by party, posting_date"
else:
return "order by posting_date, party"

Expand Down
Loading