Skip to content

Commit

Permalink
Merge pull request #14 from sygel-technology/15.0-T-6536
Browse files Browse the repository at this point in the history
[T-6536][15.0][ADD]transfer_client_portfolio, transfer_client_portfolio_commissions: Add new modules
  • Loading branch information
ValentinVinagre authored Sep 25, 2024
2 parents f771883 + 4858ab3 commit 47d0e5f
Show file tree
Hide file tree
Showing 63 changed files with 2,807 additions and 35 deletions.
4 changes: 2 additions & 2 deletions crm_autoassign/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

==============
CRM Autoassign
Expand Down
1 change: 0 additions & 1 deletion crm_autoassign/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

from .post_install import post_init_hook
from . import models
from . import tests
7 changes: 4 additions & 3 deletions crm_autoassign/models/crm_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ def action_autoassign_opportunities(self):
action_id = self.env.ref("crm_autoassign.crm_autoassign_cron")
try:
self._cr.execute(
f"SELECT id FROM ir_cron WHERE id in ({action_id.id}) FOR UPDATE NOWAIT"
"SELECT id FROM ir_cron WHERE id IN %s FOR UPDATE NOWAIT",
(tuple([action_id.id])),
)
except psycopg2.OperationalError:
raise UserError(
_(
"Odoo is currently executing the planned action of opportunity"
" allocation. Please try again later."
)
)
) from UserError
for sel in self:
sel.env["crm.team.member"].action_autoassign_opportunities(sel)

