diff --git a/crm_salesperson_planner_sale/README.rst b/crm_salesperson_planner_sale/README.rst new file mode 100644 index 00000000000..9cd7f59e7cb --- /dev/null +++ b/crm_salesperson_planner_sale/README.rst @@ -0,0 +1,96 @@ +============================ +Crm Salesperson Planner Sale +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c9fb35c0e00b295b492cd7e894041986aa3304d7ec4a1affe6042381193bf329 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fcrm-lightgray.png?logo=github + :target: https://github.com/OCA/crm/tree/16.0/crm_salesperson_planner_sale + :alt: OCA/crm +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/crm-16-0/crm-16-0-crm_salesperson_planner_sale + :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/crm&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to manage sales from commercial visits. +You can create Sales Quotations from visits and check the related ones. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Go to any "Validated" or "Visited" visit. +* Click "New Quotation" button or click in the smart button "Quotation" and create a quotation. + +In the Quotation or Sale Order you will have a new field that is related to the salesperson visit. + +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 +~~~~~~~ + +* Sygel Technology +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Sygel `__: + + * Valentin Vinagre + +* `Tecnativa `_: + + * Víctor Martínez + +* `Pesol `__: + + * Gerardo Marin Parra + +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/crm `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/crm_salesperson_planner_sale/__init__.py b/crm_salesperson_planner_sale/__init__.py new file mode 100644 index 00000000000..759f62baf66 --- /dev/null +++ b/crm_salesperson_planner_sale/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2021 Sygel - Valentin Vinagre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import models diff --git a/crm_salesperson_planner_sale/__manifest__.py b/crm_salesperson_planner_sale/__manifest__.py new file mode 100644 index 00000000000..8f91b7f6dc0 --- /dev/null +++ b/crm_salesperson_planner_sale/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2021 Sygel - Valentin Vinagre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +{ + "name": "Crm Salesperson Planner Sale", + "version": "16.0.1.0.0", + "development_status": "Beta", + "category": "Customer Relationship Management", + "author": "Sygel Technology, Tecnativa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/crm", + "license": "AGPL-3", + "depends": ["crm_salesperson_planner", "sale"], + "data": [ + "views/sale_order_views.xml", + "views/crm_salesperson_planner_visit_views.xml", + ], + "installable": True, +} diff --git a/crm_salesperson_planner_sale/i18n/crm_salesperson_planner_sale.pot b/crm_salesperson_planner_sale/i18n/crm_salesperson_planner_sale.pot new file mode 100644 index 00000000000..f9db67fdcc5 --- /dev/null +++ b/crm_salesperson_planner_sale/i18n/crm_salesperson_planner_sale.pot @@ -0,0 +1,60 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_salesperson_planner_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \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: crm_salesperson_planner_sale +#: model_terms:ir.ui.view,arch_db:crm_salesperson_planner_sale.crm_salesperson_planner_visit_sale_form_view +msgid "New Quotation" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_crm_salesperson_planner_visit__quotation_count +msgid "Number of Quotations" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_crm_salesperson_planner_visit__sale_order_count +msgid "Number of Sale Orders" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_crm_salesperson_planner_visit__order_ids +#: model_terms:ir.ui.view,arch_db:crm_salesperson_planner_sale.crm_salesperson_planner_visit_sale_form_view +msgid "Orders" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model:ir.actions.act_window,name:crm_salesperson_planner_sale.crm_salesperson_visit_action_quotation_new +msgid "Quotation" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model_terms:ir.ui.view,arch_db:crm_salesperson_planner_sale.crm_salesperson_planner_visit_sale_form_view +msgid "Quotations" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model:ir.model,name:crm_salesperson_planner_sale.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model:ir.model,name:crm_salesperson_planner_sale.model_crm_salesperson_planner_visit +msgid "Salesperson Planner Visit" +msgstr "" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_sale_order__visit_id +msgid "Visit" +msgstr "" diff --git a/crm_salesperson_planner_sale/i18n/es.po b/crm_salesperson_planner_sale/i18n/es.po new file mode 100644 index 00000000000..118efb38a9a --- /dev/null +++ b/crm_salesperson_planner_sale/i18n/es.po @@ -0,0 +1,64 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_salesperson_planner_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-11-30 13:07+0000\n" +"PO-Revision-Date: 2022-11-30 14:07+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: crm_salesperson_planner_sale +#: model_terms:ir.ui.view,arch_db:crm_salesperson_planner_sale.crm_salesperson_planner_visit_sale_form_view +msgid "New Quotation" +msgstr "Nuevo presupuesto" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_crm_salesperson_planner_visit__quotation_count +msgid "Number of Quotations" +msgstr "Nº de presupuestos" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_crm_salesperson_planner_visit__sale_order_count +msgid "Number of Sale Orders" +msgstr "Nº de ordenes de venta" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_crm_salesperson_planner_visit__order_ids +#: model_terms:ir.ui.view,arch_db:crm_salesperson_planner_sale.crm_salesperson_planner_visit_sale_form_view +msgid "Orders" +msgstr "Ventas" + +#. module: crm_salesperson_planner_sale +#: model:ir.actions.act_window,name:crm_salesperson_planner_sale.crm_salesperson_visit_action_quotation_new +msgid "Quotation" +msgstr "Presupuesto" + +#. module: crm_salesperson_planner_sale +#: model_terms:ir.ui.view,arch_db:crm_salesperson_planner_sale.crm_salesperson_planner_visit_sale_form_view +msgid "Quotations" +msgstr "Presupuestos" + +#. module: crm_salesperson_planner_sale +#: model:ir.model,name:crm_salesperson_planner_sale.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" + +#. module: crm_salesperson_planner_sale +#: model:ir.model,name:crm_salesperson_planner_sale.model_crm_salesperson_planner_visit +msgid "Salesperson Planner Visit" +msgstr "Planificador de visitas comerciales" + +#. module: crm_salesperson_planner_sale +#: model:ir.model.fields,field_description:crm_salesperson_planner_sale.field_sale_order__visit_id +msgid "Visit" +msgstr "Visita" diff --git a/crm_salesperson_planner_sale/models/__init__.py b/crm_salesperson_planner_sale/models/__init__.py new file mode 100644 index 00000000000..a31c8735e48 --- /dev/null +++ b/crm_salesperson_planner_sale/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2021 Sygel - Valentin Vinagre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import sale_order +from . import crm_salesperson_planner_visit diff --git a/crm_salesperson_planner_sale/models/crm_salesperson_planner_visit.py b/crm_salesperson_planner_sale/models/crm_salesperson_planner_visit.py new file mode 100644 index 00000000000..cf0d9c6f384 --- /dev/null +++ b/crm_salesperson_planner_sale/models/crm_salesperson_planner_visit.py @@ -0,0 +1,90 @@ +# Copyright 2021 Sygel - Valentin Vinagre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import api, fields, models + + +class CrmSalespersonPlannerVisit(models.Model): + _inherit = "crm.salesperson.planner.visit" + + order_ids = fields.One2many("sale.order", "visit_id", string="Orders") + sale_order_count = fields.Integer( + compute="_compute_sale_data", string="Number of Sale Orders", store=True + ) + quotation_count = fields.Integer( + compute="_compute_sale_data", string="Number of Quotations", store=True + ) + + @api.depends("order_ids.state") + def _compute_sale_data(self): + quotation_domain = [ + ("visit_id", "in", self.ids), + ("state", "in", ("draft", "sent")), + ] + quotation_data = self.env["sale.order"].read_group( + domain=quotation_domain, fields=["visit_id"], groupby=["visit_id"] + ) + sale_domain = [ + ("visit_id", "in", self.ids), + ("state", "not in", ("draft", "sent", "cancel")), + ] + sale_data = self.env["sale.order"].read_group( + domain=sale_domain, fields=["visit_id"], groupby=["visit_id"] + ) + mapped_quotation_data = { + m["visit_id"][0]: m["visit_id_count"] for m in quotation_data + } + mapped_sale_data = {m["visit_id"][0]: m["visit_id_count"] for m in sale_data} + for sel in self: + sel.quotation_count = mapped_quotation_data.get(sel.id, 0) + sel.sale_order_count = mapped_sale_data.get(sel.id, 0) + + def _prepare_context_from_action(self): + return { + "search_default_visit_id": self.id, + "default_visit_id": self.id, + "search_default_partner_id": self.partner_id.commercial_partner_id.id, + "default_partner_id": self.partner_id.commercial_partner_id.id, + "default_origin": self.name, + "default_company_id": self.company_id.id or self.env.company.id, + "default_user_id": self.user_id.id, + } + + def action_sale_quotation_new(self): + action = self.env["ir.actions.act_window"]._for_xml_id( + "crm_salesperson_planner_sale.crm_salesperson_visit_action_quotation_new" + ) + action["context"] = self._prepare_context_from_action() + return action + + def action_view_sale_quotation(self): + action = self.env["ir.actions.act_window"]._for_xml_id( + "sale.action_quotations_with_onboarding" + ) + ctx = self._prepare_context_from_action() + ctx.update(search_default_draft=1) + action["context"] = ctx + action["domain"] = [ + ("visit_id", "=", self.id), + ("state", "in", ("draft", "sent")), + ] + if self.quotation_count == 1: + action["views"] = [(self.env.ref("sale.view_order_form").id, "form")] + quotation = self.order_ids.filtered(lambda l: l.state in ("draft", "sent")) + action["res_id"] = quotation.id + return action + + def action_view_sale_order(self): + action = self.env["ir.actions.act_window"]._for_xml_id("sale.action_orders") + action["context"] = self._prepare_context_from_action() + action["domain"] = [ + ("visit_id", "=", self.id), + ("state", "not in", ("draft", "sent", "cancel")), + ] + if self.sale_order_count == 1: + action["views"] = [(self.env.ref("sale.view_order_form").id, "form")] + order = self.order_ids.filtered( + lambda l: l.state not in ("draft", "sent", "cancel") + ) + action["res_id"] = order.id + return action diff --git a/crm_salesperson_planner_sale/models/sale_order.py b/crm_salesperson_planner_sale/models/sale_order.py new file mode 100644 index 00000000000..689d65c7bbe --- /dev/null +++ b/crm_salesperson_planner_sale/models/sale_order.py @@ -0,0 +1,16 @@ +# Copyright 2021 Sygel - Valentin Vinagre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + visit_id = fields.Many2one( + comodel_name="crm.salesperson.planner.visit", + string="Visit", + check_company=True, + domain="[('partner_id', 'child_of', partner_id)," + " '|', ('company_id', '=', False), ('company_id', '=', company_id)]", + ) diff --git a/crm_salesperson_planner_sale/readme/CONTRIBUTORS.rst b/crm_salesperson_planner_sale/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..a3926a4ed47 --- /dev/null +++ b/crm_salesperson_planner_sale/readme/CONTRIBUTORS.rst @@ -0,0 +1,11 @@ +* `Sygel `__: + + * Valentin Vinagre + +* `Tecnativa `_: + + * Víctor Martínez + +* `Pesol `__: + + * Gerardo Marin Parra diff --git a/crm_salesperson_planner_sale/readme/DESCRIPTION.rst b/crm_salesperson_planner_sale/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..f5bdb9a1704 --- /dev/null +++ b/crm_salesperson_planner_sale/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows you to manage sales from commercial visits. +You can create Sales Quotations from visits and check the related ones. diff --git a/crm_salesperson_planner_sale/readme/USAGE.rst b/crm_salesperson_planner_sale/readme/USAGE.rst new file mode 100644 index 00000000000..4d4afa6bdd9 --- /dev/null +++ b/crm_salesperson_planner_sale/readme/USAGE.rst @@ -0,0 +1,4 @@ +* Go to any "Validated" or "Visited" visit. +* Click "New Quotation" button or click in the smart button "Quotation" and create a quotation. + +In the Quotation or Sale Order you will have a new field that is related to the salesperson visit. diff --git a/crm_salesperson_planner_sale/static/description/icon.png b/crm_salesperson_planner_sale/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/crm_salesperson_planner_sale/static/description/icon.png differ diff --git a/crm_salesperson_planner_sale/static/description/index.html b/crm_salesperson_planner_sale/static/description/index.html new file mode 100644 index 00000000000..769bc9283f6 --- /dev/null +++ b/crm_salesperson_planner_sale/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Crm Salesperson Planner Sale + + + +
+

