From b9a4f3feabae35b41dac0af5020a6e80194f1114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Rold=C3=A1n?= Date: Mon, 23 Sep 2024 11:35:55 -0300 Subject: [PATCH] Desarrollo Serviplaga COT-2024-00012-1 (#873) * fix: report * fix * trans: voucher type en cuentas por brobrar * familia pdf --- .../accounts_receivable.html | 7 +++ .../accounts_receivable.js | 28 ++++++++++- .../accounts_receivable.py | 49 ++++++++++++++++++- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html index f4fd06ba0374..9196a0842661 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html @@ -142,6 +142,9 @@
{% } %} {% if(!filters.show_future_payments) { %} {%= (filters.customer || filters.supplier) ? __("Remarks"): __("Party") %} + {% if(report.report_name === "Accounts Receivable" && frappe.boot.single_types.includes("Persat Settings")) { %} + Familia + {% } %} {% } %} {%= __("Invoiced Amount") %} {% if(!filters.show_future_payments) { %} @@ -204,6 +207,10 @@
{% } %} + {% if(report.report_name === "Accounts Receivable" && frappe.boot.single_types.includes("Persat Settings")) { %} + {%= data[i]["familia"] %} + {% } %} + {%= format_currency(data[i]["invoiced"], data[i]["currency"]) %} diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js index ce641dc68742..446b78b103be 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.js +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.js @@ -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 = { @@ -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": [ @@ -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"), diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index f4aff769c3cd..ebd6424a8afe 100755 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -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() @@ -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: @@ -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'): @@ -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'] @@ -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) @@ -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"): @@ -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 @@ -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) @@ -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) @@ -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, @@ -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"