diff --git a/crm_sign_oca/README.rst b/crm_sign_oca/README.rst new file mode 100644 index 00000000..8f2dd5dd --- /dev/null +++ b/crm_sign_oca/README.rst @@ -0,0 +1,101 @@ +============ +Crm Sign Oca +============ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bb1c4c6fbebab88e825902a837740a7f427e1a789d7ab4bb41530fd27f6f35ed + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsign-lightgray.png?logo=github + :target: https://github.com/OCA/sign/tree/18.0/crm_sign_oca + :alt: OCA/sign +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sign-18-0/sign-18-0-crm_sign_oca + :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/sign&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module links the Sign app with the CRM. In this way, a document can +be sent for signature to the related partners in the CRM model, and the +signed documents will be linked to the corresponding CRM record. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module, you need to: + +- Go to Sign and create a sign template +- Go to Sign > Settings > Roles, create a role, set the "Partner + Selection Policy" to "Expression" and define an expression + +Usage +===== + +- Once you have configured the sign template for the CRM model as + explained in CONFIGURE.md, you can go to a CRM record, open it, and + click the gear button. + +- Select the option "Sign from template", choose the configured + template, and write a message for the signer. + +- The signer must log into the system and sign the request. + +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 +------- + +* Dixmit + +Contributors +------------ + +- `Dixmit `__: + + - Luis David Rodríguez + +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/sign `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/crm_sign_oca/__init__.py b/crm_sign_oca/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/crm_sign_oca/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/crm_sign_oca/__manifest__.py b/crm_sign_oca/__manifest__.py new file mode 100644 index 00000000..29f6417c --- /dev/null +++ b/crm_sign_oca/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Crm Sign Oca", + "summary": """CRM Sign OCA""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Dixmit,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sign", + "depends": [ + "sign_oca", + "crm", + ], + "data": [ + "views/crm_lead_views.xml", + "views/res_config_settings_view.xml", + "views/sign_oca_request.xml", + ], + "demo": ["demo/sign_oca_role.xml", "demo/sign_oca_template.xml"], +} diff --git a/crm_sign_oca/demo/sign_oca_role.xml b/crm_sign_oca/demo/sign_oca_role.xml new file mode 100644 index 00000000..9e9a6ac6 --- /dev/null +++ b/crm_sign_oca/demo/sign_oca_role.xml @@ -0,0 +1,8 @@ + + + + CRM Signatory Person + expression + {{object.user_id.partner_id.id}} + + diff --git a/crm_sign_oca/demo/sign_oca_template.xml b/crm_sign_oca/demo/sign_oca_template.xml new file mode 100644 index 00000000..713f620a --- /dev/null +++ b/crm_sign_oca/demo/sign_oca_template.xml @@ -0,0 +1,18 @@ + + + Crm + + + + + + + + 1 + 10 + 10 + 10 + 10 + + + diff --git a/crm_sign_oca/models/__init__.py b/crm_sign_oca/models/__init__.py new file mode 100644 index 00000000..c010adaf --- /dev/null +++ b/crm_sign_oca/models/__init__.py @@ -0,0 +1,4 @@ +from . import crm_lead +from . import res_company +from . import res_config_settings +from . import sign_oca_request diff --git a/crm_sign_oca/models/crm_lead.py b/crm_sign_oca/models/crm_lead.py new file mode 100644 index 00000000..7b5a1378 --- /dev/null +++ b/crm_sign_oca/models/crm_lead.py @@ -0,0 +1,49 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class CrmLead(models.Model): + _inherit = "crm.lead" + + sign_request_ids = fields.One2many( + comodel_name="sign.oca.request", + inverse_name="crm_lead_id", + string="Sign Requests", + ) + sign_request_count = fields.Integer( + string="Sign request count", + compute="_compute_sign_request_count", + compute_sudo=True, + store=True, + ) + + @api.depends("sign_request_ids") + def _compute_sign_request_count(self): + request_data = self.env["sign.oca.request"].read_group( + [("crm_lead_id", "in", self.ids)], + ["crm_lead_id"], + ["crm_lead_id"], + ) + mapped_data = { + x["crm_lead_id"][0]: x["crm_lead_id_count"] for x in request_data + } + for item in self: + item.sign_request_count = mapped_data.get(item.id, 0) + + def action_view_sign_requests(self): + self.ensure_one() + result = self.env["ir.actions.act_window"]._for_xml_id( + "sign_oca.sign_oca_request_act_window" + ) + result["domain"] = [("id", "in", self.sign_request_ids.ids)] + ctx = dict(self.env.context) + ctx.update( + { + "default_crm_lead_id": self.id, + "search_default_crm_lead_id": self.id, + } + ) + result["context"] = ctx + return result diff --git a/crm_sign_oca/models/res_company.py b/crm_sign_oca/models/res_company.py new file mode 100644 index 00000000..b4a33d33 --- /dev/null +++ b/crm_sign_oca/models/res_company.py @@ -0,0 +1,14 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + crm_lead_sign_oca_template_id = fields.Many2one( + comodel_name="sign.oca.template", + domain="[('model_id.model', '=', 'crm.lead')]", + string="Sign Oca Template", + ) diff --git a/crm_sign_oca/models/res_config_settings.py b/crm_sign_oca/models/res_config_settings.py new file mode 100644 index 00000000..912df701 --- /dev/null +++ b/crm_sign_oca/models/res_config_settings.py @@ -0,0 +1,15 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + crm_lead_sign_oca_template_id = fields.Many2one( + comodel_name="sign.oca.template", + related="company_id.crm_lead_sign_oca_template_id", + string="Sign Oca Template", + readonly=False, + ) diff --git a/crm_sign_oca/models/sign_oca_request.py b/crm_sign_oca/models/sign_oca_request.py new file mode 100644 index 00000000..7998b506 --- /dev/null +++ b/crm_sign_oca/models/sign_oca_request.py @@ -0,0 +1,24 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class SignOcaRequest(models.Model): + _inherit = "sign.oca.request" + + # This field is required for the inverse of crm.lead. + crm_lead_id = fields.Many2one( + comodel_name="crm.lead", + compute="_compute_crm_lead_id", + string="CRM Lead", + readonly=True, + store=True, + ) + + @api.depends("record_ref") + def _compute_crm_lead_id(self): + for item in self.filtered( + lambda x: x.record_ref and x.record_ref._name == "crm.lead" + ): + item.crm_lead_id = item.record_ref.id diff --git a/crm_sign_oca/pyproject.toml b/crm_sign_oca/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/crm_sign_oca/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/crm_sign_oca/readme/CONFIGURE.md b/crm_sign_oca/readme/CONFIGURE.md new file mode 100644 index 00000000..c63d5808 --- /dev/null +++ b/crm_sign_oca/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +To configure this module, you need to: + +- Go to Sign and create a sign template +- Go to Sign > Settings > Roles, create a role, set the "Partner Selection Policy" to "Expression" and define an expression diff --git a/crm_sign_oca/readme/CONTRIBUTORS.md b/crm_sign_oca/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..7ac8d4cc --- /dev/null +++ b/crm_sign_oca/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Dixmit](https://dixmit.com): + - Luis David Rodríguez \<\> diff --git a/crm_sign_oca/readme/DESCRIPTION.md b/crm_sign_oca/readme/DESCRIPTION.md new file mode 100644 index 00000000..f6fcaff9 --- /dev/null +++ b/crm_sign_oca/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module links the Sign app with the CRM. In this way, a document can be sent for signature to the related partners in the CRM model, and the signed documents will be linked to the corresponding CRM record. \ No newline at end of file diff --git a/crm_sign_oca/readme/USAGE.md b/crm_sign_oca/readme/USAGE.md new file mode 100644 index 00000000..3e964565 --- /dev/null +++ b/crm_sign_oca/readme/USAGE.md @@ -0,0 +1,5 @@ +- Once you have configured the sign template for the CRM model as explained in CONFIGURE.md, you can go to a CRM record, open it, and click the gear button. + +- Select the option "Sign from template", choose the configured template, and write a message for the signer. + +- The signer must log into the system and sign the request. \ No newline at end of file diff --git a/crm_sign_oca/static/description/icon.png b/crm_sign_oca/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/crm_sign_oca/static/description/icon.png differ diff --git a/crm_sign_oca/static/description/index.html b/crm_sign_oca/static/description/index.html new file mode 100644 index 00000000..57b12fcc --- /dev/null +++ b/crm_sign_oca/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +Crm Sign Oca + + + +
+

