From b5185941366d665abb29292f5bb411a7482944b7 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 2 Feb 2017 00:24:20 +0100 Subject: [PATCH] Prospect modules (different approch than the OCA module partner_prospect in sale-workflow) --- base_partner_prospect/__init__.py | 3 ++ base_partner_prospect/__manifest__.py | 30 +++++++++++++++++++ base_partner_prospect/partner.py | 31 +++++++++++++++++++ base_partner_prospect/partner_view.xml | 41 ++++++++++++++++++++++++++ crm_partner_prospect/__init__.py | 3 ++ crm_partner_prospect/__manifest__.py | 29 ++++++++++++++++++ crm_partner_prospect/crm.py | 16 ++++++++++ crm_partner_prospect/crm_view.xml | 40 +++++++++++++++++++++++++ sale_partner_prospect/__init__.py | 3 ++ sale_partner_prospect/__manifest__.py | 29 ++++++++++++++++++ sale_partner_prospect/sale.py | 28 ++++++++++++++++++ sale_partner_prospect/sale_view.xml | 32 ++++++++++++++++++++ 12 files changed, 285 insertions(+) create mode 100644 base_partner_prospect/__init__.py create mode 100644 base_partner_prospect/__manifest__.py create mode 100644 base_partner_prospect/partner.py create mode 100644 base_partner_prospect/partner_view.xml create mode 100644 crm_partner_prospect/__init__.py create mode 100644 crm_partner_prospect/__manifest__.py create mode 100644 crm_partner_prospect/crm.py create mode 100644 crm_partner_prospect/crm_view.xml create mode 100644 sale_partner_prospect/__init__.py create mode 100644 sale_partner_prospect/__manifest__.py create mode 100644 sale_partner_prospect/sale.py create mode 100644 sale_partner_prospect/sale_view.xml diff --git a/base_partner_prospect/__init__.py b/base_partner_prospect/__init__.py new file mode 100644 index 0000000..61cf8b2 --- /dev/null +++ b/base_partner_prospect/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import partner diff --git a/base_partner_prospect/__manifest__.py b/base_partner_prospect/__manifest__.py new file mode 100644 index 0000000..78a5205 --- /dev/null +++ b/base_partner_prospect/__manifest__.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Base Partner Prospect', + 'version': '10.0.1.0.0', + 'category': 'Partner', + 'license': 'AGPL-3', + 'summary': "Add boolean field 'Prospect' on partners", + 'description': """ +Base Partner Prospect +===================== + +This module adds a regular boolean field *Prospect* on partner form view. + +This module is a different implementation of the OCA module *partner_prospect* which adds the same field on partners: that module doesn't use a regular boolean field but a compute boolean field. I don't like this approch because I want to have manual control over that field and have a customer with prospect = False even if there is not sale order in Odoo for that customer. + +This module has been written by Alexis de Lattre from Akretion +. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['base'], + 'data': [ + 'partner_view.xml', + ], + 'installable': True, +} diff --git a/base_partner_prospect/partner.py b/base_partner_prospect/partner.py new file mode 100644 index 0000000..9c257da --- /dev/null +++ b/base_partner_prospect/partner.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# © 2015-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + prospect = fields.Boolean( + string='Is a Prospect', track_visibility='onchange') + + @api.onchange('customer') + def prospect_customer_change(self): + if self.customer and self.prospect: + self.prospect = False + + @api.onchange('prospect') + def prospect_change(self): + if self.prospect and self.customer: + self.customer = False + + @api.constrains('customer', 'prospect') + def partner_prospect_check(self): + for partner in self: + if partner.customer and partner.prospect: + raise ValidationError(_( + "Partner '%s' cannot be both a prospect and a customer") + % self.name_get()[0][1]) diff --git a/base_partner_prospect/partner_view.xml b/base_partner_prospect/partner_view.xml new file mode 100644 index 0000000..9612f36 --- /dev/null +++ b/base_partner_prospect/partner_view.xml @@ -0,0 +1,41 @@ + + + + + + + base_usability.title.on.partner.form + res.partner + + + + + + + + + + base_usability.partner.search.form + res.partner + + + + + + + + + + Prospects + res.partner + tree,form,kanban + {'default_prospect': 1, 'search_default_prospect': 1} + + + + + diff --git a/crm_partner_prospect/__init__.py b/crm_partner_prospect/__init__.py new file mode 100644 index 0000000..c6e6f19 --- /dev/null +++ b/crm_partner_prospect/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import crm diff --git a/crm_partner_prospect/__manifest__.py b/crm_partner_prospect/__manifest__.py new file mode 100644 index 0000000..b400f0d --- /dev/null +++ b/crm_partner_prospect/__manifest__.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'CRM Partner Prospect', + 'version': '10.0.1.0.0', + 'category': 'Sales', + 'license': 'AGPL-3', + 'summary': "Glue module between base_partner_prospect and crm modules", + 'description': """ +CRM Partner Prospect +===================== + +This is a glue module between *base_partner_prospect* and *crm* modules. + +This module has been written by Alexis de Lattre from Akretion +. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['crm', 'base_partner_prospect'], + 'data': [ + 'crm_view.xml', + ], + 'installable': True, + 'auto_install': True, +} diff --git a/crm_partner_prospect/crm.py b/crm_partner_prospect/crm.py new file mode 100644 index 0000000..4881316 --- /dev/null +++ b/crm_partner_prospect/crm.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © 2015-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api + + +class CrmLead(models.Model): + _inherit = 'crm.lead' + + @api.multi + def _lead_create_contact(self, name, is_company, parent_id=False): + partner = super(CrmLead, self)._lead_create_contact( + name, is_company, parent_id=parent_id) + partner.write({'prospect': True, 'customer': False}) + return partner diff --git a/crm_partner_prospect/crm_view.xml b/crm_partner_prospect/crm_view.xml new file mode 100644 index 0000000..c46fe7e --- /dev/null +++ b/crm_partner_prospect/crm_view.xml @@ -0,0 +1,40 @@ + + + + + + + crm_partner_prospect.crm.opportunity.form + crm.lead + + + + ['|', ('prospect', '=', True), ('customer', '=', True)] + {'default_customer': 0, 'default_prospect': 1, + 'default_name': partner_name, 'default_street': street, + 'default_street2': street2, 'default_city': city, + 'default_state_id': state_id, 'default_zip': zip, + 'default_country_id': country_id, 'default_function': function, + 'default_phone': phone, 'default_mobile': mobile, + 'default_fax': fax, 'default_email': email_from, + 'default_user_id': user_id, 'default_team_id': team_id} + + + + + + crm_partner_prospect.crm.lead2opportunity.partner.form + crm.lead2opportunity.partner + + + + ['|', ('prospect', '=', True), ('customer', '=', True)]} + + + + + diff --git a/sale_partner_prospect/__init__.py b/sale_partner_prospect/__init__.py new file mode 100644 index 0000000..78a9604 --- /dev/null +++ b/sale_partner_prospect/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import sale diff --git a/sale_partner_prospect/__manifest__.py b/sale_partner_prospect/__manifest__.py new file mode 100644 index 0000000..8631ed2 --- /dev/null +++ b/sale_partner_prospect/__manifest__.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# © 2017 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Sale Partner Prospect', + 'version': '10.0.1.0.0', + 'category': 'Sales', + 'license': 'AGPL-3', + 'summary': "Glue module between base_partner_prospect and sale modules", + 'description': """ +Sale Partner Prospect +===================== + +This is a glue module between *base_partner_prospect* and *sale* modules. When you confirm a sale order, the partner will be converted from a prospect to a customer. + +This module has been written by Alexis de Lattre from Akretion +. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['sale', 'base_partner_prospect'], + 'data': [ + 'sale_view.xml', + ], + 'installable': True, + 'auto_install': True, +} diff --git a/sale_partner_prospect/sale.py b/sale_partner_prospect/sale.py new file mode 100644 index 0000000..870f489 --- /dev/null +++ b/sale_partner_prospect/sale.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# © 2015-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, api, _ + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + @api.multi + def action_confirm(self): + vals = { + 'prospect': False, + 'customer': True} + for order in self: + msg = _( + 'Validation of sale order %s triggered the conversion ' + 'of this partner from prospect to customer.') % order.name + if order.partner_id.prospect: + order.partner_id.write(vals) + order.partner_id.message_post(msg) + if ( + order.partner_id.parent_id and + order.partner_id.commercial_partner_id.prospect): + order.partner_id.commercial_partner_id.write(vals) + order.partner_id.commercial_partner_id.message_post(msg) + return super(SaleOrder, self).action_confirm() diff --git a/sale_partner_prospect/sale_view.xml b/sale_partner_prospect/sale_view.xml new file mode 100644 index 0000000..56eab1a --- /dev/null +++ b/sale_partner_prospect/sale_view.xml @@ -0,0 +1,32 @@ + + + + + + + sale_partner_prospect.sale.order.form + sale.order + + + + ['|', ('prospect', '=', True), ('customer', '=', True)] + + + + + + sale_partner_prospect.partner.form + res.partner + + + + + + +