diff --git a/gn_financial_report/README.md b/gn_financial_report/README.md index c4572ba..13908e0 100644 --- a/gn_financial_report/README.md +++ b/gn_financial_report/README.md @@ -19,13 +19,14 @@ It is based on modules: - Displays unaffected earnings ### General Ledger -- Displays unaffected earnings +- Displays unaffected earnings initial balance and movements ### Journal Ledger - Operations on unaffected earnings account displayed as 110 or 119 ## ChangeLog +- v16.0.0.0.7: unaffected earnings movements in general ledger - v16.0.0.0.6: unaffected earnings movements in journal ledger - v16.0.0.0.5: - remove year's earning in trial balance diff --git a/gn_financial_report/__manifest__.py b/gn_financial_report/__manifest__.py index 14a1763..25960bb 100644 --- a/gn_financial_report/__manifest__.py +++ b/gn_financial_report/__manifest__.py @@ -1,6 +1,6 @@ { 'name': "Gn Financial Report", - 'version': '16.0.0.0.6', + 'version': '16.0.0.0.7', 'author': 'Garage Numérique', 'category': 'Accounting', 'description': """ diff --git a/gn_financial_report/report/general_ledger.py b/gn_financial_report/report/general_ledger.py index c331a36..d691962 100644 --- a/gn_financial_report/report/general_ledger.py +++ b/gn_financial_report/report/general_ledger.py @@ -2,6 +2,9 @@ import calendar import datetime import operator +import logging +_logger = logging.getLogger(__name__) + from odoo import _, api, models from odoo.tools import float_is_zero @@ -85,4 +88,146 @@ class GnGeneralLedgerReport(models.AbstractModel): data[unaffected_profit_id][key_bal][field_name] += pl_initial_balance[ field_name ] - return data \ No newline at end of file + return data + + def _get_period_ml_data( + self, + account_ids, + partner_ids, + company_id, + foreign_currency, + only_posted_moves, + date_from, + date_to, + gen_ld_data, + cost_center_ids, + extra_domain, + grouped_by, + ): + domain = self._get_period_domain( + account_ids, + partner_ids, + company_id, + only_posted_moves, + date_to, + date_from, + cost_center_ids, + ) + if extra_domain: + domain += extra_domain + ml_fields = self._get_ml_fields() + move_lines = self.env["account.move.line"].search_read( + domain=domain, fields=ml_fields, order="date,move_name" + ) + + # Modified part by GN (loss and profit account definition) + unaffected_earning_account = self.env['account.account'].search([('account_type', '=', 'equity_unaffected')]) + unaffected_earning_id = False + if unaffected_earning_account and len(unaffected_earning_account) == 1: + unaffected_earning_id = unaffected_earning_account[0].id + + unaffected_loss_account = self.env['account.account'].search([('code', '=', '119000')]) + if unaffected_loss_account and len(unaffected_loss_account) == 1: + unaffected_loss_id = unaffected_loss_account[0].id + + unaffected_profit_account = self.env['account.account'].search([('code', '=', '110000')]) + if unaffected_profit_account and len(unaffected_profit_account) == 1: + unaffected_profit_id = unaffected_profit_account[0].id + # End of modified part by GN + + journal_ids = set() + full_reconcile_ids = set() + taxes_ids = set() + analytic_ids = set() + full_reconcile_data = {} + acc_prt_account_ids = self._get_acc_prt_accounts_ids(company_id, grouped_by) + for move_line in move_lines: + journal_ids.add(move_line["journal_id"][0]) + for tax_id in move_line["tax_ids"]: + taxes_ids.add(tax_id) + for analytic_account in move_line["analytic_distribution"] or {}: + analytic_ids.add(int(analytic_account)) + if move_line["full_reconcile_id"]: + rec_id = move_line["full_reconcile_id"][0] + if rec_id not in full_reconcile_ids: + full_reconcile_data.update( + { + rec_id: { + "id": rec_id, + "name": move_line["full_reconcile_id"][1], + } + } + ) + full_reconcile_ids.add(rec_id) + acc_id = move_line["account_id"][0] + + # Unaffected earning lines treatment + if acc_id == unaffected_earning_id: + if move_line['balance'] > 0: + move_line["account_id"] = (unaffected_profit_id, unaffected_profit_account[0]) + acc_id = unaffected_profit_id + elif move_line['balance'] < 0: + move_line["account_id"] = (unaffected_loss_id, unaffected_loss_account[0]) + acc_id = unaffected_loss_id + # End of Gn mod + + ml_id = move_line["id"] + if acc_id not in gen_ld_data.keys(): + gen_ld_data[acc_id] = self._initialize_data(foreign_currency) + gen_ld_data[acc_id]["id"] = acc_id + gen_ld_data[acc_id]["mame"] = move_line["account_id"][1] + if grouped_by: + gen_ld_data[acc_id][grouped_by] = False + if acc_id in acc_prt_account_ids: + item_ids = self._prepare_ml_items(move_line, grouped_by) + for item in item_ids: + item_id = item["id"] + if item_id not in gen_ld_data[acc_id]: + if grouped_by: + gen_ld_data[acc_id][grouped_by] = True + gen_ld_data[acc_id][item_id] = self._initialize_data( + foreign_currency + ) + gen_ld_data[acc_id][item_id]["id"] = item_id + gen_ld_data[acc_id][item_id]["name"] = item["name"] + gen_ld_data[acc_id][item_id][ml_id] = self._get_move_line_data( + move_line + ) + gen_ld_data[acc_id][item_id]["fin_bal"]["credit"] += move_line[ + "credit" + ] + gen_ld_data[acc_id][item_id]["fin_bal"]["debit"] += move_line[ + "debit" + ] + gen_ld_data[acc_id][item_id]["fin_bal"]["balance"] += move_line[ + "balance" + ] + if foreign_currency: + gen_ld_data[acc_id][item_id]["fin_bal"][ + "bal_curr" + ] += move_line["amount_currency"] + else: + gen_ld_data[acc_id][ml_id] = self._get_move_line_data(move_line) + gen_ld_data[acc_id]["fin_bal"]["credit"] += move_line["credit"] + gen_ld_data[acc_id]["fin_bal"]["debit"] += move_line["debit"] + gen_ld_data[acc_id]["fin_bal"]["balance"] += move_line["balance"] + if foreign_currency: + gen_ld_data[acc_id]["fin_bal"]["bal_curr"] += move_line[ + "amount_currency" + ] + journals_data = self._get_journals_data(list(journal_ids)) + accounts_data = self._get_accounts_data(gen_ld_data.keys()) + taxes_data = self._get_taxes_data(list(taxes_ids)) + analytic_data = self._get_analytic_data(list(analytic_ids)) + rec_after_date_to_ids = self._get_reconciled_after_date_to_ids( + full_reconcile_data.keys(), date_to + ) + return ( + gen_ld_data, + accounts_data, + journals_data, + full_reconcile_data, + taxes_data, + analytic_data, + rec_after_date_to_ids, + ) \ No newline at end of file