From 12d367de49befd46da6e5f17360fe246603ba188 Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Wed, 29 Apr 2020 17:11:32 +0200 Subject: [PATCH] [IMP] account_financial_report: open_items * added option "show_partner_details" --- account_financial_report/report/open_items.py | 20 ++ .../report/open_items_xlsx.py | 45 ++- .../report/templates/general_ledger.xml | 24 +- .../report/templates/open_items.xml | 315 ++++++++++-------- .../wizard/open_items_wizard.py | 1 + .../wizard/open_items_wizard_view.xml | 1 + 6 files changed, 228 insertions(+), 178 deletions(-) diff --git a/account_financial_report/report/open_items.py b/account_financial_report/report/open_items.py index be0c21f9..544cc3e1 100644 --- a/account_financial_report/report/open_items.py +++ b/account_financial_report/report/open_items.py @@ -324,6 +324,20 @@ class OpenItemsReport(models.AbstractModel): total_amount[account_id]["residual"] += move_line["amount_residual"] return total_amount + @api.model + def _get_open_items_no_partners(self, open_items_move_lines_data): + new_open_items = {} + for acc_id in open_items_move_lines_data.keys(): + new_open_items[acc_id] = {} + move_lines = [] + for prt_id in open_items_move_lines_data[acc_id]: + for move_line in open_items_move_lines_data[acc_id][prt_id]: + move_lines += [move_line] + move_lines = sorted(move_lines, key=lambda k: (k["date"])) + new_open_items[acc_id] = move_lines + return new_open_items + + @api.multi def _get_report_values(self, docids, data): wizard_id = data["wizard_id"] company = self.env["res.company"].browse(data["company_id"]) @@ -334,6 +348,7 @@ class OpenItemsReport(models.AbstractModel): date_at_object = datetime.strptime(date_at, "%Y-%m-%d").date() date_from = data["date_from"] target_move = data["target_move"] + show_partner_details = data["show_partner_details"] ( move_lines_data, @@ -346,11 +361,16 @@ class OpenItemsReport(models.AbstractModel): ) total_amount = self._calculate_amounts(open_items_move_lines_data) + if not show_partner_details: + open_items_move_lines_data = self._get_open_items_no_partners( + open_items_move_lines_data + ) return { "doc_ids": [wizard_id], "doc_model": "open.items.report.wizard", "docs": self.env["open.items.report.wizard"].browse(wizard_id), "foreign_currency": data["foreign_currency"], + "show_partner_details": data["show_partner_details"], "company_name": company.display_name, "currency_name": company.currency_id.name, "date_at": date_at_object.strftime("%d/%m/%Y"), diff --git a/account_financial_report/report/open_items_xlsx.py b/account_financial_report/report/open_items_xlsx.py index 36f8677a..5fc0841d 100644 --- a/account_financial_report/report/open_items_xlsx.py +++ b/account_financial_report/report/open_items_xlsx.py @@ -109,6 +109,7 @@ class OpenItemsXslx(models.AbstractModel): accounts_data = res_data["accounts_data"] partners_data = res_data["partners_data"] total_amount = res_data["total_amount"] + show_partner_details = res_data["show_partner_details"] for account_id in Open_items.keys(): # Write account title self.write_array_title( @@ -119,30 +120,38 @@ class OpenItemsXslx(models.AbstractModel): # For each partner if Open_items[account_id]: - for partner_id in Open_items[account_id]: - type_object = "partner" - # Write partner title - self.write_array_title(partners_data[partner_id]["name"]) - + if show_partner_details: + for partner_id in Open_items[account_id]: + type_object = "partner" + # Write partner title + self.write_array_title(partners_data[partner_id]["name"]) + + # Display array header for move lines + self.write_array_header() + + # Display account move lines + for line in Open_items[account_id][partner_id]: + self.write_line_from_dict(line) + + # Display ending balance line for partner + self.write_ending_balance_from_dict( + partners_data[partner_id], + type_object, + total_amount, + account_id, + partner_id, + ) + + # Line break + self.row_pos += 1 + else: # Display array header for move lines self.write_array_header() # Display account move lines - for line in Open_items[account_id][partner_id]: + for line in Open_items[account_id]: self.write_line_from_dict(line) - # Display ending balance line for partner - self.write_ending_balance_from_dict( - partners_data[partner_id], - type_object, - total_amount, - account_id, - partner_id, - ) - - # Line break - self.row_pos += 1 - # Display ending balance line for account type_object = "account" self.write_ending_balance_from_dict( diff --git a/account_financial_report/report/templates/general_ledger.xml b/account_financial_report/report/templates/general_ledger.xml index 06444e7d..42610b54 100644 --- a/account_financial_report/report/templates/general_ledger.xml +++ b/account_financial_report/report/templates/general_ledger.xml @@ -85,20 +85,20 @@ /> - - - - - - - + + + + + + + diff --git a/account_financial_report/report/templates/open_items.xml b/account_financial_report/report/templates/open_items.xml index 4f1c333a..56a59539 100644 --- a/account_financial_report/report/templates/open_items.xml +++ b/account_financial_report/report/templates/open_items.xml @@ -28,26 +28,48 @@ -
- -
- @@ -101,133 +123,130 @@
-