Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
3048 Ansichten


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
Verwerfen
Autor

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

it error show

Autor Beste Antwort

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

Avatar
Verwerfen
Autor

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

it error show

Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
3
Aug. 25
2755
1
Mai 25
2707
1
Apr. 25
3694
1
Apr. 25
4556
1
Apr. 25
2007