Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions srm/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===
SRM
===

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6e6380a8b3a6c8aa36be3cb6861a190da89e603afaa94e6c982b505f29c5e56f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/license-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/19.0/srm
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-19-0/crm-19-0-srm
: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=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows the usage of crm module to manage leads coming from
suppliers. The flow is similar to CRM. The main change is that leads be
generated from customer or supplier request type. For supplier requests
leads can be converted in purchases.

.. 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 <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/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/OCA/crm/issues/new?body=module:%20srm%0Aversion:%2019.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
-------

* Camptocamp

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

- Telmo Santos <telmo.santos@camptocamp.com>
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>

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 <https://github.com/OCA/crm/tree/19.0/srm>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions srm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
28 changes: 28 additions & 0 deletions srm/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "SRM",
"summary": "Use CRM model for suppliers",
"version": "19.0.1.0.0",
"development_status": "Alpha",
"category": "CRM",
"website": "https://github.com/OCA/crm",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"account",
"crm",
"sale_crm",
"purchase",
],
"data": [
"security/ir.model.access.csv",
"views/srm_menu.xml",
"views/srm_lead.xml",
"views/crm_lead.xml",
"views/purchase_order.xml",
"wizard/srm_opportunity_to_rfq.xml",
],
"installable": True,
}
3 changes: 3 additions & 0 deletions srm/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import crm_lead
from . import crm_team
from . import purchase_order
147 changes: 147 additions & 0 deletions srm/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from collections import defaultdict

from odoo import api, fields, models
from odoo.fields import Domain


class CrmLead(models.Model):
_inherit = "crm.lead"

user_id = fields.Many2one(string="Responsible")
team_id = fields.Many2one(string="Team")

request_type = fields.Selection(
selection=[
("customer", "Customer Lead"),
("supplier", "Supplier Lead"),
],
)
purchase_amount_total = fields.Monetary(
compute="_compute_purchase_amount_total",
string="Sum of Purchase Orders",
help="Untaxed Total of Confirmed Purchase Orders",
currency_field="company_currency",
)
request_for_quotation_count = fields.Integer(
compute="_compute_request_for_quotation_count",
string="Number of Request for Quotations",
)
purchase_order_count = fields.Integer(
compute="_compute_purchase_order_count", string="Number of Purchase Orders"
)
purchase_order_ids = fields.One2many(
comodel_name="purchase.order",
inverse_name="opportunity_id",
string="Purchase Orders",
)

def _get_lead_purchase_order_domain(self):
return Domain("state", "not in", ("draft", "sent", "cancel"))

def _get_lead_request_for_quotation_domain(self):
return Domain("state", "in", ("draft", "sent"))

def _get_purchase_order_lead_domain(self):
return Domain("opportunity_id", "in", self.ids)

@api.depends("purchase_order_ids.state")
def _compute_purchase_order_count(self):
purchase_order_per_lead = {
lead.id: count
for lead, count in self.env["purchase.order"]._read_group(
domain=Domain.AND(
[
self._get_purchase_order_lead_domain(),
self._get_lead_purchase_order_domain(),
]
),
groupby=["opportunity_id"],
aggregates=["__count"],
)
}
for lead in self:
lead.purchase_order_count = purchase_order_per_lead.get(lead.id, 0)

@api.depends("purchase_order_ids.state")
def _compute_request_for_quotation_count(self):
rfq_per_lead = {
lead.id: count
for lead, count in self.env["purchase.order"]._read_group(
domain=Domain.AND(
[
self._get_purchase_order_lead_domain(),
self._get_lead_request_for_quotation_domain(),
]
),
groupby=["opportunity_id"],
aggregates=["__count"],
)
}
for lead in self:
lead.request_for_quotation_count = rfq_per_lead.get(lead.id, 0)

@api.depends(
"purchase_order_ids.state",
"purchase_order_ids.currency_id",
"purchase_order_ids.amount_untaxed",
"purchase_order_ids.date_order",
"purchase_order_ids.company_id",
)
def _compute_purchase_amount_total(self):
amount_per_lead = defaultdict(float)

for lead, currency, company, date_order, amount in self.env[
"purchase.order"
]._read_group(
domain=Domain.AND(
[
self._get_purchase_order_lead_domain(),
self._get_lead_purchase_order_domain(),
]
),
groupby=["opportunity_id", "currency_id", "company_id", "date_order:day"],
aggregates=["amount_untaxed:sum"],
):
company_currency = lead.company_currency or self.env.company.currency_id
amount_per_lead[lead.id] += currency._convert(
amount,
company_currency,
company,
date_order or fields.Date.context_today(self),
)

for lead in self:
lead.purchase_amount_total = amount_per_lead.get(lead.id, 0.0)

def _create_customer(self, with_parent=None):
"""It can be a customer or supplier depending on lead request type"""
self.ensure_one()
self = self.with_context(res_partner_search_mode=self.request_type)
return super()._create_customer(with_parent=with_parent)

def action_lead_rfq_new(self):
self.ensure_one()
if not self.partner_id:
return self.env["ir.actions.actions"]._for_xml_id(
"srm.srm_rfq_partner_action"
)
else:
return self.action_rfq_new()

def action_rfq_new(self):
self.ensure_one()
action = self.env["ir.actions.actions"]._for_xml_id("srm.action_lead_rfq_new")
action["context"] = self._prepare_rfq_context()
return action

def _prepare_rfq_context(self):
self.ensure_one()
rfq_context = {
"default_partner_id": self.partner_id.id,
"default_opportunity_id": self.id,
}
if self.user_id:
rfq_context["default_user_id"] = self.user_id.id
return rfq_context
18 changes: 18 additions & 0 deletions srm/models/crm_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class Team(models.Model):
_inherit = "crm.team"

@api.model
def action_your_pipeline(self):
action = super().action_your_pipeline()
if request_type := self.env.context.get("request_type", False):
action["domain"] = (
f"[('type','=','opportunity'), ('request_type', '=', '{request_type}')]"
)
action["context"]["default_request_type"] = request_type
return action
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning a Domain instance here works?
Is it converted to a list automatically in the JSON response?

honest question.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, didn't know that. Thanks!

23 changes: 23 additions & 0 deletions srm/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

opportunity_id = fields.Many2one(
comodel_name="crm.lead",
string="Opportunity",
check_company=True,
domain="""
[
('type', '=', 'opportunity'),
('request_type', '=', 'supplier'),
'|',
('company_id', '=', False),
('company_id', '=', company_id),
]
""",
)
3 changes: 3 additions & 0 deletions srm/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions srm/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Telmo Santos \<<telmo.santos@camptocamp.com>\>
- Vincent Van Rossem \<<vincent.vanrossem@camptocamp.com>\>
3 changes: 3 additions & 0 deletions srm/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows the usage of crm module to manage leads coming from suppliers.
The flow is similar to CRM. The main change is that leads be generated from customer or supplier request type.
For supplier requests leads can be converted in purchases.
2 changes: 2 additions & 0 deletions srm/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_srm_rfq_partner,access.srm.rfq.partner,model_srm_rfq_partner,purchase.group_purchase_user,1,1,1,0
Loading
Loading