diff --git a/sale_financial_risk_exclude_order_type/README.rst b/sale_financial_risk_exclude_order_type/README.rst new file mode 100644 index 000000000..1c75edcfc --- /dev/null +++ b/sale_financial_risk_exclude_order_type/README.rst @@ -0,0 +1,148 @@ +====================================== +Sale Financial Risk Exclude Order Type +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f47c700d76bb1d6eda697be06e36a973c16d1b9409211b4a17653209e388ee74 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcredit--control-lightgray.png?logo=github + :target: https://github.com/OCA/credit-control/tree/17.0/sale_financial_risk_exclude_order_type + :alt: OCA/credit-control +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/credit-control-17-0/credit-control-17-0-sale_financial_risk_exclude_order_type + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/credit-control&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends ``sale.order.type`` to integrate with +``sale_financial_risk``. + +It adds two independent behaviors to sale order types: + +- Exclude orders from financial risk computation +- Allow confirmation bypass for financial risk blocking + +This allows implementing flexible commercial workflows while keeping the +standard financial risk framework intact. + +Features +======== + +- Extend ``sale.order.type`` with financial risk options +- Exclude selected order types from risk exposure computation +- Allow selected order types to bypass financial risk blocking +- Keep computation and blocking behaviors independent +- Compatible with ``sale_financial_risk`` +- Compatible with multi-company environments + +Design Notes +============ + +This module intentionally keeps the financial risk behavior directly +attached to ``sale.order.type``. + +The implementation avoids introducing additional rule or configuration +models in order to: + +- keep the behavior simple +- reduce maintenance complexity +- align with the functional nature of sale order types +- avoid unnecessary configuration layers + +The module still preserves separation between: + +- financial exposure computation +- confirmation blocking behavior + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Usage +===== + +- Exclude from Risk Computation + +Sale orders using this type will not contribute to the partner financial +exposure calculation. + +- Allow Risk Blocking Bypass + +Sale orders using this type can be confirmed even when financial risk +blocking would normally prevent confirmation. + +Both options are independent and can be combined freely. + +Known issues / Roadmap +====================== + +Known issues / Roadmap +====================== + +- Add optional risk warning indicators on sale orders +- Improve reporting of excluded order types + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Binhex Systems Solutions S.L + +Contributors +------------ + +- `Binhex Systems Solutions S.L. `__: + + - Ariel Torres + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/credit-control `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_financial_risk_exclude_order_type/__init__.py b/sale_financial_risk_exclude_order_type/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_financial_risk_exclude_order_type/__manifest__.py b/sale_financial_risk_exclude_order_type/__manifest__.py new file mode 100644 index 000000000..a1ccc55d3 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/__manifest__.py @@ -0,0 +1,20 @@ +{ + "name": "Sale Financial Risk Exclude Order Type", + "summary": "Exclude sale order types from financial risk computation", + "version": "17.0.1.0.0", + "category": "Credit Control", + "author": "Binhex Systems Solutions S.L, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/credit-control", + "license": "AGPL-3", + "depends": [ + "sale_financial_risk", + "sale_order_type", + ], + "data": [ + "views/sale_order_type_views.xml", + ], + "images": ["static/description/icon.png"], + "installable": True, + "application": False, + "development_status": "Alpha", +} diff --git a/sale_financial_risk_exclude_order_type/i18n/es.po b/sale_financial_risk_exclude_order_type/i18n/es.po new file mode 100644 index 000000000..6e9958a92 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/i18n/es.po @@ -0,0 +1,64 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_financial_risk_exclude_order_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-04-23 07:27+0000\n" +"PO-Revision-Date: 2026-04-23 07:27+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_financial_risk_exclude_order_type +#: model:ir.model.fields,field_description:sale_financial_risk_exclude_order_type.field_sale_order_type__allow_blocking_bypass +msgid "Allow Risk Blocking Bypass" +msgstr "Permitir omitir bloqueo de riesgo" + +#. module: sale_financial_risk_exclude_order_type +#: model:ir.model,name:sale_financial_risk_exclude_order_type.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: sale_financial_risk_exclude_order_type +#: model:ir.model.fields,field_description:sale_financial_risk_exclude_order_type.field_sale_order_type__exclude_from_risk +msgid "Exclude from Risk Computation" +msgstr "Excluir del cálculo de riesgo" + +#. module: sale_financial_risk_exclude_order_type +#: model_terms:ir.ui.view,arch_db:sale_financial_risk_exclude_order_type.sale_order_type_view_form_inherit_sale_financial_risk_exclude_order_type +msgid "Financial Risk" +msgstr "Riesgo financiero" + +#. module: sale_financial_risk_exclude_order_type +#: model:ir.model.fields,help:sale_financial_risk_exclude_order_type.field_sale_order_type__exclude_from_risk +msgid "" +"If enabled, sale orders of this type are excluded from sale financial risk " +"computation." +msgstr "" +"Si está habilitado, los pedidos de venta de este tipo se excluyen del cálculo " +"del riesgo financiero de venta." + +#. module: sale_financial_risk_exclude_order_type +#: model:ir.model.fields,help:sale_financial_risk_exclude_order_type.field_sale_order_type__allow_blocking_bypass +msgid "" +"If enabled, sale orders of this type can be confirmed without financial risk" +" blocking." +msgstr "" +"Si está habilitado, los pedidos de venta de este tipo se pueden confirmar " +"sin bloqueo por riesgo financiero. " + +#. module: sale_financial_risk_exclude_order_type +#: model:ir.model,name:sale_financial_risk_exclude_order_type.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" + +#. module: sale_financial_risk_exclude_order_type +#: model:ir.model,name:sale_financial_risk_exclude_order_type.model_sale_order_type +msgid "Type of sale order" +msgstr "Tipo de pedido de venta" diff --git a/sale_financial_risk_exclude_order_type/models/__init__.py b/sale_financial_risk_exclude_order_type/models/__init__.py new file mode 100644 index 000000000..54c46f430 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/models/__init__.py @@ -0,0 +1,3 @@ +from . import sale_order_type +from . import res_partner +from . import sale_order diff --git a/sale_financial_risk_exclude_order_type/models/res_partner.py b/sale_financial_risk_exclude_order_type/models/res_partner.py new file mode 100644 index 000000000..778a1da38 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/models/res_partner.py @@ -0,0 +1,28 @@ +from odoo import models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + def _get_risk_sale_order_domain(self): + """ + Extend the domain used by sale_financial_risk to compute + sale order exposure. + Since the base computation runs on sale.order.line, the related + field path used here is: + order_id.type_id + """ + domain = super()._get_risk_sale_order_domain() + excluded_types = self.env["sale.order.type"].search( + [ + ("exclude_from_risk", "=", True), + "|", + ("company_id", "=", False), + ("company_id", "=", self.env.company.id), + ] + ) + + if excluded_types: + domain += [("order_id.type_id", "not in", excluded_types.ids)] + + return domain diff --git a/sale_financial_risk_exclude_order_type/models/sale_order.py b/sale_financial_risk_exclude_order_type/models/sale_order.py new file mode 100644 index 000000000..576f15c3c --- /dev/null +++ b/sale_financial_risk_exclude_order_type/models/sale_order.py @@ -0,0 +1,27 @@ +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _allow_financial_risk_blocking_bypass(self): + """ + Return whether this order type is configured to bypass + financial risk blocking. + """ + self.ensure_one() + return bool(self.type_id and self.type_id.allow_blocking_bypass) + + def evaluate_risk_message(self, partner): + """ + Override the blocking decision from sale_financial_risk. + If the order type is configured with 'Allow Risk Blocking Bypass', + no blocking message is returned. + Otherwise, preserve the standard behavior. + """ + self.ensure_one() + + if self._allow_financial_risk_blocking_bypass(): + return False + + return super().evaluate_risk_message(partner) diff --git a/sale_financial_risk_exclude_order_type/models/sale_order_type.py b/sale_financial_risk_exclude_order_type/models/sale_order_type.py new file mode 100644 index 000000000..0020a4d03 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/models/sale_order_type.py @@ -0,0 +1,20 @@ +from odoo import fields, models + + +class SaleOrderType(models.Model): + _inherit = "sale.order.type" + + exclude_from_risk = fields.Boolean( + string="Exclude from Risk Computation", + help=( + "If enabled, sale orders of this type are excluded from " + "sale financial risk computation." + ), + ) + allow_blocking_bypass = fields.Boolean( + string="Allow Risk Blocking Bypass", + help=( + "If enabled, sale orders of this type can be confirmed " + "without financial risk blocking." + ), + ) diff --git a/sale_financial_risk_exclude_order_type/pyproject.toml b/sale_financial_risk_exclude_order_type/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/sale_financial_risk_exclude_order_type/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_financial_risk_exclude_order_type/readme/CONFIGURATION.md b/sale_financial_risk_exclude_order_type/readme/CONFIGURATION.md new file mode 100644 index 000000000..50c002be7 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/readme/CONFIGURATION.md @@ -0,0 +1,11 @@ +To configure the module: + +Go to: + +*Sales > Configuration > Sale Order Types* + +For each order type you can configure: + +- *Exclude from Risk Computation* + +- *Allow Risk Blocking Bypass* diff --git a/sale_financial_risk_exclude_order_type/readme/CONTRIBUTORS.md b/sale_financial_risk_exclude_order_type/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..84faefa7a --- /dev/null +++ b/sale_financial_risk_exclude_order_type/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Binhex Systems Solutions S.L.](https://www.binhex.cloud): + - Ariel Torres diff --git a/sale_financial_risk_exclude_order_type/readme/DESCRIPTION.md b/sale_financial_risk_exclude_order_type/readme/DESCRIPTION.md new file mode 100644 index 000000000..74be736e3 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/readme/DESCRIPTION.md @@ -0,0 +1,39 @@ +This module extends ``sale.order.type`` to integrate with +``sale_financial_risk``. + +It adds two independent behaviors to sale order types: + +- Exclude orders from financial risk computation +- Allow confirmation bypass for financial risk blocking + +This allows implementing flexible commercial workflows while +keeping the standard financial risk framework intact. + +Features +======== + +- Extend ``sale.order.type`` with financial risk options +- Exclude selected order types from risk exposure computation +- Allow selected order types to bypass financial risk blocking +- Keep computation and blocking behaviors independent +- Compatible with ``sale_financial_risk`` +- Compatible with multi-company environments + +Design Notes +============ + +This module intentionally keeps the financial risk behavior +directly attached to ``sale.order.type``. + +The implementation avoids introducing additional rule or +configuration models in order to: + +- keep the behavior simple +- reduce maintenance complexity +- align with the functional nature of sale order types +- avoid unnecessary configuration layers + +The module still preserves separation between: + +- financial exposure computation +- confirmation blocking behavior diff --git a/sale_financial_risk_exclude_order_type/readme/ROADMAP.md b/sale_financial_risk_exclude_order_type/readme/ROADMAP.md new file mode 100644 index 000000000..6e0d59996 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/readme/ROADMAP.md @@ -0,0 +1,5 @@ +Known issues / Roadmap +====================== + +- Add optional risk warning indicators on sale orders +- Improve reporting of excluded order types diff --git a/sale_financial_risk_exclude_order_type/readme/TESTS.md b/sale_financial_risk_exclude_order_type/readme/TESTS.md new file mode 100644 index 000000000..cb152e697 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/readme/TESTS.md @@ -0,0 +1,11 @@ +Testing +======= + +Includes automated tests covering: + +- risk computation exclusion +- blocking bypass behavior +- separation of concerns +- multi-company behavior +- neutral order types +- domain integrity \ No newline at end of file diff --git a/sale_financial_risk_exclude_order_type/readme/USAGE.md b/sale_financial_risk_exclude_order_type/readme/USAGE.md new file mode 100644 index 000000000..f232e5b5f --- /dev/null +++ b/sale_financial_risk_exclude_order_type/readme/USAGE.md @@ -0,0 +1,15 @@ +Usage +===== + +- Exclude from Risk Computation + +Sale orders using this type will not contribute to the +partner financial exposure calculation. + + +- Allow Risk Blocking Bypass + +Sale orders using this type can be confirmed even when +financial risk blocking would normally prevent confirmation. + +Both options are independent and can be combined freely. diff --git a/sale_financial_risk_exclude_order_type/static/description/icon.png b/sale_financial_risk_exclude_order_type/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sale_financial_risk_exclude_order_type/static/description/icon.png differ diff --git a/sale_financial_risk_exclude_order_type/static/description/index.html b/sale_financial_risk_exclude_order_type/static/description/index.html new file mode 100644 index 000000000..e3b450e1c --- /dev/null +++ b/sale_financial_risk_exclude_order_type/static/description/index.html @@ -0,0 +1,485 @@ + + + + + +Sale Financial Risk Exclude Order Type + + + +
+

