From 77bdc39e329f207fb0c066c07e85ec1f7b029a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Thu, 30 Jun 2022 11:51:18 +0200 Subject: [PATCH] [UPD] Add button to list draft invoice lines linked to budget line --- .../models/budget_forecast.py | 21 +++++++++++++++++++ .../views/budget_forecast.xml | 15 +++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/account_budget_forecast/models/budget_forecast.py b/account_budget_forecast/models/budget_forecast.py index e415913..ffe10c8 100644 --- a/account_budget_forecast/models/budget_forecast.py +++ b/account_budget_forecast/models/budget_forecast.py @@ -418,3 +418,24 @@ class BudgetForecast(models.Model): return action else: raise UserError(_("There is no analytic lines linked to this budget line")) + + def action_view_draft_invoice_lines(self): + self.ensure_one() + invoice_lines = ( + self.env["account.move.line"] + .search([("parent_state", "in", ["draft"])]) + .filtered(lambda x: self.analytic_tag in x.analytic_tag_ids) + ) + if len(invoice_lines) > 0: + action = self.env["ir.actions.actions"]._for_xml_id( + "account.action_account_moves_all_tree" + ) + action["domain"] = [ + ("analytic_tag_ids", "ilike", self.analytic_tag.id), + ("parent_state", "in", ["draft"]), + ] + return action + else: + raise UserError( + _("There is no draft invoice lines linked to this budget line") + ) diff --git a/account_budget_forecast/views/budget_forecast.xml b/account_budget_forecast/views/budget_forecast.xml index 1e1c179..40d93cd 100644 --- a/account_budget_forecast/views/budget_forecast.xml +++ b/account_budget_forecast/views/budget_forecast.xml @@ -36,10 +36,17 @@ - - + + + + + + +