From ead9bc6520cbc8170070ed1f3dd0d126723db822 Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Tue, 30 Jul 2024 15:53:15 -0400 Subject: [PATCH] account_credit_hold: fix a bug where the hold isn't lifted upon payment registration --- account_credit_hold/__manifest__.py | 35 +++++++++-------- account_credit_hold/models/res_partner.py | 33 ++++++++-------- .../views/account_followup_views.xml | 38 +++++++++++++------ .../views/res_partner_views.xml | 25 +++++++----- .../views/sale_order_views.xml | 15 +++++--- .../views/stock_picking_views.xml | 17 +++++---- 6 files changed, 96 insertions(+), 67 deletions(-) diff --git a/account_credit_hold/__manifest__.py b/account_credit_hold/__manifest__.py index e45d9e4..e60291f 100644 --- a/account_credit_hold/__manifest__.py +++ b/account_credit_hold/__manifest__.py @@ -1,21 +1,20 @@ { - 'name': 'Account Credit Hold', - 'version': '17.0.1.1.0', - 'summary': 'Allows setting clients on credit hold, blocking the ability confirm a new sales order.', - 'description': 'Allows setting clients on hold, blocking the ability confirm a new sales order.', - 'category': 'Accounting/Accounting', - 'author': 'Bemade Inc.', - 'maintainer': 'Marc Durepos ', - 'website': 'http://www.bemade.org', - 'license': 'LGPL-3', - 'depends': ['sale', 'account_followup', 'stock'], - 'data': [ - 'views/account_followup_views.xml', - 'views/sale_order_views.xml', - 'views/res_partner_views.xml', - 'views/stock_picking_views.xml', + "name": "Account Credit Hold", + "version": "17.0.1.1.1", + "summary": "Allows setting clients on credit hold, blocking the ability confirm a new sales order.", + "category": "Accounting/Accounting", + "author": "Bemade Inc.", + "maintainer": "Marc Durepos ", + "website": "http://www.bemade.org", + "license": "LGPL-3", + "depends": ["sale", "account_followup", "stock"], + "data": [ + "views/account_followup_views.xml", + "views/sale_order_views.xml", + "views/res_partner_views.xml", + "views/stock_picking_views.xml", ], - 'demo': [], - 'installable': True, - 'auto_install': False + "demo": [], + "installable": True, + "auto_install": False, } diff --git a/account_credit_hold/models/res_partner.py b/account_credit_hold/models/res_partner.py index 78671ca..7cdf9a1 100644 --- a/account_credit_hold/models/res_partner.py +++ b/account_credit_hold/models/res_partner.py @@ -3,7 +3,7 @@ from datetime import date class Partner(models.Model): - _inherit = 'res.partner' + _inherit = "res.partner" postpone_hold_until = fields.Date( string="Postpone Hold", @@ -19,13 +19,14 @@ class Partner(models.Model): compute_sudo=True, tracking=True, ) - on_hold = fields.Boolean(string="Account on Hold", - help="Client account is on hold for unpaid overdue invoices.", - compute="_compute_on_hold", - compute_sudo=True, - ) + on_hold = fields.Boolean( + string="Account on Hold", + help="Client account is on hold for unpaid overdue invoices.", + compute="_compute_on_hold", + compute_sudo=True, + ) - @api.depends('postpone_hold_until', 'hold_bg') + @api.depends("postpone_hold_until", "hold_bg") def _compute_on_hold(self): # manually re-compute hold_bg since followup_status doesn't get updated in Python but gets recalculated # by an SQL query every time @@ -37,7 +38,8 @@ class Partner(models.Model): return # If there is no parent company or the parent is not on hold, we compute for ourselves if rec.hold_bg and not ( - rec.postpone_hold_until and rec.postpone_hold_until > date.today()): + rec.postpone_hold_until and rec.postpone_hold_until > date.today() + ): rec.on_hold = True else: if rec.on_hold: @@ -46,34 +48,33 @@ class Partner(models.Model): @api.autovacuum def _cleanup_expired_hold_postponements(self): - expired_holds = self.search( - [('postpone_hold_until', '<=', date.today())]) - expired_holds.write({'postpone_hold_until': False}) + expired_holds = self.search([("postpone_hold_until", "<=", date.today())]) + expired_holds.write({"postpone_hold_until": False}) def action_credit_hold(self): for rec in self: rec.hold_bg = True - rec.message_post(body=_('Placed on credit hold.')) + rec.message_post(body=_("Placed on credit hold.")) def action_lift_credit_hold(self): for rec in self: rec.hold_bg = False - rec.message_post(body=_('Credit hold lifted.')) + rec.message_post(body=_("Credit hold lifted.")) def _execute_followup_partner(self, options=None): res = super()._execute_followup_partner(options) - if self.followup_status == 'in_need_of_action': + if self.followup_status == "in_need_of_action": if self.followup_line_id.account_hold: self.action_credit_hold() return res - @api.depends('followup_status', 'followup_line_id') + @api.depends("followup_status", "followup_line_id") def _compute_hold_bg(self): first_followup_level = self._get_first_followup_level() for rec in self: prev_hold_bg = rec.hold_bg level = rec.followup_line_id - if rec.followup_status == 'no_action_needed' and level == first_followup_level: + if rec.followup_status == "no_action_needed" and not level: rec.hold_bg = False else: rec.hold_bg = prev_hold_bg diff --git a/account_credit_hold/views/account_followup_views.xml b/account_credit_hold/views/account_followup_views.xml index faa0804..962cd79 100644 --- a/account_credit_hold/views/account_followup_views.xml +++ b/account_credit_hold/views/account_followup_views.xml @@ -1,33 +1,49 @@ - + - account_credit_hold.account_followup_line.form account_followup.followup.line - + - + customer.statements.form.view.inherit res.partner - + - -