Skip to content

Commit 750d6f9

Browse files
vvrossemyankinmax
authored andcommitted
[MIG] srm: Migration to 19.0
1 parent 2988d09 commit 750d6f9

9 files changed

Lines changed: 342 additions & 50 deletions

File tree

srm/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "SRM",
66
"summary": "Use CRM model for suppliers",
7-
"version": "18.0.1.0.0",
7+
"version": "19.0.1.0.0",
88
"development_status": "Alpha",
99
"category": "CRM",
1010
"website": "https://github.com/OCA/crm",

srm/models/crm_lead.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections import defaultdict
44

55
from odoo import api, fields, models
6+
from odoo.fields import Domain
67

78

89
class CrmLead(models.Model):
@@ -37,20 +38,25 @@ class CrmLead(models.Model):
3738
)
3839

3940
def _get_lead_purchase_order_domain(self):
40-
return [("state", "not in", ("draft", "sent", "cancel"))]
41+
return Domain("state", "not in", ("draft", "sent", "cancel"))
4142

4243
def _get_lead_request_for_quotation_domain(self):
43-
return [("state", "in", ("draft", "sent"))]
44+
return Domain("state", "in", ("draft", "sent"))
45+
46+
def _get_purchase_order_lead_domain(self):
47+
return Domain("opportunity_id", "in", self.ids)
4448

4549
@api.depends("purchase_order_ids.state")
4650
def _compute_purchase_order_count(self):
4751
purchase_order_per_lead = {
4852
lead.id: count
4953
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+
domain=Domain.AND(
55+
[
56+
self._get_purchase_order_lead_domain(),
57+
self._get_lead_purchase_order_domain(),
58+
]
59+
),
5460
groupby=["opportunity_id"],
5561
aggregates=["__count"],
5662
)
@@ -63,10 +69,12 @@ def _compute_request_for_quotation_count(self):
6369
rfq_per_lead = {
6470
lead.id: count
6571
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-
],
72+
domain=Domain.AND(
73+
[
74+
self._get_purchase_order_lead_domain(),
75+
self._get_lead_request_for_quotation_domain(),
76+
]
77+
),
7078
groupby=["opportunity_id"],
7179
aggregates=["__count"],
7280
)
@@ -84,17 +92,15 @@ def _compute_request_for_quotation_count(self):
8492
def _compute_purchase_amount_total(self):
8593
amount_per_lead = defaultdict(float)
8694

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-
],
95+
for lead, currency, company, date_order, amount in self.env[
96+
"purchase.order"
97+
]._read_group(
98+
domain=Domain.AND(
99+
[
100+
self._get_purchase_order_lead_domain(),
101+
self._get_lead_purchase_order_domain(),
102+
]
103+
),
98104
groupby=["opportunity_id", "currency_id", "company_id", "date_order:day"],
99105
aggregates=["amount_untaxed:sum"],
100106
):
@@ -109,12 +115,14 @@ def _compute_purchase_amount_total(self):
109115
for lead in self:
110116
lead.purchase_amount_total = amount_per_lead.get(lead.id, 0.0)
111117

112-
def _create_customer(self):
118+
def _create_customer(self, with_parent=None):
113119
"""It can be a customer or supplier depending on lead request type"""
120+
self.ensure_one()
114121
self = self.with_context(res_partner_search_mode=self.request_type)
115-
return super()._create_customer()
122+
return super()._create_customer(with_parent=with_parent)
116123

117124
def action_lead_rfq_new(self):
125+
self.ensure_one()
118126
if not self.partner_id:
119127
return self.env["ir.actions.actions"]._for_xml_id(
120128
"srm.srm_rfq_partner_action"
@@ -123,6 +131,7 @@ def action_lead_rfq_new(self):
123131
return self.action_rfq_new()
124132

125133
def action_rfq_new(self):
134+
self.ensure_one()
126135
action = self.env["ir.actions.actions"]._for_xml_id("srm.action_lead_rfq_new")
127136
action["context"] = self._prepare_rfq_context()
128137
return action

srm/models/crm_team.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright 2022 Camptocamp SA
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
import ast
34

45
from odoo import api, models
6+
from odoo.fields import Domain
57

68

79
class Team(models.Model):
@@ -13,7 +15,13 @@ def action_your_pipeline(self):
1315
request_type = self.env.context.get("request_type")
1416
if request_type:
1517
action["domain"] = (
16-
f"[('type','=','opportunity'), ('request_type', '=', '{request_type}')]"
18+
Domain(action.get("domain") or Domain.TRUE)
19+
& Domain("type", "=", "opportunity")
20+
& Domain("request_type", "=", request_type)
1721
)
22+
if action.get("context"):
23+
action["context"] = ast.literal_eval(action["context"])
24+
else:
25+
action["context"] = {}
1826
action["context"]["default_request_type"] = request_type
1927
return action

srm/models/purchase_order.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ class PurchaseOrder(models.Model):
1111
comodel_name="crm.lead",
1212
string="Opportunity",
1313
check_company=True,
14-
domain="[('type', '=', 'opportunity'), ('request_type', '=', 'supplier'), "
15-
"'|', ('company_id', '=', False), ('company_id', '=', company_id)]",
14+
domain="""
15+
[
16+
('type', '=', 'opportunity'),
17+
('request_type', '=', 'supplier'),
18+
'|',
19+
('company_id', '=', False),
20+
('company_id', '=', company_id),
21+
]
22+
""",
1623
)

srm/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_srm

0 commit comments

Comments
 (0)