I'm developing a custom module that adds some functionality to the crm.lead, this module let you set a product on the lead when a customer choose a product to buy, a special requirement for our customer:
class CRMLeadProduct(models.Model):
_inherit = ["crm.lead"]
product_id = fields.Many2one('product.template',)
The problem is when the sale person press "new quotation" button, it necessary when that button is pressed the sale order must have and order line with the product from the lead, I try to do this:
class SaleOrder(models.Model):
_inherit = 'sale.order'
def _get_lead_product(self):
product_id = self.env['product.template'].search(
[('id', '=', self.opportunity_id.product_id.id)])
return [(4, {'order_id': self.id, 'product_id': product_id.id, 'product_uom_qty': 1, 'product_uom': 1, })]
order_line = fields.One2many(default=_get_lead_product)
But as the order still doesn't exist we can't set the order line, how can we accomplish this?