Small improvements :
- when lead is marked as lost, related quotes are cancelled - when you create a lead from a quote, its stage will be "proposition"
This commit is contained in:
@@ -18,6 +18,8 @@ This module adds a One2many link from opportunities to sale orders.
|
|||||||
When a sale order linked to an opportunity is confirmed, the opportunity
|
When a sale order linked to an opportunity is confirmed, the opportunity
|
||||||
is automatically moved to the *Won* step.
|
is automatically moved to the *Won* step.
|
||||||
|
|
||||||
|
When you click on the button *Mark as lost* on an opportunity, the related quotations (*draft* or *sent* state) are automatically cancelled.
|
||||||
|
|
||||||
This module has been written by Alexis de Lattre from Akretion
|
This module has been written by Alexis de Lattre from Akretion
|
||||||
<alexis.delattre@akretion.com>.
|
<alexis.delattre@akretion.com>.
|
||||||
""",
|
""",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
|
||||||
from openerp import models, fields, api, _
|
from openerp import models, fields, api, _, workflow
|
||||||
from openerp.exceptions import Warning as UserError
|
from openerp.exceptions import Warning as UserError
|
||||||
|
|
||||||
|
|
||||||
@@ -59,3 +59,31 @@ class CrmLead(models.Model):
|
|||||||
else:
|
else:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
'There are no quotations linked to this opportunity'))
|
'There are no quotations linked to this opportunity'))
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def create(self, vals):
|
||||||
|
if vals is None:
|
||||||
|
vals = {}
|
||||||
|
if self._context.get('usability_default_stage_xmlid'):
|
||||||
|
stage = self.env.ref(self._context['usability_default_stage_xmlid'])
|
||||||
|
vals['stage_id'] = stage.id
|
||||||
|
return super(CrmLead, self).create(vals)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def case_mark_lost(self):
|
||||||
|
"""When opportunity is marked as lost, cancel the related quotations
|
||||||
|
I don't inherit the write but the button, because it leaves a waty to
|
||||||
|
mask lead as lost and not cancel the quotations
|
||||||
|
"""
|
||||||
|
res = super(CrmLead, self).case_mark_lost()
|
||||||
|
sales = self.env['sale.order'].search([
|
||||||
|
('lead_id', 'in', self.ids),
|
||||||
|
('state', 'in', ('draft', 'sent'))])
|
||||||
|
for so in sales:
|
||||||
|
workflow.trg_validate(
|
||||||
|
self._uid, 'sale.order', so.id, 'cancel', self._cr)
|
||||||
|
so.message_post(_(
|
||||||
|
'The related opportunity has been marked as lost, '
|
||||||
|
'therefore this quotation has been automatically cancelled.'))
|
||||||
|
return res
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<field name="pricelist_id" position="after">
|
<field name="pricelist_id" position="after">
|
||||||
<field name="lead_id"
|
<field name="lead_id"
|
||||||
domain="[('type', '=', 'opportunity'), ('partner_id', '=', partner_id)]"
|
domain="[('type', '=', 'opportunity'), ('partner_id', '=', partner_id)]"
|
||||||
context="{'default_type': 'opportunity', 'default_partner_id': partner_id, 'default_user_id': uid, 'stage_type': 'opportunity'}"/>
|
context="{'default_type': 'opportunity', 'default_partner_id': partner_id, 'default_user_id': uid, 'stage_type': 'opportunity', 'usability_default_stage_xmlid': 'crm.stage_lead4'}"/>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user