diff --git a/sale_order_discount_approval_odoo/__manifest__.py b/sale_order_discount_approval_odoo/__manifest__.py index 21efbdd1a..3be3293ae 100644 --- a/sale_order_discount_approval_odoo/__manifest__.py +++ b/sale_order_discount_approval_odoo/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'Sale Order Discount Approval', - 'version': '18.0.1.0.0', + 'version': '18.0.1.0.1', 'category': 'Sales', 'summary': 'Sale Order Discount Approval based on the Allowed discount values', 'description': """Module for discount approval of sales orders if diff --git a/sale_order_discount_approval_odoo/doc/RELEASE_NOTES.md b/sale_order_discount_approval_odoo/doc/RELEASE_NOTES.md index 90289cb43..4bd130b9f 100644 --- a/sale_order_discount_approval_odoo/doc/RELEASE_NOTES.md +++ b/sale_order_discount_approval_odoo/doc/RELEASE_NOTES.md @@ -4,3 +4,7 @@ #### Version 18.0.1.0.0 #### ADD - Initial commit for Sale Order Discount Approval +#### 14.10.2024 +#### Version 18.0.1.0.1 +#### UPDATE +- Updated the workflow to set the approval stage by also comparing the global discount. diff --git a/sale_order_discount_approval_odoo/models/__init__.py b/sale_order_discount_approval_odoo/models/__init__.py index f25d90cab..333ee9c28 100644 --- a/sale_order_discount_approval_odoo/models/__init__.py +++ b/sale_order_discount_approval_odoo/models/__init__.py @@ -3,7 +3,7 @@ # # Cybrosys Technologies Pvt. Ltd. # -# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Copyright (C) 2025-TODAY Cybrosys Technologies(). # Author: Cybrosys Techno Solutions() # # You can modify it under the terms of the GNU AFFERO diff --git a/sale_order_discount_approval_odoo/models/sale_order.py b/sale_order_discount_approval_odoo/models/sale_order.py index d2cf7c4ff..7fab847cb 100644 --- a/sale_order_discount_approval_odoo/models/sale_order.py +++ b/sale_order_discount_approval_odoo/models/sale_order.py @@ -35,19 +35,46 @@ class SaleOrder(models.Model): help='The discount approver') def action_confirm(self): - """Method for confirming the sale order discount and sending mail for - the approver if approval limit crossed""" + """Confirm sale order with discount approval check. + - If line/global discount exceeds user limit → set 'waiting_for_approval' + - Else → proceed normally. + """ + self.ensure_one() res = super().action_confirm() + to_approve = False - discount_vals = self.order_line.mapped('discount') + user_discount = self.env.user.allow_discount + discount_product = self.env.company.sale_discount_product_id approval_users = self.env.ref( 'sale_order_discount_approval_odoo.sale_order_discount_approval_odoo_group_manager').users - user_discount = self.env.user.allow_discount - if self.env.user.is_discount_control == True: - for rec in discount_vals: - if rec > user_discount: + + # ------------------------------- + # 1. Line-based discount check + # ------------------------------- + if self.env.user.is_discount_control: + for line in self.order_line: + if line.discount > user_discount: to_approve = True break + + # ------------------------------- + # 2. Global discount check + # ------------------------------- + if not to_approve and discount_product: + discount_line = self.order_line.filtered(lambda l: l.product_id == discount_product) + if discount_line: + discount_amount = abs(discount_line.price_unit) + # base total before discount + base_total = sum( + l.product_uom_qty * l.price_unit for l in self.order_line if l.product_id != discount_product) + if base_total > 0: + global_discount_pct = (discount_amount / base_total) * 100 + if global_discount_pct > user_discount: + to_approve = True + + # ------------------------------- + # 3. Apply result + # ------------------------------- if to_approve: action_id = self.env.ref( 'sale.action_quotations_with_onboarding').id @@ -56,13 +83,13 @@ class SaleOrder(models.Model): url = self.env['ir.config_parameter'].sudo().get_param( 'web.base.url') + redirect_link for user in approval_users: - mail_body = f"""

Hello,

New sale order '{self.name}' - created with Discount by '{self.env.user.name}' need your approval - on it.

To Approve, Cancel Order, Click on the Following - Link: Click Me

Thank You.

""" + mail_body = f"""

Hello,

New sale order '{self.name}' + created with Discount by '{self.env.user.name}' need your approval + on it.

To Approve, Cancel Order, Click on the Following + Link: Click Me

Thank You.

""" mail_values = { 'subject': f"{self.name} Discount Approval Request", 'body_html': mail_body, @@ -75,6 +102,8 @@ class SaleOrder(models.Model): self.state = 'waiting_for_approval' return res + + def action_waiting_approval(self): """Method for approving the sale order discount""" self.approval_user_id = self.env.user.id diff --git a/sale_order_discount_approval_odoo/static/description/assets/screenshots/s09.png b/sale_order_discount_approval_odoo/static/description/assets/screenshots/s09.png new file mode 100644 index 000000000..631a220d5 Binary files /dev/null and b/sale_order_discount_approval_odoo/static/description/assets/screenshots/s09.png differ diff --git a/sale_order_discount_approval_odoo/static/description/index.html b/sale_order_discount_approval_odoo/static/description/index.html index c9ef2fe3f..24f50666f 100644 --- a/sale_order_discount_approval_odoo/static/description/index.html +++ b/sale_order_discount_approval_odoo/static/description/index.html @@ -654,6 +654,36 @@ +
+
+
+
+

+ Check for + + + Global Discount. +

+
+
+

+ Discount will be checked for approval also +

+
+
+
+ +
+
+
+
+