From 4beb76dc8c8a048b54e00a7319a91fdc174d5ffb Mon Sep 17 00:00:00 2001 From: Risvana Cybro Date: Mon, 10 Nov 2025 18:34:40 +0530 Subject: [PATCH] Nov 10: [FIX] Bug Fixed 'auto_save_restrict' --- auto_save_restrict/__init__.py | 1 + auto_save_restrict/__manifest__.py | 2 +- auto_save_restrict/models/__init__.py | 1 + auto_save_restrict/models/sale_order.py | 73 +++++++++++++++++++ .../static/description/index.html | 24 +++++- 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 auto_save_restrict/models/__init__.py create mode 100644 auto_save_restrict/models/sale_order.py diff --git a/auto_save_restrict/__init__.py b/auto_save_restrict/__init__.py index 5ac71562c..93b2a812e 100644 --- a/auto_save_restrict/__init__.py +++ b/auto_save_restrict/__init__.py @@ -19,3 +19,4 @@ # If not, see . # ############################################################################# +from . import models \ No newline at end of file diff --git a/auto_save_restrict/__manifest__.py b/auto_save_restrict/__manifest__.py index 58775076e..42ea2f2f1 100644 --- a/auto_save_restrict/__manifest__.py +++ b/auto_save_restrict/__manifest__.py @@ -32,7 +32,7 @@ 'company': 'Cybrosys Techno Solutions', 'maintainer': 'Cybrosys Techno Solutions', 'website': 'https://www.cybrosys.com', - 'depends': ['base'], + 'depends': ['base','sale'], 'assets': { 'web.assets_backend': [ 'auto_save_restrict/static/src/js/form_controller.js', diff --git a/auto_save_restrict/models/__init__.py b/auto_save_restrict/models/__init__.py new file mode 100644 index 000000000..67427f49a --- /dev/null +++ b/auto_save_restrict/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order \ No newline at end of file diff --git a/auto_save_restrict/models/sale_order.py b/auto_save_restrict/models/sale_order.py new file mode 100644 index 000000000..1915d6063 --- /dev/null +++ b/auto_save_restrict/models/sale_order.py @@ -0,0 +1,73 @@ +from odoo import models, api, _ +from odoo.exceptions import UserError + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + def action_confirm(self): + """ Confirm the given quotation(s) and set their confirmation date. + + If the corresponding setting is enabled, also locks the Sale Order. + + :return: True + :rtype: bool + :raise: UserError if trying to confirm cancelled SO's + """ + + # Filter out orders that are already confirmed or don't need confirmation + orders_to_confirm = self.env['sale.order'] + for order in self: + error_msg = order._confirmation_error_message() + if error_msg: + if order.state in ('sale', 'done', 'cancel'): + continue + raise UserError(error_msg) + orders_to_confirm |= order + + # If no orders to confirm, return early + if not orders_to_confirm: + return True + + orders_to_confirm.order_line._validate_analytic_distribution() + + for order in orders_to_confirm: + # ensure the record exists in DB before checking followers + if not order.id: + order.flush() + + # Refresh follower cache + order.invalidate_recordset(['message_partner_ids']) + + # Check if already followed directly in DB + self.env.cr.execute(""" + SELECT 1 FROM mail_followers + WHERE res_model = %s AND res_id = %s AND partner_id = %s + LIMIT 1 + """, ('sale.order', order.id, order.partner_id.id)) + already_follower = self.env.cr.fetchone() + + if not already_follower: + try: + with self.env.cr.savepoint(): + order.message_subscribe([order.partner_id.id]) + except Exception: + pass # partner already subscribed (race condition, etc.) + + orders_to_confirm.write( + orders_to_confirm._prepare_confirmation_values() + ) + + # Remove unwanted context + context = self._context.copy() + context.pop('default_name', None) + + orders_to_confirm.with_context(context)._action_confirm() + + user = orders_to_confirm[:1].create_uid + if user and user.sudo().has_group('sale.group_auto_done_setting'): + orders_to_confirm.action_lock() + + if self.env.context.get('send_email'): + orders_to_confirm._send_order_confirmation_mail() + + return True diff --git a/auto_save_restrict/static/description/index.html b/auto_save_restrict/static/description/index.html index 7649b927f..dcd44791a 100644 --- a/auto_save_restrict/static/description/index.html +++ b/auto_save_restrict/static/description/index.html @@ -171,7 +171,29 @@ >Email Us - + + + Skype Us +