diff --git a/account_financial_report/README.rst b/account_financial_report/README.rst index 1dc56d7f..b76b83e6 100644 --- a/account_financial_report/README.rst +++ b/account_financial_report/README.rst @@ -136,6 +136,8 @@ Contributors * Harald Panten * Valentin Vinagre +* Lois Rilo + Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. diff --git a/account_financial_report/readme/CONTRIBUTORS.rst b/account_financial_report/readme/CONTRIBUTORS.rst index 7d3a130a..b460bc03 100644 --- a/account_financial_report/readme/CONTRIBUTORS.rst +++ b/account_financial_report/readme/CONTRIBUTORS.rst @@ -29,5 +29,7 @@ * Harald Panten * Valentin Vinagre +* Lois Rilo + Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. diff --git a/account_financial_report/report/__init__.py b/account_financial_report/report/__init__.py index 41936758..ae2ee3d5 100644 --- a/account_financial_report/report/__init__.py +++ b/account_financial_report/report/__init__.py @@ -3,6 +3,7 @@ # © 2016 Julien Coux (Camptocamp) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).- +from . import abstract_report from . import abstract_report_xlsx from . import aged_partner_balance from . import aged_partner_balance_xlsx diff --git a/account_financial_report/report/abstract_report.py b/account_financial_report/report/abstract_report.py new file mode 100644 index 00000000..96e32351 --- /dev/null +++ b/account_financial_report/report/abstract_report.py @@ -0,0 +1,126 @@ +# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class AgedPartnerBalanceReport(models.AbstractModel): + _name = "report.account_financial_report.abstract_report" + _description = "Abstract Report" + + @api.model + def _get_move_lines_domain_not_reconciled( + self, company_id, account_ids, partner_ids, only_posted_moves, date_from + ): + domain = [ + ("account_id", "in", account_ids), + ("company_id", "=", company_id), + ("reconciled", "=", False), + ] + if partner_ids: + domain += [("partner_id", "in", partner_ids)] + if only_posted_moves: + domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] + if date_from: + domain += [("date", ">", date_from)] + return domain + + @api.model + def _get_new_move_lines_domain( + self, new_ml_ids, account_ids, company_id, partner_ids, only_posted_moves + ): + domain = [ + ("account_id", "in", account_ids), + ("company_id", "=", company_id), + ("id", "in", new_ml_ids), + ] + if partner_ids: + domain += [("partner_id", "in", partner_ids)] + if only_posted_moves: + domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] + return domain + + def _recalculate_move_lines( + self, + move_lines, + debit_ids, + credit_ids, + debit_amount, + credit_amount, + ml_ids, + account_ids, + company_id, + partner_ids, + only_posted_moves, + ): + debit_ids = set(debit_ids) + credit_ids = set(credit_ids) + in_credit_but_not_in_debit = credit_ids - debit_ids + reconciled_ids = list(debit_ids) + list(in_credit_but_not_in_debit) + reconciled_ids = set(reconciled_ids) + ml_ids = set(ml_ids) + new_ml_ids = reconciled_ids - ml_ids + new_ml_ids = list(new_ml_ids) + new_domain = self._get_new_move_lines_domain( + new_ml_ids, account_ids, company_id, partner_ids, only_posted_moves + ) + ml_fields = [ + "id", + "name", + "date", + "move_id", + "journal_id", + "account_id", + "partner_id", + "amount_residual", + "date_maturity", + "ref", + "debit", + "credit", + "reconciled", + "currency_id", + "amount_currency", + "amount_residual_currency", + ] + new_move_lines = self.env["account.move.line"].search_read( + domain=new_domain, fields=ml_fields + ) + move_lines = move_lines + new_move_lines + for move_line in move_lines: + ml_id = move_line["id"] + if ml_id in debit_ids: + move_line["amount_residual"] += debit_amount[ml_id] + if ml_id in credit_ids: + move_line["amount_residual"] -= credit_amount[ml_id] + return move_lines + + def _get_accounts_data(self, accounts_ids): + accounts = self.env["account.account"].browse(accounts_ids) + accounts_data = {} + for account in accounts: + accounts_data.update( + { + account.id: { + "id": account.id, + "code": account.code, + "name": account.name, + "hide_account": False, + "group_id": account.group_id.id, + "currency_id": account.currency_id or False, + "currency_name": account.currency_id.name, + "centralized": account.centralized, + } + } + ) + return accounts_data + + def _get_journals_data(self, journals_ids): + journals = self.env["account.journal"].browse(journals_ids) + journals_data = {} + for journal in journals: + journals_data.update({journal.id: {"id": journal.id, "code": journal.code}}) + return journals_data diff --git a/account_financial_report/report/aged_partner_balance.py b/account_financial_report/report/aged_partner_balance.py index f18daaf0..93019118 100644 --- a/account_financial_report/report/aged_partner_balance.py +++ b/account_financial_report/report/aged_partner_balance.py @@ -12,6 +12,7 @@ from odoo.tools import float_is_zero class AgedPartnerBalanceReport(models.AbstractModel): _name = "report.account_financial_report.aged_partner_balance" _description = "Aged Partner Balance Report" + _inherit = "report.account_financial_report.abstract_report" @api.model def _initialize_account(self, ag_pb_data, acc_id): @@ -40,45 +41,6 @@ class AgedPartnerBalanceReport(models.AbstractModel): ag_pb_data[acc_id][prt_id]["move_lines"] = [] return ag_pb_data - def _get_journals_data(self, journals_ids): - journals = self.env["account.journal"].browse(journals_ids) - journals_data = {} - for journal in journals: - journals_data.update({journal.id: {"id": journal.id, "code": journal.code}}) - return journals_data - - def _get_accounts_data(self, accounts_ids): - accounts = self.env["account.account"].browse(accounts_ids) - accounts_data = {} - for account in accounts: - accounts_data.update( - { - account.id: { - "id": account.id, - "code": account.code, - "name": account.name, - } - } - ) - return accounts_data - - @api.model - def _get_move_lines_domain( - self, company_id, account_ids, partner_ids, only_posted_moves, date_from - ): - domain = [ - ("account_id", "in", account_ids), - ("company_id", "=", company_id), - ("reconciled", "=", False), - ] - if partner_ids: - domain += [("partner_id", "in", partner_ids)] - if only_posted_moves: - domain += [("move_id.state", "=", "posted")] - if date_from: - domain += [("date", ">", date_from)] - return domain - @api.model def _calculate_amounts( self, ag_pb_data, acc_id, prt_id, residual, due_date, date_at_object @@ -128,70 +90,6 @@ class AgedPartnerBalanceReport(models.AbstractModel): ) return accounts_partial_reconcile, debit_amount, credit_amount - @api.model - def _get_new_move_lines_domain( - self, new_ml_ids, account_ids, company_id, partner_ids, only_posted_moves - ): - domain = [ - ("account_id", "in", account_ids), - ("company_id", "=", company_id), - ("id", "in", new_ml_ids), - ] - if partner_ids: - domain += [("partner_id", "in", partner_ids)] - if only_posted_moves: - domain += [("move_id.state", "=", "posted")] - return domain - - def _recalculate_move_lines( - self, - move_lines, - debit_ids, - credit_ids, - debit_amount, - credit_amount, - ml_ids, - account_ids, - company_id, - partner_ids, - only_posted_moves, - ): - debit_ids = set(debit_ids) - credit_ids = set(credit_ids) - in_credit_but_not_in_debit = credit_ids - debit_ids - reconciled_ids = list(debit_ids) + list(in_credit_but_not_in_debit) - reconciled_ids = set(reconciled_ids) - ml_ids = set(ml_ids) - new_ml_ids = reconciled_ids - ml_ids - new_ml_ids = list(new_ml_ids) - new_domain = self._get_new_move_lines_domain( - new_ml_ids, account_ids, company_id, partner_ids, only_posted_moves - ) - ml_fields = [ - "id", - "name", - "date", - "move_id", - "journal_id", - "account_id", - "partner_id", - "amount_residual", - "date_maturity", - "ref", - "reconciled", - ] - new_move_lines = self.env["account.move.line"].search_read( - domain=new_domain, fields=ml_fields - ) - move_lines = move_lines + new_move_lines - for move_line in move_lines: - ml_id = move_line["id"] - if ml_id in debit_ids: - move_line["amount_residual"] += debit_amount[ml_id] - if ml_id in credit_ids: - move_line["amount_residual"] -= credit_amount[ml_id] - return move_lines - def _get_move_lines_data( self, company_id, @@ -202,7 +100,7 @@ class AgedPartnerBalanceReport(models.AbstractModel): only_posted_moves, show_move_line_details, ): - domain = self._get_move_lines_domain( + domain = self._get_move_lines_domain_not_reconciled( company_id, account_ids, partner_ids, only_posted_moves, date_from ) ml_fields = [ diff --git a/account_financial_report/report/general_ledger.py b/account_financial_report/report/general_ledger.py index a410a244..a3e169ef 100644 --- a/account_financial_report/report/general_ledger.py +++ b/account_financial_report/report/general_ledger.py @@ -13,32 +13,7 @@ from odoo.tools import float_is_zero class GeneralLedgerReport(models.AbstractModel): _name = "report.account_financial_report.general_ledger" _description = "General Ledger Report" - - def _get_accounts_data(self, account_ids): - accounts = self.env["account.account"].browse(account_ids) - accounts_data = {} - for account in accounts: - accounts_data.update( - { - account.id: { - "id": account.id, - "code": account.code, - "name": account.name, - "group_id": account.group_id.id, - "currency_id": account.currency_id or False, - "currency_name": account.currency_id.name, - "centralized": account.centralized, - } - } - ) - return accounts_data - - def _get_journals_data(self, journals_ids): - journals = self.env["account.journal"].browse(journals_ids) - journals_data = {} - for journal in journals: - journals_data.update({journal.id: {"id": journal.id, "code": journal.code}}) - return journals_data + _inherit = "report.account_financial_report.abstract_report" def _get_tags_data(self, tags_ids): tags = self.env["account.analytic.tag"].browse(tags_ids) @@ -195,6 +170,8 @@ class GeneralLedgerReport(models.AbstractModel): base_domain += [("partner_id", "in", partner_ids)] if only_posted_moves: base_domain += [("move_id.state", "=", "posted")] + else: + base_domain += [("move_id.state", "in", ["posted", "draft"])] if analytic_tag_ids: base_domain += [("analytic_tag_ids", "in", analytic_tag_ids)] if cost_center_ids: @@ -384,6 +361,8 @@ class GeneralLedgerReport(models.AbstractModel): domain += [("partner_id", "in", partner_ids)] if only_posted_moves: domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] if analytic_tag_ids: domain += [("analytic_tag_ids", "in", analytic_tag_ids)] if cost_center_ids: @@ -628,7 +607,7 @@ class GeneralLedgerReport(models.AbstractModel): hide_account_at_0, ): general_ledger = [] - rounding = self.env.user.company_id.currency_id.rounding + rounding = self.env.company.currency_id.rounding for acc_id in gen_led_data.keys(): account = {} account.update( diff --git a/account_financial_report/report/journal_ledger.py b/account_financial_report/report/journal_ledger.py index a79a6cd5..e64a8c5c 100644 --- a/account_financial_report/report/journal_ledger.py +++ b/account_financial_report/report/journal_ledger.py @@ -49,6 +49,8 @@ class JournalLedgerReport(models.AbstractModel): ] if wizard.move_target != "all": domain += [("state", "=", wizard.move_target)] + else: + domain += [("state", "in", ["posted", "draft"])] return domain def _get_moves_order(self, wizard, journal_ids): diff --git a/account_financial_report/report/open_items.py b/account_financial_report/report/open_items.py index 6e6702fc..92b2ac23 100644 --- a/account_financial_report/report/open_items.py +++ b/account_financial_report/report/open_items.py @@ -12,23 +12,7 @@ from odoo.tools import float_is_zero class OpenItemsReport(models.AbstractModel): _name = "report.account_financial_report.open_items" _description = "Open Items Report" - - @api.model - def get_html(self, given_context=None): - return self._get_html() - - def _get_html(self): - result = {} - rcontext = {} - context = dict(self.env.context) - rcontext.update(context.get("data")) - active_id = context.get("active_id") - wiz = self.env["open.items.report.wizard"].browse(active_id) - rcontext["o"] = wiz - result["html"] = self.env.ref( - "account_financial_report.report_open_items" - ).render(rcontext) - return result + _inherit = "report.account_financial_report.abstract_report" def _get_account_partial_reconciled(self, company_id, date_at_object): domain = [("max_date", ">", date_at_object), ("company_id", "=", company_id)] @@ -52,128 +36,17 @@ class OpenItemsReport(models.AbstractModel): ) return accounts_partial_reconcile, debit_amount, credit_amount - @api.model - def _get_new_move_lines_domain( - self, new_ml_ids, account_ids, company_id, partner_ids, target_moves - ): - domain = [ - ("account_id", "in", account_ids), - ("company_id", "=", company_id), - ("id", "in", new_ml_ids), - ] - if partner_ids: - domain += [("partner_id", "in", partner_ids)] - if target_moves == "posted": - domain += [("move_id.state", "=", "posted")] - return domain - - def _recalculate_move_lines( - self, - move_lines, - debit_ids, - credit_ids, - debit_amount, - credit_amount, - ml_ids, - account_ids, - company_id, - partner_ids, - target_moves, - ): - debit_ids = set(debit_ids) - credit_ids = set(credit_ids) - in_credit_but_not_in_debit = credit_ids - debit_ids - reconciled_ids = list(debit_ids) + list(in_credit_but_not_in_debit) - reconciled_ids = set(reconciled_ids) - ml_ids = set(ml_ids) - new_ml_ids = reconciled_ids - ml_ids - new_ml_ids = list(new_ml_ids) - new_domain = self._get_new_move_lines_domain( - new_ml_ids, account_ids, company_id, partner_ids, target_moves - ) - ml_fields = [ - "id", - "name", - "date", - "move_id", - "journal_id", - "account_id", - "partner_id", - "amount_residual", - "date_maturity", - "ref", - "debit", - "credit", - "reconciled", - "currency_id", - "amount_currency", - "amount_residual_currency", - ] - new_move_lines = self.env["account.move.line"].search_read( - domain=new_domain, fields=ml_fields - ) - move_lines = move_lines + new_move_lines - for move_line in move_lines: - ml_id = move_line["id"] - if ml_id in debit_ids: - move_line["amount_residual"] += debit_amount[ml_id] - if ml_id in credit_ids: - move_line["amount_residual"] -= credit_amount[ml_id] - return move_lines - - @api.model - def _get_move_lines_domain( - self, company_id, account_ids, partner_ids, target_move, date_from - ): - domain = [ - ("account_id", "in", account_ids), - ("company_id", "=", company_id), - ("reconciled", "=", False), - ] - if partner_ids: - domain += [("partner_id", "in", partner_ids)] - if target_move == "posted": - domain += [("move_id.state", "=", "posted")] - if date_from: - domain += [("date", ">", date_from)] - return domain - - def _get_accounts_data(self, accounts_ids): - accounts = self.env["account.account"].browse(accounts_ids) - accounts_data = {} - for account in accounts: - accounts_data.update( - { - account.id: { - "id": account.id, - "code": account.code, - "name": account.name, - "hide_account": False, - "currency_id": account.currency_id or False, - "currency_name": account.currency_id.name, - } - } - ) - return accounts_data - - def _get_journals_data(self, journals_ids): - journals = self.env["account.journal"].browse(journals_ids) - journals_data = {} - for journal in journals: - journals_data.update({journal.id: {"id": journal.id, "code": journal.code}}) - return journals_data - def _get_data( self, account_ids, partner_ids, date_at_object, - target_move, + only_posted_moves, company_id, date_from, ): - domain = self._get_move_lines_domain( - company_id, account_ids, partner_ids, target_move, date_from + domain = self._get_move_lines_domain_not_reconciled( + company_id, account_ids, partner_ids, only_posted_moves, date_from ) ml_fields = [ "id", @@ -223,7 +96,7 @@ class OpenItemsReport(models.AbstractModel): account_ids, company_id, partner_ids, - target_move, + only_posted_moves, ) move_lines = [ move_line @@ -357,7 +230,7 @@ class OpenItemsReport(models.AbstractModel): date_at = data["date_at"] date_at_object = datetime.strptime(date_at, "%Y-%m-%d").date() date_from = data["date_from"] - target_move = data["target_move"] + only_posted_moves = data["only_posted_moves"] show_partner_details = data["show_partner_details"] ( @@ -367,7 +240,12 @@ class OpenItemsReport(models.AbstractModel): accounts_data, open_items_move_lines_data, ) = self._get_data( - account_ids, partner_ids, date_at_object, target_move, company_id, date_from + account_ids, + partner_ids, + date_at_object, + only_posted_moves, + company_id, + date_from, ) total_amount = self._calculate_amounts(open_items_move_lines_data) diff --git a/account_financial_report/report/trial_balance.py b/account_financial_report/report/trial_balance.py index fd586575..0aec42e2 100644 --- a/account_financial_report/report/trial_balance.py +++ b/account_financial_report/report/trial_balance.py @@ -10,42 +10,7 @@ from odoo import api, models class TrialBalanceReport(models.AbstractModel): _name = "report.account_financial_report.trial_balance" _description = "Trial Balance Report" - - @api.model - def get_html(self, given_context=None): - return self._get_html() - - def _get_html(self): - result = {} - rcontext = {} - context = dict(self.env.context) - rcontext.update(context.get("data")) - active_id = context.get("active_id") - wiz = self.env["open.items.report.wizard"].browse(active_id) - rcontext["o"] = wiz - result["html"] = self.env.ref( - "account_financial_report.report_trial_balance" - ).render(rcontext) - return result - - def _get_accounts_data(self, account_ids): - accounts = self.env["account.account"].browse(account_ids) - accounts_data = {} - for account in accounts: - accounts_data.update( - { - account.id: { - "id": account.id, - "code": account.code, - "name": account.name, - "group_id": account.group_id.id, - "hide_account": False, - "currency_id": account.currency_id or False, - "currency_name": account.currency_id.name, - } - } - ) - return accounts_data + _inherit = "report.account_financial_report.abstract_report" def _get_initial_balances_bs_ml_domain( self, @@ -74,6 +39,8 @@ class TrialBalanceReport(models.AbstractModel): domain += [("partner_id", "in", partner_ids)] if only_posted_moves: domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] if show_partner_details: domain += [("account_id.internal_type", "in", ["receivable", "payable"])] return domain @@ -106,6 +73,8 @@ class TrialBalanceReport(models.AbstractModel): domain += [("partner_id", "in", partner_ids)] if only_posted_moves: domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] if show_partner_details: domain += [("account_id.internal_type", "in", ["receivable", "payable"])] return domain @@ -137,6 +106,8 @@ class TrialBalanceReport(models.AbstractModel): domain += [("partner_id", "in", partner_ids)] if only_posted_moves: domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] if show_partner_details: domain += [("account_id.internal_type", "in", ["receivable", "payable"])] return domain @@ -168,6 +139,8 @@ class TrialBalanceReport(models.AbstractModel): domain += [("partner_id", "in", partner_ids)] if only_posted_moves: domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] if show_partner_details: domain += [("account_id.internal_type", "in", ["receivable", "payable"])] return domain @@ -252,6 +225,25 @@ class TrialBalanceReport(models.AbstractModel): ) return total_amount + @api.model + def _compute_acc_prt_amount( + self, total_amount, tb, acc_id, prt_id, foreign_currency + ): + total_amount[acc_id][prt_id] = {} + total_amount[acc_id][prt_id]["credit"] = 0.0 + total_amount[acc_id][prt_id]["debit"] = 0.0 + total_amount[acc_id][prt_id]["balance"] = 0.0 + total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"] + total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"] + if foreign_currency: + total_amount[acc_id][prt_id]["initial_currency_balance"] = round( + tb["amount_currency"], 2 + ) + total_amount[acc_id][prt_id]["ending_currency_balance"] = round( + tb["amount_currency"], 2 + ) + return total_amount + @api.model def _compute_partner_amount( self, total_amount, tb_initial_prt, tb_period_prt, foreign_currency @@ -287,34 +279,14 @@ class TrialBalanceReport(models.AbstractModel): {prt_id: {"id": prt_id, "name": tb["partner_id"][1]}} ) if acc_id not in total_amount.keys(): - total_amount[acc_id][prt_id] = {} - total_amount[acc_id][prt_id]["credit"] = 0.0 - total_amount[acc_id][prt_id]["debit"] = 0.0 - total_amount[acc_id][prt_id]["balance"] = 0.0 - total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"] - total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"] - if foreign_currency: - total_amount[acc_id][prt_id][ - "initial_currency_balance" - ] = round(tb["amount_currency"], 2) - total_amount[acc_id][prt_id]["ending_currency_balance"] = round( - tb["amount_currency"], 2 - ) + total_amount = self._compute_acc_prt_amount( + total_amount, tb, acc_id, prt_id, foreign_currency + ) partners_ids.add(tb["partner_id"]) elif prt_id not in total_amount[acc_id].keys(): - total_amount[acc_id][prt_id] = {} - total_amount[acc_id][prt_id]["credit"] = 0.0 - total_amount[acc_id][prt_id]["debit"] = 0.0 - total_amount[acc_id][prt_id]["balance"] = 0.0 - total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"] - total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"] - if foreign_currency: - total_amount[acc_id][prt_id][ - "initial_currency_balance" - ] = round(tb["amount_currency"], 2) - total_amount[acc_id][prt_id]["ending_currency_balance"] = round( - tb["amount_currency"], 2 - ) + total_amount = self._compute_acc_prt_amount( + total_amount, tb, acc_id, prt_id, foreign_currency + ) partners_ids.add(tb["partner_id"]) else: total_amount[acc_id][prt_id]["initial_balance"] += tb["balance"] diff --git a/account_financial_report/report/vat_report.py b/account_financial_report/report/vat_report.py index c529da7c..0c80673b 100644 --- a/account_financial_report/report/vat_report.py +++ b/account_financial_report/report/vat_report.py @@ -40,6 +40,8 @@ class VATReport(models.AbstractModel): ] if only_posted_moves: domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] return domain @api.model @@ -52,6 +54,8 @@ class VATReport(models.AbstractModel): ] if only_posted_moves: domain += [("move_id.state", "=", "posted")] + else: + domain += [("move_id.state", "in", ["posted", "draft"])] return domain def _get_vat_report_data(self, company_id, date_from, date_to, only_posted_moves): diff --git a/account_financial_report/static/description/index.html b/account_financial_report/static/description/index.html index 1b3ca142..cbc074dd 100644 --- a/account_financial_report/static/description/index.html +++ b/account_financial_report/static/description/index.html @@ -3,7 +3,7 @@ - + Account Financial Reports