From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/sale_crm/wizard/__init__.py | 4 ++ .../wizard/crm_opportunity_to_quotation.py | 52 ++++++++++++++++++++++ .../wizard/crm_opportunity_to_quotation_views.xml | 35 +++++++++++++++ 3 files changed, 91 insertions(+) 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 (limited to 'addons/sale_crm/wizard') diff --git a/addons/sale_crm/wizard/__init__.py b/addons/sale_crm/wizard/__init__.py new file mode 100644 index 00000000..cf3b469f --- /dev/null +++ b/addons/sale_crm/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import crm_opportunity_to_quotation diff --git a/addons/sale_crm/wizard/crm_opportunity_to_quotation.py b/addons/sale_crm/wizard/crm_opportunity_to_quotation.py new file mode 100644 index 00000000..4247bd2b --- /dev/null +++ b/addons/sale_crm/wizard/crm_opportunity_to_quotation.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + + +class Opportunity2Quotation(models.TransientModel): + _name = 'crm.quotation.partner' + _description = 'Create new or use existing Customer on new Quotation' + + @api.model + def default_get(self, fields): + result = super(Opportunity2Quotation, self).default_get(fields) + + active_model = self._context.get('active_model') + if active_model != 'crm.lead': + raise UserError(_('You can only apply this action from a lead.')) + + lead = False + if result.get('lead_id'): + lead = self.env['crm.lead'].browse(result['lead_id']) + elif 'lead_id' in fields and self._context.get('active_id'): + lead = self.env['crm.lead'].browse(self._context['active_id']) + if lead: + result['lead_id'] = lead.id + partner_id = result.get('partner_id') or lead._find_matching_partner().id + if 'action' in fields and not result.get('action'): + result['action'] = 'exist' if partner_id else 'create' + if 'partner_id' in fields and not result.get('partner_id'): + result['partner_id'] = partner_id + + return result + + action = fields.Selection([ + ('create', 'Create a new customer'), + ('exist', 'Link to an existing customer'), + ('nothing', 'Do not link to a customer') + ], string='Quotation Customer', required=True) + lead_id = fields.Many2one('crm.lead', "Associated Lead", required=True) + partner_id = fields.Many2one('res.partner', 'Customer') + + def action_apply(self): + """ Convert lead to opportunity or merge lead and opportunity and open + the freshly created opportunity view. + """ + self.ensure_one() + if self.action == 'create': + self.lead_id.handle_partner_assignment(create_missing=True) + elif self.action == 'exist': + self.lead_id.handle_partner_assignment(force_partner_id=self.partner_id.id, create_missing=False) + return self.lead_id.action_new_quotation() diff --git a/addons/sale_crm/wizard/crm_opportunity_to_quotation_views.xml b/addons/sale_crm/wizard/crm_opportunity_to_quotation_views.xml new file mode 100644 index 00000000..385eb52e --- /dev/null +++ b/addons/sale_crm/wizard/crm_opportunity_to_quotation_views.xml @@ -0,0 +1,35 @@ + + + + crm.quotation.partner.view.form + crm.quotation.partner + +
+ + + + + + + + + + + +
+
+
+
+
+ + + New Quotation + ir.actions.act_window + crm.quotation.partner + form + + new + +
-- cgit v1.2.3