Skip to content

Commit f50eb8b

Browse files
vvrossemyankinmax
authored andcommitted
[MIG] srm: Migration to 18.0
1 parent f0137cb commit f50eb8b

16 files changed

Lines changed: 655 additions & 177 deletions

srm/README.rst

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,74 @@
1-
============
1+
===
22
SRM
3-
============
3+
===
44

5-
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67
!! This file is generated by oca-gen-addon-readme !!
78
!! changes will be overwritten. !!
89
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:6e6380a8b3a6c8aa36be3cb6861a190da89e603afaa94e6c982b505f29c5e56f
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
912
10-
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
1114
:target: https://odoo-community.org/page/development-status
12-
:alt: Beta
15+
:alt: Alpha
1316
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
1417
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1518
:alt: License: AGPL-3
1619
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcrm-lightgray.png?logo=github
17-
:target: https://github.com/OCA/crm/tree/14.0/crm_location
20+
:target: https://github.com/OCA/crm/tree/18.0/srm
1821
:alt: OCA/crm
1922
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20-
:target: https://translation.odoo-community.org/projects/crm-14-0/crm-14-0-srm
23+
:target: https://translation.odoo-community.org/projects/crm-18-0/crm-18-0-srm
2124
:alt: Translate me on Weblate
22-
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/111/14.0
24-
:alt: Try me on Runbot
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/crm&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
2530

26-
|badge1| |badge2| |badge3| |badge4| |badge5|
31+
This module allows the usage of crm module to manage leads coming from
32+
suppliers. The flow is similar to CRM. The main change is that leads be
33+
generated from customer or supplier request type. For supplier requests
34+
leads can be converted in purchases.
2735

28-
This module allows the usage of crm module to manage leads coming from suppliers.
29-
The flow is similar to CRM. The main change is that leads be generated from customer or supplier request type.
30-
For suplier requests leads can be converted in purchases.
36+
.. IMPORTANT::
37+
This is an alpha version, the data model and design can change at any time without warning.
38+
Only for development or testing purpose, do not use in production.
39+
`More details on development status <https://odoo-community.org/page/development-status>`_
3140

3241
**Table of contents**
3342

3443
.. contents::
3544
:local:
3645

37-
Installation
38-
============
39-
40-
To install this module, you need:
41-
42-
* crm
43-
4446
Bug Tracker
4547
===========
4648

4749
Bugs are tracked on `GitHub Issues <https://github.com/OCA/crm/issues>`_.
4850
In case of trouble, please check there if your issue has already been reported.
49-
If you spotted it first, help us smashing it by providing a detailed and welcomed
50-
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20srm%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
51+
If you spotted it first, help us to smash it by providing a detailed and welcomed
52+
`feedback <https://github.com/OCA/crm/issues/new?body=module:%20srm%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
5153

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

5456
Credits
5557
=======
5658

5759
Authors
58-
~~~~~~~
60+
-------
5961

60-
* Camptocmap
62+
* Camptocamp
6163

6264
Contributors
63-
~~~~~~~~~~~~
65+
------------
6466

65-
* Telmo Santos <telmo.santos@camptocamp.com>
67+
- Telmo Santos <telmo.santos@camptocamp.com>
68+
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>
6669

6770
Maintainers
68-
~~~~~~~~~~~
71+
-----------
6972

7073
This module is maintained by the OCA.
7174

@@ -77,6 +80,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
7780
mission is to support the collaborative development of Odoo features and
7881
promote its widespread use.
7982

80-
This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/14.0/srm>`_ project on GitHub.
83+
This module is part of the `OCA/crm <https://github.com/OCA/crm/tree/18.0/srm>`_ project on GitHub.
8184

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

srm/__manifest__.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
# Copyright 2022 Telmo Santos <telmo.santos@camptocamp.com>
1+
# Copyright 2022 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33

