Skip to Content
Menu
This question has been flagged
2 Replies
2206 Views


class CrmInherit(models.Model):
_inherit = 'crm.lead'
	​crm_lead_transfer_line_ids = fields.One2many('crm.lead.transfer.line', 'crm_lead_transfer_line_id',
)

	​def quotation_create(self):
self.ensure_one()
inv_lines = []
sale_order = self.env['sale.order']
for line_items in self.crm_lead_transfer_line_ids:
tmp = {
"product_template_id": line_items.vehicle_name,
"name"
: line_items.vehicle_name,
"product_uom_qty"
: 2,
'price_unit'
: 6,
}
inv_lines.append([0, False, tmp])

order_values = {
'partner_id': self.partner_id.id,
"order_line"
: inv_lines,
}
self.env['sale.order'].create(order_values)

class CrmInheritLine(models.Model):
_name = 'crm.lead.transfer.line'

vehicle_name = fields.Char(string="Vehicle Name")
vehicle_category = fields.Char(string="Vehicle Category")
crm_lead_transfer_line_id = fields.Many2one('crm.lead')

Avatar
Discard
Author

The operation cannot be completed: Missing required fields on accountable sale order line.

it error show

Author Best Answer

I added above this function but it shows an error "The operation cannot be completed: Missing required fields on accountable sale order line."

Avatar
Discard
Author

The operation cannot be completed: Missing required fields on accountable sale order line.

it error show

Best Answer

To add values into the sale.order.line by a function from the crm module in Odoo 16, you can use the quotation_create function in the CrmInherit class that inherits from the crm.lead model.

In this function, you can first retrieve the crm.lead.transfer.line records related to the current crm.lead record using the crm_lead_transfer_line_ids one2many field. Then, for each of these lines, you can create a dictionary containing the values you want to add to the sale.order.line, such as the product template, name, quantity, and price.

You can then append this dictionary to a list of invoice lines, and use this list to create a new sale.order record with the partner_id and order_line fields set to the appropriate values.

Here is an example:

class CrmInherit(models.Model):
    _inherit = 'crm.lead'

    crm_lead_transfer_line_ids = fields.One2many('crm.lead.transfer.line', 'crm_lead_transfer_line_id',string='Transfer Lines')

    def quotation_create(self):
        self.ensure_one()
        inv_lines = []
        for line_items in self.crm_lead_transfer_line_ids:
            tmp = {
                "product_template_id": line_items.vehicle_name.id,
                "name": line_items.vehicle_category,
                "product_uom_qty": 1,
                'price_unit': line_items.price,
            }
            inv_lines.append((0, 0, tmp))

        order_values = {
            'partner_id': self.partner_id.id,
            "order_line": inv_lines,
        }
        self.env['sale.order'].create(order_values)

In this example, the values for product template,name,quantity and price unit comes from the crm.lead.transfer.line model.

Avatar
Discard
Related Posts Replies Views Activity
3
Nov 24
2947
5
Nov 24
7457
2
Oct 24
2883
4
Oct 24
1864
2
Oct 24
4017