Sale Financial Risk Exclude Order Type

+ + +

Alpha License: AGPL-3 OCA/credit-control Translate me on Weblate Try me on Runboat

+

This module extends sale.order.type to integrate with +sale_financial_risk.

+

It adds two independent behaviors to sale order types:

+
    +
  • Exclude orders from financial risk computation
  • +
  • Allow confirmation bypass for financial risk blocking
  • +
+

This allows implementing flexible commercial workflows while keeping the +standard financial risk framework intact.

+
+

Features

+
    +
  • Extend sale.order.type with financial risk options
  • +
  • Exclude selected order types from risk exposure computation
  • +
  • Allow selected order types to bypass financial risk blocking
  • +
  • Keep computation and blocking behaviors independent
  • +
  • Compatible with sale_financial_risk
  • +
  • Compatible with multi-company environments
  • +
+
+
+

Design Notes

+

This module intentionally keeps the financial risk behavior directly +attached to sale.order.type.

+

The implementation avoids introducing additional rule or configuration +models in order to:

+
    +
  • keep the behavior simple
  • +
  • reduce maintenance complexity
  • +
  • align with the functional nature of sale order types
  • +
  • avoid unnecessary configuration layers
  • +
+

The module still preserves separation between:

+
    +
  • financial exposure computation
  • +
  • confirmation blocking behavior
  • +
