تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
3062 أدوات العرض


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')

الصورة الرمزية
إهمال
الكاتب

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

it error show

الكاتب أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب

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

it error show

أفضل إجابة

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.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
أغسطس 25
2783
1
مايو 25
2746
1
أبريل 25
3717
1
أبريل 25
4580
1
أبريل 25
2027