diff --git a/sale_crm_team_invoiced_payment_state/README.rst b/sale_crm_team_invoiced_payment_state/README.rst new file mode 100644 index 00000000000..44efda2c4bf --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/README.rst @@ -0,0 +1,85 @@ +==================================== +Sale Crm Team Invoiced Payment State +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9fe69c9c1ff84c38afea407ccd42ec9d41b253d8d64454832b89c6e912d4289b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/15.0/sale_crm_team_invoiced_payment_state + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_crm_team_invoiced_payment_state + :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/sale-workflow&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Extends CRM Teams to filter invoiced amounts by payment status. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Navigate to **CRM** > **Configuration** > **Settings**. +3. In the Settings view, go to **Team Invoiced Domain** block. +4. Select the desired **Payment Status** to calculate the team's **Invoiced Amount**. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +- [Tecnativa](https://www.tecnativa.com): + - Sergio Teruel + - Juan Carlos Oñate + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_crm_team_invoiced_payment_state/__init__.py b/sale_crm_team_invoiced_payment_state/__init__.py new file mode 100644 index 00000000000..9186ee3ad24 --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/__init__.py @@ -0,0 +1 @@ +from . import model diff --git a/sale_crm_team_invoiced_payment_state/__manifest__.py b/sale_crm_team_invoiced_payment_state/__manifest__.py new file mode 100644 index 00000000000..32f0fea46c2 --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2025 Tecnativa - Juan Carlos Oñate +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Crm Team Invoiced Payment State", + "version": "15.0.1.0.0", + "author": "Tecnativa," "Odoo Community Association (OCA)", + "category": "Sale", + "license": "AGPL-3", + "website": "https://github.com/OCA/sale-workflow", + "depends": ["sale", "crm"], + "data": [ + "views/res_config_settings_views.xml", + ], + "installable": True, +} diff --git a/sale_crm_team_invoiced_payment_state/model/__init__.py b/sale_crm_team_invoiced_payment_state/model/__init__.py new file mode 100644 index 00000000000..7e87cb357cb --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/model/__init__.py @@ -0,0 +1,3 @@ +from . import crm_team +from . import res_company +from . import res_config_settings diff --git a/sale_crm_team_invoiced_payment_state/model/crm_team.py b/sale_crm_team_invoiced_payment_state/model/crm_team.py new file mode 100644 index 00000000000..35c0402a89b --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/model/crm_team.py @@ -0,0 +1,31 @@ +import ast + +from odoo import fields, models +from odoo.osv import expression + + +class CrmTeam(models.Model): + _inherit = "crm.team" + + def _compute_invoiced(self): + if not self: + return + + crm_team_invoiced_domain = self.env.company.crm_team_invoiced_domain + if not crm_team_invoiced_domain: + return super(CrmTeam, self)._compute_invoiced() + today = fields.Date.today() + invoiced_domain = [ + ("move_type", "in", ["out_invoice", "out_refund", "out_receipt"]), + ("team_id", "in", self.ids), + ("date", ">=", fields.Date.to_string(today.replace(day=1))), + ("date", "<=", fields.Date.to_string(today)), + ] + domain_list = ast.literal_eval(crm_team_invoiced_domain) + invoiced_domain = expression.AND([invoiced_domain, domain_list]) + for team in self: + team.invoiced = 0.0 + moves = self.env["account.move"].search(invoiced_domain) + for move in moves: + if move.team_id == team: + team.invoiced += move.amount_untaxed_signed diff --git a/sale_crm_team_invoiced_payment_state/model/res_company.py b/sale_crm_team_invoiced_payment_state/model/res_company.py new file mode 100644 index 00000000000..0a18b46a243 --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/model/res_company.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + crm_team_invoiced_domain = fields.Char( + default="['|', '|', " + "['payment_state', '=', 'in_payment'], " + "['payment_state', '=', 'paid'], " + "['payment_state', '=', 'reversed']]" + ) diff --git a/sale_crm_team_invoiced_payment_state/model/res_config_settings.py b/sale_crm_team_invoiced_payment_state/model/res_config_settings.py new file mode 100644 index 00000000000..acb72dc784d --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/model/res_config_settings.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + crm_team_invoiced_domain = fields.Char( + related="company_id.crm_team_invoiced_domain", readonly=False + ) diff --git a/sale_crm_team_invoiced_payment_state/readme/CONTRIBUTORS.rst b/sale_crm_team_invoiced_payment_state/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..b4926ff488d --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com): + - Sergio Teruel + - Juan Carlos Oñate diff --git a/sale_crm_team_invoiced_payment_state/readme/DESCRIPTION.rst b/sale_crm_team_invoiced_payment_state/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..c6d528ed13d --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Extends CRM Teams to filter invoiced amounts by payment status. diff --git a/sale_crm_team_invoiced_payment_state/readme/USAGE.rst b/sale_crm_team_invoiced_payment_state/readme/USAGE.rst new file mode 100644 index 00000000000..db903ef2176 --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/readme/USAGE.rst @@ -0,0 +1,3 @@ +1. Navigate to **CRM** > **Configuration** > **Settings**. +3. In the Settings view, go to **Team Invoiced Domain** block. +4. Select the desired **Payment Status** to calculate the team's **Invoiced Amount**. diff --git a/sale_crm_team_invoiced_payment_state/static/description/icon.png b/sale_crm_team_invoiced_payment_state/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_crm_team_invoiced_payment_state/static/description/icon.png differ diff --git a/sale_crm_team_invoiced_payment_state/static/description/index.html b/sale_crm_team_invoiced_payment_state/static/description/index.html new file mode 100644 index 00000000000..2a9d8c07806 --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/static/description/index.html @@ -0,0 +1,432 @@ + + + + + +Sale Crm Team Invoiced Payment State + + + +
+

