From 4c9c249cc398d42e93939646e1237a1d0ff61166 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Tue, 11 Dec 2018 14:28:05 +0000 Subject: [PATCH] [IMP] sale_crm : create partner on new quotation if no customer set on opportunity When creating a quotation from a opportunity that does not have any customer set, we ended up on a quotation without any customer or any of the contact information entered on the crm.lead. If no customer is set on the opportunity, when hitting New Quotation button, a modal is displayed to ask the user what to do to fill in the customer field. - Create a new customer : Use the information from the opportunity to create automatically a res.partner. Set the res.partner on the quotation and on the opportunity. - Use an existing customer : Set this customer on the quotation and on the opportunity. Task ID : 1917332 Closes PR #30475 --- addons/crm/wizard/crm_partner_binding.py | 4 ++ addons/sale_crm/__init__.py | 1 + addons/sale_crm/__manifest__.py | 3 +- addons/sale_crm/models/crm_lead.py | 22 ++++++++ addons/sale_crm/views/crm_lead_views.xml | 11 +--- addons/sale_crm/wizard/__init__.py | 4 ++ .../wizard/crm_opportunity_to_quotation.py | 52 +++++++++++++++++++ .../crm_opportunity_to_quotation_views.xml | 35 +++++++++++++ 8 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 addons/sale_crm/wizard/__init__.py create mode 100644 addons/sale_crm/wizard/crm_opportunity_to_quotation.py create mode 100644 addons/sale_crm/wizard/crm_opportunity_to_quotation_views.xml diff --git a/addons/crm/wizard/crm_partner_binding.py b/addons/crm/wizard/crm_partner_binding.py index 85acbc62396..136f2b41a93 100644 --- a/addons/crm/wizard/crm_partner_binding.py +++ b/addons/crm/wizard/crm_partner_binding.py @@ -64,4 +64,8 @@ class PartnerBinding(models.TransientModel): partner = Partner.search([('name', 'ilike', '%' + lead.contact_name+'%')], limit=1) return partner.id + if lead.name: # to be aligned with _create_lead_partner, search on lead's name as last possibility + partner = Partner.search([('name', 'ilike', '%' + lead.name + '%')], limit=1) + return partner.id + return False diff --git a/addons/sale_crm/__init__.py b/addons/sale_crm/__init__.py index e3e519761b8..ab491732dfe 100644 --- a/addons/sale_crm/__init__.py +++ b/addons/sale_crm/__init__.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import models +from . import wizard from odoo import api, SUPERUSER_ID diff --git a/addons/sale_crm/__manifest__.py b/addons/sale_crm/__manifest__.py index 9620ea428e7..fd554044d9d 100644 --- a/addons/sale_crm/__manifest__.py +++ b/addons/sale_crm/__manifest__.py @@ -22,7 +22,8 @@ modules. 'views/partner_views.xml', 'views/sale_order_views.xml', 'views/crm_lead_views.xml', - 'views/crm_team_views.xml' + 'views/crm_team_views.xml', + 'wizard/crm_opportunity_to_quotation_views.xml' ], 'auto_install': True, 'uninstall_hook': 'uninstall_hook' diff --git a/addons/sale_crm/models/crm_lead.py b/addons/sale_crm/models/crm_lead.py index 6d080f1b1f9..e5fe4e07203 100644 --- a/addons/sale_crm/models/crm_lead.py +++ b/addons/sale_crm/models/crm_lead.py @@ -60,3 +60,25 @@ class CrmLead(models.Model): res['invoiced']['target'] = self.env.user.target_sales_invoiced return res + + def action_sale_quotations_new(self): + if not self.partner_id: + return self.env.ref("sale_crm.crm_quotation_partner_action").read()[0] + else: + return self.action_new_quotation() + + def action_new_quotation(self): + action = self.env.ref("sale_crm.sale_action_quotations_new").read()[0] + action['context'] = { + 'search_default_opportunity_id': self.id, + 'default_opportunity_id': self.id, + 'search_default_partner_id': self.partner_id.id, + 'default_partner_id': self.partner_id.id, + 'default_team_id': self.team_id.id, + 'default_campaign_id': self.campaign_id.id, + 'default_medium_id': self.medium_id.id, + 'default_origin': self.name, + 'default_name': self.name, + 'default_source_id': self.source_id.id + } + return action diff --git a/addons/sale_crm/views/crm_lead_views.xml b/addons/sale_crm/views/crm_lead_views.xml index 1634b340bda..d0c79228246 100644 --- a/addons/sale_crm/views/crm_lead_views.xml +++ b/addons/sale_crm/views/crm_lead_views.xml @@ -7,15 +7,8 @@ -