Prospect modules (different approch than the OCA module partner_prospect in sale-workflow)

This commit is contained in:
Alexis de Lattre
2017-02-02 00:24:20 +01:00
parent e353cdcad1
commit b518594136
12 changed files with 285 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import partner

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['base'],
'data': [
'partner_view.xml',
],
'installable': True,
}

View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# 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])

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">base_usability.title.on.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='sales_purchases']//group[@name='sale']/field[@name='customer']" position="after">
<field name="prospect"/>
</xpath>
</field>
</record>
<record id="view_res_partner_filter" model="ir.ui.view">
<field name="name">base_usability.partner.search.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_res_partner_filter"/>
<field name="arch" type="xml">
<filter name="customer" position="after">
<filter name="prospect" string="Prospects" domain="[('prospect', '=', True), ('parent_id', '=', False)]"/>
</filter>
</field>
</record>
<record id="partner_prospect_action" model="ir.actions.act_window">
<field name="name">Prospects</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree,form,kanban</field>
<field name="context">{'default_prospect': 1, 'search_default_prospect': 1}</field>
</record>
<!-- I don't add a menu entry ; it should be added in custom module if needed -->
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import crm

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['crm', 'base_partner_prospect'],
'data': [
'crm_view.xml',
],
'installable': True,
'auto_install': True,
}

View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# 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

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="crm_case_form_view_oppor" model="ir.ui.view">
<field name="name">crm_partner_prospect.crm.opportunity.form</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="domain">['|', ('prospect', '=', True), ('customer', '=', True)]</attribute>
<attribute name="context">{'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}</attribute>
</field>
</field>
</record>
<record id="view_crm_lead2opportunity_partner" model="ir.ui.view">
<field name="name">crm_partner_prospect.crm.lead2opportunity.partner.form</field>
<field name="model">crm.lead2opportunity.partner</field>
<field name="inherit_id" ref="crm.view_crm_lead2opportunity_partner"/>
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="domain">['|', ('prospect', '=', True), ('customer', '=', True)]}</attribute>
</field>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import sale

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['sale', 'base_partner_prospect'],
'data': [
'sale_view.xml',
],
'installable': True,
'auto_install': True,
}

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# © 2015-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# 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()

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale_partner_prospect.sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="attributes">
<attribute name="domain">['|', ('prospect', '=', True), ('customer', '=', True)]</attribute>
</field>
</field>
</record>
<record id="res_partner_view_buttons" model="ir.ui.view">
<field name="name">sale_partner_prospect.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="sale.res_partner_view_buttons"/>
<field name="arch" type="xml">
<button name="%(sale.act_res_partner_2_sale_order)d" position="attributes">
<attribute name="attrs">{'invisible': [('prospect', '=', False), ('customer', '=', False)]}</attribute>
</button>
</field>
</record>
</odoo>