Crm Sign Oca

+ + +

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

+

This module links the Sign app with the CRM. In this way, a document can +be sent for signature to the related partners in the CRM model, and the +signed documents will be linked to the corresponding CRM record.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  • Go to Sign and create a sign template
  • +
  • Go to Sign > Settings > Roles, create a role, set the “Partner +Selection Policy” to “Expression” and define an expression
  • +
+
+
+

Usage

+
    +
  • Once you have configured the sign template for the CRM model as +explained in CONFIGURE.md, you can go to a CRM record, open it, and +click the gear button.
  • +
  • Select the option “Sign from template”, choose the configured +template, and write a message for the signer.
  • +
  • The signer must log into the system and sign the request.
  • +
+
+
+

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

+
    +
  • Dixmit
  • +
+
+
+

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

+

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

+
+
+
+ + diff --git a/crm_sign_oca/tests/__init__.py b/crm_sign_oca/tests/__init__.py new file mode 100644 index 00000000..2bdbfc56 --- /dev/null +++ b/crm_sign_oca/tests/__init__.py @@ -0,0 +1 @@ +from . import test_crm_sign_oca diff --git a/crm_sign_oca/tests/test_crm_sign_oca.py b/crm_sign_oca/tests/test_crm_sign_oca.py new file mode 100644 index 00000000..93940b9a --- /dev/null +++ b/crm_sign_oca/tests/test_crm_sign_oca.py @@ -0,0 +1,70 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo.addons.base.tests.common import BaseCommon + + +class TestCRMSignOca(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company = cls.env.company + cls.template = cls.env.ref("crm_sign_oca.sign_oca_template_crm_lead_demo") + cls.crm_a = ( + cls.env["crm.lead"] + .with_user(cls.env.uid) + .create({"name": "Test CRM A", "user_id": cls.env.uid}) + ) + + def test_action_send_signed_request(self): + """Test that when a request is signed""" + + crm_role = self.env.ref("crm_sign_oca.role_crm_signer") + + sign_request = self.env["sign.oca.request"].create( + { + "name": "Signed CRM A.pdf", + "record_ref": f"crm.lead,{self.crm_a.id}", + "state": "0_sent", + "signer_ids": [ + ( + 0, + 0, + { + "role_id": crm_role.id, + "partner_id": self.env.user.partner_id.id, + }, + ), + ], + } + ) + + # Simulate signing + for signer in sign_request.signer_ids: + signer.signed_on = "2025-01-01 12:00:00" + sign_request.state = "2_signed" + + sign_request.action_send_signed_request() + + self.assertEqual( + sign_request.signer_id.partner_id.id, self.env.user.partner_id.id + ) + self.assertEqual(sign_request.state, "2_signed") + self.assertEqual( + f"{sign_request.record_ref._name},{sign_request.record_ref.id}", + f"crm.lead,{self.crm_a.id}", + ) + + def test_action_send_signed_request_state_not_signed(self): + """Test that crm is not updated if request is not signed.""" + sign_request = self.env["sign.oca.request"].create( + { + "name": "Test.pdf", + "record_ref": f"crm.lead,{self.crm_a.id}", + "state": "0_sent", # Not signed + } + ) + sign_request.action_send_signed_request() + + self.assertFalse(sign_request.signer_id) diff --git a/crm_sign_oca/views/crm_lead_views.xml b/crm_sign_oca/views/crm_lead_views.xml new file mode 100644 index 00000000..f9d9360f --- /dev/null +++ b/crm_sign_oca/views/crm_lead_views.xml @@ -0,0 +1,32 @@ + + + + crm.lead.form + crm.lead + + + + + + + + diff --git a/crm_sign_oca/views/res_config_settings_view.xml b/crm_sign_oca/views/res_config_settings_view.xml new file mode 100644 index 00000000..5d3b7281 --- /dev/null +++ b/crm_sign_oca/views/res_config_settings_view.xml @@ -0,0 +1,18 @@ + + + + + res.config.settings + + + + + + + + + + + + diff --git a/crm_sign_oca/views/sign_oca_request.xml b/crm_sign_oca/views/sign_oca_request.xml new file mode 100644 index 00000000..3a1e899c --- /dev/null +++ b/crm_sign_oca/views/sign_oca_request.xml @@ -0,0 +1,21 @@ + + + + sign.oca.request.search + sign.oca.request + + + + + + + + + + +