Crm Salesperson Planner Sale

+ + +

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

+

This module allows you to manage sales from commercial visits. +You can create Sales Quotations from visits and check the related ones.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to any “Validated” or “Visited” visit.
  • +
  • Click “New Quotation” button or click in the smart button “Quotation” and create a quotation.
  • +
+

In the Quotation or Sale Order you will have a new field that is related to the salesperson visit.

+
+
+

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

+
    +
  • Sygel Technology
  • +
  • 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/crm project on GitHub.

+

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

+
+
+
+ + diff --git a/crm_salesperson_planner_sale/tests/__init__.py b/crm_salesperson_planner_sale/tests/__init__.py new file mode 100644 index 00000000000..cfc5d31d30e --- /dev/null +++ b/crm_salesperson_planner_sale/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import test_crm_salesperson_planner_sale diff --git a/crm_salesperson_planner_sale/tests/test_crm_salesperson_planner_sale.py b/crm_salesperson_planner_sale/tests/test_crm_salesperson_planner_sale.py new file mode 100644 index 00000000000..213e97919f2 --- /dev/null +++ b/crm_salesperson_planner_sale/tests/test_crm_salesperson_planner_sale.py @@ -0,0 +1,32 @@ +# Copyright 2022 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from odoo.tests import Form + +from odoo.addons.crm_salesperson_planner.tests.test_crm_salesperson_planner_visit import ( + TestCrmSalespersonPlannerVisitBase, +) + + +class TestCrmSalespersonPlannerSale(TestCrmSalespersonPlannerVisitBase): + def _create_sale_order_from_visit(self, visit): + res = self.visit1.action_sale_quotation_new() + order_form = Form(self.env[res["res_model"]].with_context(**res["context"])) + return order_form.save() + + def test_visit_process(self): + self.assertFalse(self.visit1.order_ids) + order = self._create_sale_order_from_visit(self.visit1) + self.assertEqual(order.visit_id, self.visit1) + self.assertIn(order, self.visit1.order_ids) + self.assertEqual(self.visit1.sale_order_count, 0) + self.assertEqual(self.visit1.quotation_count, 1) + res = self.visit1.action_view_sale_quotation() + self.assertIn(order, self.env[res["res_model"]].search(res["domain"])) + self.assertEqual(res["res_id"], order.id) + order.write({"state": "sale"}) + self.assertEqual(self.visit1.sale_order_count, 1) + self.assertEqual(self.visit1.quotation_count, 0) + res = self.visit1.action_view_sale_order() + self.assertIn(order, self.env[res["res_model"]].search(res["domain"])) + self.assertEqual(res["res_id"], order.id) diff --git a/crm_salesperson_planner_sale/views/crm_salesperson_planner_visit_views.xml b/crm_salesperson_planner_sale/views/crm_salesperson_planner_visit_views.xml new file mode 100644 index 00000000000..4907befdda6 --- /dev/null +++ b/crm_salesperson_planner_sale/views/crm_salesperson_planner_visit_views.xml @@ -0,0 +1,60 @@ + + + + + Crm Salesperson Planner Visit Sale Form View + crm.salesperson.planner.visit + + +
+
+ + + + +
+
+ + Quotation + sale.order + form,tree,graph + [('visit_id', '=', active_id)] + {'search_default_visit_id': active_id, 'default_visit_id': active_id} + +
diff --git a/crm_salesperson_planner_sale/views/sale_order_views.xml b/crm_salesperson_planner_sale/views/sale_order_views.xml new file mode 100644 index 00000000000..5f64c1975ec --- /dev/null +++ b/crm_salesperson_planner_sale/views/sale_order_views.xml @@ -0,0 +1,15 @@ + + + + + crm.salesperson.planner.sale.view.order.form + sale.order + + + + + + + + diff --git a/setup/crm_salesperson_planner_sale/odoo/addons/crm_salesperson_planner_sale b/setup/crm_salesperson_planner_sale/odoo/addons/crm_salesperson_planner_sale new file mode 120000 index 00000000000..ca5f6d96fae --- /dev/null +++ b/setup/crm_salesperson_planner_sale/odoo/addons/crm_salesperson_planner_sale @@ -0,0 +1 @@ +../../../../crm_salesperson_planner_sale \ No newline at end of file diff --git a/setup/crm_salesperson_planner_sale/setup.py b/setup/crm_salesperson_planner_sale/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/crm_salesperson_planner_sale/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)