Odoo Help


How to add a new field into Leads and pass it to Opportunity and then to Sale Quotation? [Closed]

on 3/21/13, 11:55 AM 3,191 views

The Question has been closed

on 04/23/2013 14:55:28


I would like to create new field on Leads/Opportunities and then when this Opportunity is converted to sale quotation or sales order, I want keep this field in the form of sale quotation.



| 5 4 8
Casablanca, Morocco
On 3/21/13, 12:16 PM

I suggest you to:
1- Create the same field in the sale.order object
2- Override the makeOrder method in "sale_crm/wizard/crm_make_sale.py" by passing the field value in vals

in your .py file add a class that inherit from crm.make.sale object

class crm_make_sale_inherit(osv.osv_memory):

    _inherit = "crm.make.sale"

    def makeOrder(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        # update context: if come from phonecall, default state values can make the quote crash lp:1017353
        context.pop('default_state', False)        

        case_obj = self.pool.get('crm.lead')
        sale_obj = self.pool.get('sale.order')
        partner_obj = self.pool.get('res.partner')
        data = context and context.get('active_ids', []) or []

        for make in self.browse(cr, uid, ids, context=context):
            partner = make.partner_id
            partner_addr = partner_obj.address_get(cr, uid, [partner.id],
                    ['default', 'invoice', 'delivery', 'contact'])
            pricelist = partner.property_product_pricelist.id
            fpos = partner.property_account_position and partner.property_account_position.id or False
            new_ids = []
            for case in case_obj.browse(cr, uid, data, context=context):
                if not partner and case.partner_id:
                    partner = case.partner_id
                    fpos = partner.property_account_position and partner.property_account_position.id or False
                    partner_addr = partner_obj.address_get(cr, uid, [partner.id],
                            ['default', 'invoice', 'delivery', 'contact'])
                    pricelist = partner.property_product_pricelist.id
                if False in partner_addr.values():
                    raise osv.except_osv(_('Insufficient Data!'), _('No addresse(s) defined for this customer.'))

                vals = {
                    'origin': _('Opportunity: %s') % str(case.id),
                    'section_id': case.section_id and case.section_id.id or False,
                    'categ_ids': [(6, 0, [categ_id.id for categ_id in case.categ_ids])],
                    'shop_id': make.shop_id.id,
                    'partner_id': partner.id,
                    'pricelist_id': pricelist,
                    'partner_invoice_id': partner_addr['invoice'],
                    'partner_shipping_id': partner_addr['delivery'],
                    'date_order': fields.date.context_today(self,cr,uid,context=context),
                    'fiscal_position': fpos,
                     ## for simple fields: char, integer, float, text
                    'field1': case.field_name_in_lead_object 
                     ## for many2one fields
                    'field2': case.field_name_in_lead_object2 and case.field_name_in_lead_object2.id 

                if partner.id:
                    vals['user_id'] = partner.user_id and partner.user_id.id or uid
                new_id = sale_obj.create(cr, uid, vals, context=context)
                sale_order = sale_obj.browse(cr, uid, new_id, context=context)
                case_obj.write(cr, uid, [case.id], {'ref': 'sale.order,%s' % new_id})
                message = _("Opportunity has been <b>converted</b> to the quotation <em>%s</em>.") % (sale_order.name)
            if make.close:
                case_obj.case_close(cr, uid, data)
            if not new_ids:
                return {'type': 'ir.actions.act_window_close'}
            if len(new_ids)<=1:
                value = {
                    'domain': str([('id', 'in', new_ids)]),
                    'view_type': 'form',
                    'view_mode': 'form',
                    'res_model': 'sale.order',
                    'view_id': False,
                    'type': 'ir.actions.act_window',
                    'name' : _('Quotation'),
                    'res_id': new_ids and new_ids[0]
                value = {
                    'domain': str([('id', 'in', new_ids)]),
                    'view_type': 'form',
                    'view_mode': 'tree,form',
                    'res_model': 'sale.order',
                    'view_id': False,
                    'type': 'ir.actions.act_window',
                    'name' : _('Quotation'),
                    'res_id': new_ids
            return value

crm_make_sale_inherit() </br>

Don't forget to update the vals dict with your name fields.

In first place thanks for your answer, I'm a newbie in OpenErp and for me the first point was easy, but the second one I don't know where to start... How do I add the new field in the vals of makeOrder? I trying not to edit the files from OpenERP, I doing a new module to do all the changes that I need. This module that I've created inherit class from modules that I need and after this I edit with changes that I need.

on 3/21/13, 3:11 PM

Hi Luis, I have already developed such model for myself, please have a look into the module: https://www.dropbox.com/sh/tj11nebi5zpj9vs/AACWEqw64hMzlV39rJo1KFGSa?dl=0

Sayed Anisul Hoque
on 10/22/15, 2:58 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 3/21/13, 11:55 AM
Seen: 3191 times
Last updated: 9/16/16, 11:24 AM