Sale Crm Team Invoiced Payment State

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

Extends CRM Teams to filter invoiced amounts by payment status.

+

Table of contents

+ +
+

Usage

+

1. Navigate to CRM > Configuration > Settings. +3. In the Settings view, go to Team Invoiced Domain block. +4. Select the desired Payment Status to calculate the team’s Invoiced Amount.

+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

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/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_crm_team_invoiced_payment_state/tests/__init__.py b/sale_crm_team_invoiced_payment_state/tests/__init__.py new file mode 100644 index 00000000000..61bc9b2fdea --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/tests/__init__.py @@ -0,0 +1 @@ +from . import test_crm_team diff --git a/sale_crm_team_invoiced_payment_state/tests/test_crm_team.py b/sale_crm_team_invoiced_payment_state/tests/test_crm_team.py new file mode 100644 index 00000000000..b67051e21b4 --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/tests/test_crm_team.py @@ -0,0 +1,84 @@ +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestCrmTeamInvoiced(TransactionCase): + def setUp(self): + super(TestCrmTeamInvoiced, self).setUp() + self.team = self.env["crm.team"].create({"name": "Test Team"}) + self.team2 = self.env["crm.team"].create({"name": "Test Team 2"}) + self.partner_id = self.env["res.partner"].create({"name": "Test Partner"}) + + def create_account_move(self, team_id, payment_state_code, amount): + move = self.env["account.move"].create( + { + "move_type": "out_invoice", + "team_id": team_id.id, + "date": fields.Date.today(), + "amount_untaxed_signed": amount, + "payment_state": payment_state_code, + "partner_id": self.partner_id.id, + "invoice_line_ids": [ + (0, 0, {"name": "Test Line", "quantity": 1, "price_unit": amount}) + ], + } + ) + move.action_post() + return move + + def test_compute_invoiced_multiple_teams_with_all_payment_states(self): + payment_states = ["not_paid", "in_payment", "paid", "partial", "reversed"] + self.env.company.crm_team_invoiced_domain = str( + [("payment_state", "in", payment_states)] + ) + for state in payment_states: + self.create_account_move(self.team, state, 100) + self.create_account_move(self.team2, state, 50) + (self.team + self.team2)._compute_invoiced() + self.assertEqual(self.team.invoiced, 500.0) + self.assertEqual(self.team2.invoiced, 250.0) + + def test_compute_invoiced_empty_domain(self): + self.env.company.crm_team_invoiced_domain = "[]" + self.create_account_move(self.team, "paid", 100) + self.create_account_move(self.team2, "paid", 50) + (self.team + self.team2)._compute_invoiced() + expected_team_invoiced = sum( + self.env["account.move"] + .search( + [ + ("move_type", "in", ("out_invoice", "out_refund", "out_receipt")), + ("team_id", "=", self.team.id), + ( + "date", + ">=", + fields.Date.to_string(fields.Date.today().replace(day=1)), + ), + ("date", "<=", fields.Date.to_string(fields.Date.today())), + ] + ) + .mapped("amount_untaxed_signed") + ) + expected_team2_invoiced = sum( + self.env["account.move"] + .search( + [ + ("move_type", "in", ("out_invoice", "out_refund", "out_receipt")), + ("team_id", "=", self.team2.id), + ( + "date", + ">=", + fields.Date.to_string(fields.Date.today().replace(day=1)), + ), + ("date", "<=", fields.Date.to_string(fields.Date.today())), + ] + ) + .mapped("amount_untaxed_signed") + ) + self.assertEqual(self.team.invoiced, expected_team_invoiced) + self.assertEqual(self.team2.invoiced, expected_team2_invoiced) + + def test_compute_invoiced_invalid_domain(self): + self.env.company.crm_team_invoiced_domain = "invaid domain" + with self.assertRaises(SyntaxError): + (self.team + self.team2)._compute_invoiced() diff --git a/sale_crm_team_invoiced_payment_state/views/res_config_settings_views.xml b/sale_crm_team_invoiced_payment_state/views/res_config_settings_views.xml new file mode 100644 index 00000000000..9bd7f22ebfc --- /dev/null +++ b/sale_crm_team_invoiced_payment_state/views/res_config_settings_views.xml @@ -0,0 +1,34 @@ + + + + res.config.settings + + + +

Team Invoiced Domain

+
+
+
+
+
+
+
+
diff --git a/setup/sale_crm_team_invoiced_payment_state/odoo/addons/sale_crm_team_invoiced_payment_state b/setup/sale_crm_team_invoiced_payment_state/odoo/addons/sale_crm_team_invoiced_payment_state new file mode 120000 index 00000000000..d86e76de892 --- /dev/null +++ b/setup/sale_crm_team_invoiced_payment_state/odoo/addons/sale_crm_team_invoiced_payment_state @@ -0,0 +1 @@ +../../../../sale_crm_team_invoiced_payment_state \ No newline at end of file diff --git a/setup/sale_crm_team_invoiced_payment_state/setup.py b/setup/sale_crm_team_invoiced_payment_state/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/sale_crm_team_invoiced_payment_state/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)