Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3080 มุมมอง


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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ส.ค. 25
2807
1
พ.ค. 25
2754
1
เม.ย. 25
3724
1
เม.ย. 25
4583
1
เม.ย. 25
2032