From dea732e270c213ff88747d118214bdac632dfe3d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 27 Sep 2023 23:41:58 +0200 Subject: [PATCH] account_usability_ak: add blocked on account.move and show warning banner on invoice form view --- .../models/account_move.py | 28 ++++++++++++++++++ .../views/account_move.xml | 29 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/account_usability_akretion/models/account_move.py b/account_usability_akretion/models/account_move.py index 38317b8..1a87d0c 100644 --- a/account_usability_akretion/models/account_move.py +++ b/account_usability_akretion/models/account_move.py @@ -36,6 +36,34 @@ class AccountMove(models.Model): compute="_compute_sales_dates", help="This information appear on invoice qweb report " "(you may use it for your own report)") + # There is a native "blocked" field (bool) on account.move.line + # We want to have that field on invoices to improve usability + # while keeping compatibility with the standard Odoo datamodel + blocked = fields.Boolean( + compute="_compute_blocked", + inverse="_inverse_blocked", + store=True, + string="Dispute", + tracking=True, + ) + + @api.depends("line_ids", "line_ids.blocked") + def _compute_blocked(self): + for move in self: + move.blocked = any( + [ + l.blocked + for l in move.line_ids + if l.account_id.account_type in ("liability_payable", "asset_receivable") + ] + ) + + def _inverse_blocked(self): + for move in self: + for line in move.line_ids.filtered( + lambda l: l.account_id.account_type in ("liability_payable", "asset_receivable") + ): + line.blocked = move.blocked def _compute_has_discount(self): prec = self.env['decimal.precision'].precision_get('Discount') diff --git a/account_usability_akretion/views/account_move.xml b/account_usability_akretion/views/account_move.xml index 3b4576c..4ea1689 100644 --- a/account_usability_akretion/views/account_move.xml +++ b/account_usability_akretion/views/account_move.xml @@ -43,6 +43,16 @@ + + + +
+ +
{'invisible': ['|', ('state', '=', 'cancel'), ('duplicated_ref_ids', '=', [])]} @@ -77,6 +87,8 @@ + + @@ -87,6 +99,23 @@
+ + account.move.line + + + + + {'invisible': [('account_type', 'not in', ('liability_payable', 'asset_receivable'))]} + + + + + + + account.move.line