-
-
Notifications
You must be signed in to change notification settings - Fork 481
[19.0][MIG] srm: Migration to 19.0 #732
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a4bbbe7
Supplier Relationship Management module: Initial implementation
santostelmo acc5065
[IMP] srm: pre-commit auto fixes
vvrossem 9b45bae
[MIG] srm: Migration to 18.0
vvrossem 2988d09
[IMP] srm: pre-commit auto fixes
yankinmax c32a8bf
[MIG] srm: Migration to 19.0
vvrossem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import models | ||
| from . import wizard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| ] | ||
| """, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>\> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning a
Domaininstance here works?Is it converted to a list automatically in the JSON response?
honest question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should be ok as I can see several examples in core:
https://github.com/odoo/odoo/blob/441a6d1b928a44b9a760f926180a925159edff3e/addons/stock/models/product.py#L593
There was a problem hiding this comment.
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!