Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] srm: Migration to 18.0 #632

Open
wants to merge 3 commits into
base: 18.0
Choose a base branch
from
Open
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
82 changes: 82 additions & 0 deletions srm/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
============
SRM
============

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/14.0/crm_location
:alt: OCA/crm
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/crm-14-0/crm-14-0-srm
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/111/14.0
:alt: Try me on Runbot

|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 suplier requests leads can be converted in purchases.

**Table of contents**

.. contents::
:local:

Installation
============

To install this module, you need:

* crm

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 smashing it by providing a detailed and welcomed
`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**>`_.

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

Credits
=======

Authors
~~~~~~~

* Camptocmap

Contributors
~~~~~~~~~~~~

* Telmo Santos <telmo.santos@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/14.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 Telmo Santos <telmo.santos@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).


{
"name": "SRM",
"version": "18.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"summary": "Use CRM model for suppliers",
"license": "AGPL-3",
"category": "CRM",
"depends": [
"account",
"crm",
"sale_crm",
"purchase",
],
"website": "https://github.com/OCA/crm",
"data": [
"security/ir.model.access.csv",
"views/srm_menu_views.xml",
"views/srm_lead_views.xml",
"views/crm_lead_views.xml",
"views/purchase_views.xml",
"wizard/srm_opportunity_to_rfq_views.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
81 changes: 81 additions & 0 deletions srm/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright 2022 Telmo Santos <telmo.santos@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


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

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

@api.depends(
"order_ids.state",
"order_ids.currency_id",
"order_ids.amount_untaxed",
"order_ids.date_order",
"order_ids.company_id",
)
def _compute_purchase_data(self):
for lead in self:
total = 0.0
rfq_cnt = 0
purchase_order_cnt = 0
company_currency = lead.company_currency or self.env.company.currency_id

Check warning on line 44 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L41-L44

Added lines #L41 - L44 were not covered by tests
for order in lead.purchase_order_ids:
if order.state in ("draft", "sent"):
rfq_cnt += 1

Check warning on line 47 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L47

Added line #L47 was not covered by tests
if order.state not in ("draft", "sent", "cancel"):
purchase_order_cnt += 1
total += order.currency_id._convert(

Check warning on line 50 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L49-L50

Added lines #L49 - L50 were not covered by tests
order.amount_untaxed,
company_currency,
order.company_id,
order.date_order or fields.Date.today(),
)
lead.purchase_amount_total = total
lead.request_for_quotation_count = rfq_cnt
lead.purchase_order_count = purchase_order_cnt

Check warning on line 58 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L56-L58

Added lines #L56 - L58 were not covered by tests

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

Check warning on line 63 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L62-L63

Added lines #L62 - L63 were not covered by tests

def action_lead_rfq_new(self):
if not self.partner_id:
return self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 67 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L67

Added line #L67 was not covered by tests
"srm.srm_rfq_partner_action"
)
else:
return self.action_rfq_new()

Check warning on line 71 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L71

Added line #L71 was not covered by tests

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

Check warning on line 75 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L74-L75

Added lines #L74 - L75 were not covered by tests
"default_partner_id": self.partner_id.id,
"default_opportunity_id": self.id,
}
if self.user_id:
action["context"]["default_user_id"] = self.user_id.id
return action

Check warning on line 81 in srm/models/crm_lead.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_lead.py#L80-L81

Added lines #L80 - L81 were not covered by tests
19 changes: 19 additions & 0 deletions srm/models/crm_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Telmo Santos <telmo.santos@camptocamp.com>
# 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()
request_type = self.env.context.get("request_type")

Check warning on line 13 in srm/models/crm_team.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_team.py#L12-L13

Added lines #L12 - L13 were not covered by tests
if request_type:
action["domain"] = (

Check warning on line 15 in srm/models/crm_team.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_team.py#L15

Added line #L15 was not covered by tests
f"[('type','=','opportunity'), ('request_type', '=', '{request_type}')]"
)
action["context"]["default_request_type"] = request_type
return action

Check warning on line 19 in srm/models/crm_team.py

View check run for this annotation

Codecov / codecov/patch

srm/models/crm_team.py#L18-L19

Added lines #L18 - L19 were not covered by tests
15 changes: 15 additions & 0 deletions srm/models/purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 Telmo Santos <telmo.santos@camptocamp.com>
# 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(
"crm.lead",
string="Opportunity",
check_company=True,
domain="[('type', '=', 'opportunity'), ('request_type', '=', 'supplier'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", # noqa
)
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/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
19 changes: 19 additions & 0 deletions srm/views/crm_lead_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<odoo>
<record id="crm.action_your_pipeline" model="ir.actions.server">
<field
name="code"
>action = model.with_context(request_type='customer').action_your_pipeline()</field>
</record>

<record id="crm.crm_lead_action_pipeline" model="ir.actions.act_window">
<field
name="domain"
>[('type','=','opportunity'),('request_type','in',(False,'customer'))]</field>
<field name="context">{
'default_type': 'opportunity',
'default_request_type': 'customer',
'search_default_assigned_to_me': 1,
}</field>
</record>
</odoo>
13 changes: 13 additions & 0 deletions srm/views/purchase_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="opportunity_id" />
</field>
</field>
</record>
</odoo>
Loading