4-
54
{
65
"name": "SRM",
7-
"version": "14.0.1.0.0",
8-
"author": "Camptocamp, Odoo Community Association (OCA)",
96
"summary": "Use CRM model for suppliers",
10-
"license": "AGPL-3",
7+
"version": "18.0.1.0.0",
8+
"development_status": "Alpha",
119
"category": "CRM",
10+
"website": "https://github.com/OCA/crm",
11+
"author": "Camptocamp, Odoo Community Association (OCA)",
12+
"license": "AGPL-3",
1213
"depends": [
1314
"account",
1415
"crm",
1516
"sale_crm",
1617
"purchase",
17-
"crm_enterprise",
1818
],
19-
"website": "https://github.com/OCA/crm",
2019
"data": [
2120
"security/ir.model.access.csv",
22-
"views/srm_menu_views.xml",
23-
"views/srm_lead_views.xml",
24-
"views/crm_lead_views.xml",
25-
"views/purchase_views.xml",
26-
"wizard/srm_opportunity_to_rfq_views.xml",
21+
"views/srm_menu.xml",
22+
"views/srm_lead.xml",
23+
"views/crm_lead.xml",
24+
"views/purchase_order.xml",
25+
"wizard/srm_opportunity_to_rfq.xml",
2726
],
2827
"installable": True,
2928
}

srm/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from . import crm_lead
22
from . import crm_team
3-
from . import purchase
3+
from . import purchase_order

srm/models/crm_lead.py

Lines changed: 92 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,113 @@
1-
# Copyright 2022 Telmo Santos <telmo.santos@camptocamp.com>
1+
# Copyright 2022 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
from collections import defaultdict
34

45
from odoo import api, fields, models
56

67

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

