diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-01-14 13:30:18 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-03-23 11:42:11 +0000 |
| commit | d8b6b35cb3c75b5c503b5b147fb8dd0e36e4ecfa (patch) | |
| tree | 6d6333491f3755445be9af50b8f61730b47b3bc7 /addons/sale_crm | |
| parent | 8b94dc17bfedf08ec497adf91e67bd8948d3bd79 (diff) | |
[REF] crm(_*): improve code of methods used in lead/opp convert/merge wizards
PURPOSE
As CRM is going to be updated (onchange -> compute, code improvements, better
management of sales teams) cleaning and improving code is a necessary first
step.
SPECIFICATIONS
Purpose of this commit is to rewrite code located and/or used in convert or
merge wizards. Indeed it holds unnecessary variables, dictionaries manipulation
that hides the real business flow, badly named variables, unclear methods, ...
Logic of those wizards seem quite simple but is hidden behind a wall of
bloated code.
Notably for wizards
* try to set explicit arguments in methods;
* less use of context values, replaced by arguments when possible;
* try to make better use of lead2opportunity wizard in its mass wizard that
inherit from it, notably by correctly calling super;
Notably for tools
* ``get_duplicated_leads`` was just a shortcut to ``_get_duplicated_leads_by
_emails``;
* ``_get_duplicated_leads_by_emails`` is renamed to ``_get_lead_duplicates``
because email is not the only way of finding duplicates;
* try to make better use of record sets instead of propagating ids, notably
for partner. For example input of ``_get_lead_duplicates`` or output of
``_find_matching_partner``;
* ``_create_lead_partner`` rename to ``_create_customer``, and its sub
method ``_create_lead_partner_data`` to ``_prepare_customer_values``;
* ``handle_partner_assignation`` was difficult as its use is not documented
and its docstring was not updated. Parameter have been renamed to be more
explicit about what it does. Method is renamed to ``handle_partner_
assignment`` as assignation has other meaning in English;
* ``allocate_salesman`` is renamed to ``handle_salesmen_assignment`` to match
the partner assignement and code is slightly cleaned;
No functional change should occur with this commit. Tests have been gradually
added to try to ensure behavior does not change.
LINKS
Task ID 2088565 (crm: from onchange to compute)
Diffstat (limited to 'addons/sale_crm')
| -rw-r--r-- | addons/sale_crm/wizard/crm_opportunity_to_quotation.py | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/addons/sale_crm/wizard/crm_opportunity_to_quotation.py b/addons/sale_crm/wizard/crm_opportunity_to_quotation.py index 6ffa8860153..aa465066f8d 100644 --- a/addons/sale_crm/wizard/crm_opportunity_to_quotation.py +++ b/addons/sale_crm/wizard/crm_opportunity_to_quotation.py @@ -24,7 +24,7 @@ class Opportunity2Quotation(models.TransientModel): 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() + 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'): @@ -46,16 +46,6 @@ class Opportunity2Quotation(models.TransientModel): """ self.ensure_one() if self.action != 'nothing': - self.lead_id.write({ - 'partner_id': self.partner_id.id if self.action == 'exist' else self._create_partner() - }) + self.lead_id.handle_partner_assignment(force_partner_id=self.partner_id.id, create_missing=(self.action == 'create')) self.lead_id._onchange_partner_id() return self.lead_id.action_new_quotation() - - def _create_partner(self): - """ Create partner based on action. - :return int: created res.partner id - """ - self.ensure_one() - result = self.lead_id.handle_partner_assignation(action='create') - return result.get(self.lead_id.id) |
