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

opportunity.py

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}

}

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"

Please help me. I'm not getting the current record id in the wizard py file. Using this wizard I need to change the corresponding quotation to the done stage. How did i need to change my code?

Avatar
Discard
Author

for quotation in quotation_ids:

quotation.state = "Done"

I want to update quotation state to Done. but above code piece is not working. plz correct me.

Best Answer

check self.env.context.get('active_id') ,Active  ID is parent reference

Avatar
Discard
Author

def _get_all_quotations(self):

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

in the above function how can i get the sales quotation based the active id. Plz help.

You are getting the crm.lead model id and trying to browse sale.order. Here is the conflict. If you need to pass sale relation in context then pass self.sale_order_reference_field.id in context instead of current active id.

Author

in sale.order model--there is a field named opportunity_id, which stores opportunity id from crm.lead.

self.env['sale.order'].browse(self.env.context.get('opportunity_id'='current_id'))

then the above code is correct? if not, plz correct me

while browsing you get the defined model, eg: sale order of id equal to opportunity id as you defined. instead, do search self.env['sale.order'].search([('opportunity_id','=',self.env.context.get('opportunity_id' )])

Author

Hi Hilar,

I need amount_total from the particular sale order self.env['sale.order'].search([('opportunity_id','=',self.env.context.get('opportunity_id' )])

How can i get that value. Plz help.