11+
user_id = fields.Many2one(string="Responsible")
12+
team_id = fields.Many2one(string="Team")
13+
1014
request_type = fields.Selection(
11-
[
15+
selection=[
1216
("customer", "Customer Lead"),
1317
("supplier", "Supplier Lead"),
1418
],
1519
)
1620
purchase_amount_total = fields.Monetary(
17-
compute="_compute_purchase_data",
18-
string="Sum of Orders",
19-
help="Untaxed Total of Confirmed Orders",
21+
compute="_compute_purchase_amount_total",
22+
string="Sum of Purchase Orders",
23+
help="Untaxed Total of Confirmed Purchase Orders",
2024
currency_field="company_currency",
2125
)
2226
request_for_quotation_count = fields.Integer(
23-
compute="_compute_purchase_data", string="Number of Quotations"
27+
compute="_compute_request_for_quotation_count",
28+
string="Number of Request for Quotations",
2429
)
2530
purchase_order_count = fields.Integer(
26-
compute="_compute_purchase_data", string="Number of Purchase Orders"
31+
compute="_compute_purchase_order_count", string="Number of Purchase Orders"
2732
)
2833
purchase_order_ids = fields.One2many(
29-
"purchase.order", "opportunity_id", string="Purchase Orders"
34+
comodel_name="purchase.order",
35+
inverse_name="opportunity_id",
36+
string="Purchase Orders",
3037
)
3138

39+
def _get_lead_purchase_order_domain(self):
40+
return [("state", "not in", ("draft", "sent", "cancel"))]
41+
42+
def _get_lead_request_for_quotation_domain(self):
43+
return [("state", "in", ("draft", "sent"))]
44+
45+
@api.depends("purchase_order_ids.state")
46+
def _compute_purchase_order_count(self):
47+
purchase_order_per_lead = {
48+
lead.id: count
49+
for lead, count in self.env["purchase.order"]._read_group(
50+
domain=[
51+
("opportunity_id", "in", self.ids),
52+
*self._get_lead_purchase_order_domain(),
53+
],
54+
groupby=["opportunity_id"],
55+
aggregates=["__count"],
56+
)
57+
}
58+
for lead in self:
59+
lead.purchase_order_count = purchase_order_per_lead.get(lead.id, 0)
60+
61+
@api.depends("purchase_order_ids.state")
62+
def _compute_request_for_quotation_count(self):
63+
rfq_per_lead = {
64+
lead.id: count
65+
for lead, count in self.env["purchase.order"]._read_group(
66+
domain=[
67+
("opportunity_id", "in", self.ids),
68+
*self._get_lead_request_for_quotation_domain(),
69+
],
70+
groupby=["opportunity_id"],
71+
aggregates=["__count"],
72+
)
73+
}
74+
for lead in self:
75+
lead.request_for_quotation_count = rfq_per_lead.get(lead.id, 0)
76+
3277
@api.depends(
33-
"order_ids.state",
34-
"order_ids.currency_id",
35-
"order_ids.amount_untaxed",
36-
"order_ids.date_order",
37-
"order_ids.company_id",
78+
"purchase_order_ids.state",
79+
"purchase_order_ids.currency_id",
80+
"purchase_order_ids.amount_untaxed",
81+
"purchase_order_ids.date_order",
82+
"purchase_order_ids.company_id",
3883
)
39-
def _compute_purchase_data(self):
40-
for lead in self:
41-
total = 0.0
42-
rfq_cnt = 0
43-
purchase_order_cnt = 0
84+
def _compute_purchase_amount_total(self):
85+
amount_per_lead = defaultdict(float)
86+
87+
for (
88+
lead,
89+
currency,
90+
company,
91+
date_order,
92+
amount,
93+
) in self.env["purchase.order"]._read_group(
94+
domain=[
95+
("opportunity_id", "in", self.ids),
96+
*self._get_lead_purchase_order_domain(),
97+
],
98+
groupby=["opportunity_id", "currency_id", "company_id", "date_order:day"],
99+
aggregates=["amount_untaxed:sum"],
100+
):
44101
company_currency = lead.company_currency or self.env.company.currency_id
45-
for order in lead.purchase_order_ids:
46-
if order.state in ("draft", "sent"):
47-
rfq_cnt += 1
48-
if order.state not in ("draft", "sent", "cancel"):
49-
purchase_order_cnt += 1
50-
total += order.currency_id._convert(
51-
order.amount_untaxed,
52-
company_currency,
53-
order.company_id,
54-
order.date_order or fields.Date.today(),
55-
)
56-
lead.purchase_amount_total = total
57-
lead.request_for_quotation_count = rfq_cnt
58-
lead.purchase_order_count = purchase_order_cnt
102+
amount_per_lead[lead.id] += currency._convert(
103+
amount,
104+
company_currency,
105+
company,
106+
date_order or fields.Date.context_today(self),
107+
)
108+
109+
for lead in self:
110+
lead.purchase_amount_total = amount_per_lead.get(lead.id, 0.0)
59111

60112
def _create_customer(self):
61113
"""It can be a customer or supplier depending on lead request type"""
@@ -72,10 +124,15 @@ def action_lead_rfq_new(self):
72124

73125
def action_rfq_new(self):
74126
action = self.env["ir.actions.actions"]._for_xml_id("srm.action_lead_rfq_new")
75-
action["context"] = {
127+
action["context"] = self._prepare_rfq_context()
128+
return action
129+
130+
def _prepare_rfq_context(self):
131+
self.ensure_one()
132+
rfq_context = {
76133
"default_partner_id": self.partner_id.id,
77134
"default_opportunity_id": self.id,
78135
}
79136
if self.user_id:
80-
action["context"]["default_user_id"] = self.user_id.id
81-
return action
137+
rfq_context["default_user_id"] = self.user_id.id
138+
return rfq_context

srm/models/crm_team.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Telmo Santos <telmo.santos@camptocamp.com>
1+
# Copyright 2022 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33

44
from odoo import api, models
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Telmo Santos <telmo.santos@camptocamp.com>
1+
# Copyright 2022 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33

44
from odoo import fields, models
@@ -8,8 +8,9 @@ class PurchaseOrder(models.Model):
88
_inherit = "purchase.order"
99

1010
opportunity_id = fields.Many2one(
11-
"crm.lead",
11+
comodel_name="crm.lead",
1212
string="Opportunity",
1313
check_company=True,
14-
domain="[('type', '=', 'opportunity'), ('request_type', '=', 'supplier'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", # noqa
14+
domain="[('type', '=', 'opportunity'), ('request_type', '=', 'supplier'), "
15+
"'|', ('company_id', '=', False), ('company_id', '=', company_id)]",
1516
)

srm/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Telmo Santos \<<telmo.santos@camptocamp.com>\>
2+
- Vincent Van Rossem \<<vincent.vanrossem@camptocamp.com>\>

srm/readme/DESCRIPTION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module allows the usage of crm module to manage leads coming from suppliers.
2+
The flow is similar to CRM. The main change is that leads be generated from customer or supplier request type.
3+
For supplier requests leads can be converted in purchases.

0 commit comments

Comments
 (0)