Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
3071 Weergaven


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
Annuleer
Auteur

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

it error show

Auteur Beste antwoord

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

Avatar
Annuleer
Auteur

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

it error show

Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
3
aug. 25
2800
1
mei 25
2752
1
apr. 25
3722
1
apr. 25
4581
1
apr. 25
2031