+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+
+
+

Usage

+
+
+

Usage

+
    +
  • Exclude from Risk Computation
  • +
+

Sale orders using this type will not contribute to the partner financial +exposure calculation.

+
    +
  • Allow Risk Blocking Bypass
  • +
+

Sale orders using this type can be confirmed even when financial risk +blocking would normally prevent confirmation.

+

Both options are independent and can be combined freely.

+
+
+

Known issues / Roadmap

+
+
+

Known issues / Roadmap

+
    +
  • Add optional risk warning indicators on sale orders
  • +
  • Improve reporting of excluded order types
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Binhex Systems Solutions S.L
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/credit-control project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sale_financial_risk_exclude_order_type/tests/__init__.py b/sale_financial_risk_exclude_order_type/tests/__init__.py new file mode 100644 index 000000000..a7e549f2a --- /dev/null +++ b/sale_financial_risk_exclude_order_type/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_financial_risk_exclude_order_type diff --git a/sale_financial_risk_exclude_order_type/tests/test_sale_financial_risk_exclude_order_type.py b/sale_financial_risk_exclude_order_type/tests/test_sale_financial_risk_exclude_order_type.py new file mode 100644 index 000000000..ded8679df --- /dev/null +++ b/sale_financial_risk_exclude_order_type/tests/test_sale_financial_risk_exclude_order_type.py @@ -0,0 +1,264 @@ +from odoo.addons.base.tests.common import BaseCommon + + +class TestSaleFinancialRiskExcludeOrderType(BaseCommon): + """ + Test suite for sale_financial_risk_exclude_order_type. + Covers: + - Blocking bypass behavior + - Risk computation exclusion + - Separation between blocking and computation + - Domain integrity + - Multi-company behavior + - Sale order types without flags + """ + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env.company + # --------------------------------------------------------- + # Partner + # --------------------------------------------------------- + cls.risk_partner = cls.env["res.partner"].create( + { + "name": "Risk Customer", + "customer_rank": 1, + "credit_limit": 500.0, + "risk_sale_order_include": True, + } + ) + # --------------------------------------------------------- + # Sale Order Types + # --------------------------------------------------------- + cls.type_excluded = cls.env["sale.order.type"].create( + { + "name": "Excluded Type", + "exclude_from_risk": True, + "allow_blocking_bypass": True, + } + ) + cls.type_bypass_only = cls.env["sale.order.type"].create( + { + "name": "Bypass Only", + "exclude_from_risk": False, + "allow_blocking_bypass": True, + } + ) + cls.type_normal = cls.env["sale.order.type"].create( + { + "name": "Normal Type", + "exclude_from_risk": False, + "allow_blocking_bypass": False, + } + ) + + # --------------------------------------------------------- + # Helpers + # --------------------------------------------------------- + def _create_sale_order(self, order_type=False): + """ + Create a sale order using the provided sale order type. + """ + vals = { + "partner_id": self.risk_partner.id, + "partner_invoice_id": self.risk_partner.id, + "partner_shipping_id": self.risk_partner.id, + } + if order_type: + vals["type_id"] = order_type.id + return self.env["sale.order"].create(vals) + + # --------------------------------------------------------- + # Blocking behavior + # --------------------------------------------------------- + def test_bypass_enabled(self): + """ + Order types configured with allow_blocking_bypass + must bypass financial risk blocking. + """ + order = self._create_sale_order(self.type_excluded) + self.assertTrue(order._allow_financial_risk_blocking_bypass()) + self.assertFalse(order.evaluate_risk_message(self.risk_partner)) + + def test_bypass_only_type(self): + """ + Order types configured only with blocking bypass: + - must bypass blocking + - must still contribute to risk computation + """ + order = self._create_sale_order(self.type_bypass_only) + self.assertTrue(order._allow_financial_risk_blocking_bypass()) + self.assertFalse(order.evaluate_risk_message(self.risk_partner)) + + def test_no_bypass_for_normal_type(self): + """ + Order types without bypass configuration + must preserve standard behavior. + """ + order = self._create_sale_order(self.type_normal) + self.assertFalse(order._allow_financial_risk_blocking_bypass()) + + def test_no_bypass_without_order_type(self): + """ + Orders without type_id must not bypass risk blocking. + """ + order = self._create_sale_order() + self.assertFalse(order._allow_financial_risk_blocking_bypass()) + + def test_bypass_disabled(self): + """ + Order types without bypass enabled + must not bypass blocking. + """ + order_type = self.env["sale.order.type"].create( + { + "name": "No Bypass Type", + "exclude_from_risk": True, + "allow_blocking_bypass": False, + } + ) + order = self._create_sale_order(order_type) + self.assertFalse(order._allow_financial_risk_blocking_bypass()) + + # --------------------------------------------------------- + # Risk computation domain + # --------------------------------------------------------- + def test_exclude_from_risk_domain(self): + """ + Order types configured with exclude_from_risk=True + must be excluded from the risk computation domain. + """ + domain = self.risk_partner._get_risk_sale_order_domain() + self.assertIn( + ("order_id.type_id", "not in", self.type_excluded.ids), + domain, + ) + + def test_bypass_only_does_not_affect_domain(self): + """ + Blocking bypass alone must not affect + risk computation domain. + """ + domain = self.risk_partner._get_risk_sale_order_domain() + self.assertNotIn( + ("order_id.type_id", "not in", self.type_bypass_only.ids), + domain, + ) + + def test_normal_type_does_not_affect_domain(self): + """ + Neutral order types must not affect + the risk computation domain. + """ + domain = self.risk_partner._get_risk_sale_order_domain() + self.assertNotIn( + ("order_id.type_id", "not in", self.type_normal.ids), + domain, + ) + + def test_domain_integrity(self): + """ + The resulting domain must remain list-based. + """ + domain = self.risk_partner._get_risk_sale_order_domain() + self.assertIsInstance(domain, list) + + def test_exclusion_clause_present_once(self): + """ + Exclusion clause must only appear once + in the resulting domain. + """ + domain = self.risk_partner._get_risk_sale_order_domain() + clauses = [ + clause + for clause in domain + if clause + == ( + "order_id.type_id", + "not in", + self.type_excluded.ids, + ) + ] + self.assertEqual(len(clauses), 1) + + # --------------------------------------------------------- + # Separation of concerns + # --------------------------------------------------------- + def test_computation_and_blocking_are_independent(self): + """ + Blocking bypass and risk computation exclusion + must behave independently. + """ + order = self._create_sale_order(self.type_bypass_only) + # Blocking bypass enabled + self.assertFalse(order.evaluate_risk_message(self.risk_partner)) + # Still included in computation + domain = self.risk_partner._get_risk_sale_order_domain() + self.assertNotIn( + ("order_id.type_id", "not in", self.type_bypass_only.ids), + domain, + ) + + def test_type_with_no_flags(self): + """ + Order types without any enabled flags + must not affect behavior. + """ + order_type = self.env["sale.order.type"].create( + { + "name": "Neutral Type", + "exclude_from_risk": False, + "allow_blocking_bypass": False, + } + ) + order = self._create_sale_order(order_type) + self.assertFalse(order._allow_financial_risk_blocking_bypass()) + domain = self.risk_partner._get_risk_sale_order_domain() + self.assertNotIn( + ("order_id.type_id", "not in", order_type.ids), + domain, + ) + + # --------------------------------------------------------- + # Multi-company behavior + # --------------------------------------------------------- + def test_company_specific_order_types(self): + """ + Company-specific order types must remain isolated + in their respective companies. + """ + company_2 = self.env["res.company"].create( + { + "name": "Company 2", + } + ) + partner_2 = self.env["res.partner"].create( + { + "name": "Customer Company 2", + "customer_rank": 1, + "company_id": company_2.id, + } + ) + type_company_2 = self.env["sale.order.type"].create( + { + "name": "Company 2 Type", + "company_id": company_2.id, + "exclude_from_risk": True, + "allow_blocking_bypass": True, + } + ) + order = ( + self.env["sale.order"] + .with_company(company_2) + .create( + { + "partner_id": partner_2.id, + "partner_invoice_id": partner_2.id, + "partner_shipping_id": partner_2.id, + "company_id": company_2.id, + "type_id": type_company_2.id, + } + ) + ) + self.assertTrue(order._allow_financial_risk_blocking_bypass()) diff --git a/sale_financial_risk_exclude_order_type/views/sale_order_type_views.xml b/sale_financial_risk_exclude_order_type/views/sale_order_type_views.xml new file mode 100644 index 000000000..541f8e452 --- /dev/null +++ b/sale_financial_risk_exclude_order_type/views/sale_order_type_views.xml @@ -0,0 +1,21 @@ + + + + sale.order.type.form.sale.financial.risk.exclude.order.type + sale.order.type + + + + + + + + + + +