Skip to Content
Menu
This question has been flagged
1 Reply
2541 Views

I want to give a condition on opportunity won stage.

First, I created an opportunity, then I will create a quotation against that opportunity. 

When the opportunity becomes won. I will convert the opportunity to the won stage. In that won button, I needed to inherit. 

When I click on the opportunity won button, it will automatically convert its corresponding quotation to the Done stage.

How can implement this?

Below is my code:

class Opportunity(models.Model):
_inherit = "crm.lead"

@api.multi
def action_set_won(self, context=None):



return {
'name': _('Project Confirmations'),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'crm.won',
'target': 'new',
'context': {'opportunity_id': self.id}

}

In my wizard.py

from openerp import models, fields, api


class crm_won(models.TransientModel):
_name = 'crm.won'

def _get_all_quotations(self):
return self.env['sale.order'].browse(self.env.context.get('opportunity_id'))

quotation_ids = fields.Many2one('sale.order', string='Quotations', default=_get_all_quotations)

update_quotation = fields.Selection([('yes', 'YES'), ('no', 'NO')], string='Update Quotation Stage')
opportunity_id = fields.Many2one('crm.lead',string='opportunity')


@api.multi
def update_opportunity(self):
for record in self:
if self.env['crm.lead'].search([('opportunity_id','=',self.opportunity_id)]):
quotation_ids
if record.update_quotation == "YES":
for quotation in quotation_ids:
quotation.state = "Done"

But some missing in my code. I don't know, what is the issue. Can anyone please help me?

def _get_all_quotations(self): 
this function is not working properply. Anything is missing in this funtion?






Avatar
Discard
Author Best Answer

self.env['sale.order'].search([('opportunity_id','=',self.env.context.get('opportunity_id' )])

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 24
28
1
Dec 24
65
0
Nov 24
52
0
Nov 24
62
1
Oct 24
169