Expand All @@ -58,7 +59,7 @@ def checks_team_leader(self):
"""
for sel in self.filtered(lambda x: x.user_id in x.member_ids):
if sel.crm_team_member_ids.filtered(
lambda x: x.user_id == sel.user_id
lambda x, sel=sel: x.user_id == sel.user_id
).autoassign_opportunities:
raise ValidationError(
_(
Expand Down
20 changes: 12 additions & 8 deletions crm_autoassign/models/crm_team_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class CrmTeamMember(models.Model):
_inherit = "crm.team.member"

assignment_optout = fields.Boolean(default=True)
autoassign_opportunities = fields.Boolean(
string="Autoassign Opportunities", default=False
)
assignment_days = fields.Integer(string="Assignement Days", default=0)
autoassign_opportunities = fields.Boolean(default=False)
assignment_days = fields.Integer(default=0)
max_assignment = fields.Integer(
string="Maximum number of assignments",
help="Maximum number of assignments in the last 'Assignment days'",
Expand Down Expand Up @@ -133,6 +131,11 @@ def action_autoassign_opportunities(self, team_id=None):
vals["stage_id"] = opportunity.team_id.stage_after_autoassign.id
opportunity.write(vals)
if auto_commit:
# cr.commit() is performed because:
# the changes are needed in the next iteration
# you can't wait for the system to do the save

# pylint: disable=invalid-commit
self._cr.commit()

@api.constrains("autoassign_opportunities")
Expand All @@ -145,8 +148,9 @@ def checks_team_manager(self):
):
raise ValidationError(
_(
"Member {} cannot autoassign opportunities because he is the "
"leader of team {}. The team leader's opportunities must be "
"assigned manually."
).format(sel.user_id.name, sel.crm_team_id.name)
"Member %(member_name)s cannot autoassign opportunities "
"because he is the leader of team %(team_name)s. "
"The team leader's opportunities must be assigned manually."
)
% {"member_name": sel.user_id.name, "team_name": sel.crm_team_id.name}
)
2 changes: 1 addition & 1 deletion crm_autoassign/tests/test_crm_atoassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TestCrmAutoassign(common.TransactionCase):

@classmethod
def setUpClass(cls):
super(TestCrmAutoassign, cls).setUpClass()
super().setUpClass()
cls.user_ids = cls.env["res.users"]
cls.team_ids = cls.env["crm.team"]
cls.member_ids = cls.env["crm.team.member"]
Expand Down
4 changes: 2 additions & 2 deletions crm_group_sale_salesman_extension/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

=================================
CRM Group Sale Salesman Extension
Expand Down
2 changes: 2 additions & 0 deletions crm_group_sale_salesman_extension/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2023 Ángel García de la Chica <angel.garcia@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3 changes: 3 additions & 0 deletions crm_group_sale_salesman_extension/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 2 additions & 2 deletions crm_sale_automatic_quotation/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

============================
CRM Sale Automatic Quotation
Expand Down
5 changes: 1 addition & 4 deletions crm_sale_automatic_quotation/data/mail_activity_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<!-- Copyright 2024 Alberto Martínez <alberto.martinez@sygel.es>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">
<record
id="crm_sale_automatic_quotation.review_activity"
model="mail.activity.type"
>
<record id="review_activity" model="mail.activity.type">
<field name="name">Review Automatic Quotation</field>
<field name="summary">Review Automatic Quotation</field>
<field name="category">default</field>
Expand Down
2 changes: 1 addition & 1 deletion crm_sale_automatic_quotation/models/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _action_generate_automatic_quotation(self, from_wizard=False):
quotation_id = res.create(vals_list)
# To update the quotation template fields in the quotation
quotation_id.with_context(
dict(self._context, is_crm_automatic_quotation=True)
**dict(self._context, is_crm_automatic_quotation=True)
).onchange_sale_order_template_id()
self._recompute_quotation_lines(quotation_id.order_line)
res |= quotation_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class CrmSaleAutomaticQuotationWizard(models.TransientModel):
_name = "crm.sale.automatic.quotation.wizard"

skip_quoted_leads = fields.Boolean(
string="Skip Quoted Leads",
default=True,
)
force_user_id = fields.Boolean(
Expand All @@ -26,11 +25,9 @@ class CrmSaleAutomaticQuotationWizard(models.TransientModel):
help="User that will send the email and have the quotation assigned",
)
send_mail = fields.Boolean(
string="Send Mail",
default=True,
)
email_template = fields.Many2one(
string="Email Template",
comodel_name="mail.template",
domain=lambda self: [
("model_id", "=", self.env.ref("sale.model_sale_order").id)
Expand Down Expand Up @@ -92,18 +89,22 @@ def _create_failed_lead_lines(self, lead_ids, error):
def _get_error_types(self):
# Filter Function, # Condition, # Error MSG
return [
(lambda l: not l.partner_id, True, _("The lead does not have a partner")),
(lambda li: not li.partner_id, True, _("The lead does not have a partner")),
(
lambda l: not l.partner_id.email,
lambda li: not li.partner_id.email,
self.send_mail,
_("The partner does not have an email"),
),
(
lambda l: l.order_ids.filtered(lambda o: o.state != "cancel"),
lambda li: li.order_ids.filtered(lambda o: o.state != "cancel"),
self.skip_quoted_leads,
_("The lead already has quotations"),
),
(lambda l: l.type in ["lead", False], True, _("The lead is in lead state")),
(
lambda li: li.type in ["lead", False],
True,
_("The lead is in lead state"),
),
]

def _filter_leads_and_classify_errors(self, lead_ids):
Expand Down Expand Up @@ -216,6 +217,5 @@ class CrmSaleAutomaticQuotationWizardLine(models.TransientModel):
comodel_name="crm.lead",
)
error = fields.Char(
string="Error",
readonly=True,
)
4 changes: 2 additions & 2 deletions crm_sale_automatic_quotation_asynchronous_wizard/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
:target: http://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

================================================
CRM Sale Automatic Quotation Asynchronous Wizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _send_mail(self, template, quote_ids):
channel="root.crm_sale_automatic_quotation_wizard_email"
)._delay_send_mail(template, quote_ids)
else:
super()._send_mail(template, quote_ids)
return super()._send_mail(template, quote_ids)

@api.model
def _delay_send_mail(self, template, quote_ids):
Expand Down
105 changes: 105 additions & 0 deletions transfer_client_portfolio/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
=========================
Transfer Client Portfolio
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:686d55876f432a62f5fe915046bf289eca0e9fe3cd9d2fe61284b747abc10eb5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-sygel--technology%2Fsy--crm-lightgray.png?logo=github
:target: https://github.com/sygel-technology/sy-crm/tree/15.0/transfer_client_portfolio
:alt: sygel-technology/sy-crm

|badge1| |badge2| |badge3|

This module allows to transfer contacts, activities and opportunities
from one user to another.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure if activities have to be transfered or not by default, you
need to:

1. Go to CRM -> Configuration -> CRM and check Transfer Activities
option.

To configure the stages of the opportunities that can be transferred,
you need to:

1. Go to CRM -> Configuration -> Stages
2. Enter the stages that you want to be transferable between users and
check the box "Allow transfer at this stage".

Usage
=====

To use this module, you need to:

Open the CRM application and then Go to Sales and click on 'Transfer
Customer Portfolio'. In the wizard select if you want to update the
salesperson on the contacts, the Current Salesperson' and the new
Salesperson. Click on review and select the contacts/opportunities you
want to transfer and click on transfer. Once they have been transferred
you can view the record in the 'Transfer Clients Portfolios' Reports
section. In addition, you can see the previous business in the client's
file and in the opportunity.

To use it with server action, you need to:

Open the CRM application and then Select the desired opportunities in
list mode and click on "Action" button and select "Transfer selected
opportunities". In the wizard select if you want to update the
salesperson on the contacts too and the new Salesperson. Select the
contacts/opportunities you want to transfer and click on transfer. One
they have been transferred you can view the Record and see the previous
salesperson in the 'Transfer Clients Portfolios'.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/sygel-technology/sy-crm/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 <https://github.com/sygel-technology/sy-crm/issues/new?body=module:%20transfer_client_portfolio%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Sygel

Contributors
------------

- Harald Panten harald.panten@sygel.es
- Valentin Vinagre valentin.vinagre@sygel.es
- Ángel García de la Chica Herrera angel.garcia@sygel.es
- Alberto Martínez alberto.martinez@sygel.es
- Roger Sans roger.sans@sygel.es

Maintainers
-----------

This module is part of the `sygel-technology/sy-crm <https://github.com/sygel-technology/sy-crm/tree/15.0/transfer_client_portfolio>`_ project on GitHub.

You are welcome to contribute.
5 changes: 5 additions & 0 deletions transfer_client_portfolio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2022 Ángel García de la Chica Herrera<angel.garcia@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from . import wizard
27 changes: 27 additions & 0 deletions transfer_client_portfolio/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022 Ángel García de la Chica <angel.garcia@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Transfer Client Portfolio",
"summary": "Transfer Client Portfolio Between Salespersons.",
"version": "15.0.1.2.0",
"category": "crm",
"website": "https://github.com/sygel-technology/sy-crm",
"author": "Sygel, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"crm",
],
"data": [
"security/res_groups.xml",
"security/ir.model.access.csv",
"views/res_partner_views.xml",
"views/crm_lead_views.xml",
"views/portfolio_transfer_registry_views.xml",
"views/crm_stage_views.xml",
"views/res_config_settings_view.xml",
"wizard/transfer_portfolio_wizard_views.xml",
],
}
Loading

0 comments on commit 47d0e5f

Please sign in to comment.