如何使用创建函数 odoo 13 将产品添加到 sale.subscription 订单行
how to add product to sale.subscription order line using the create function odoo 13
无法弄清楚如何使用另一个模型
的创建函数向 sale.subscription 添加一行
subscription_pak = self.env['product.template'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1)
subscription_info = {
'partner_id': vals['name'],
}
add_subscription = self.env['sale.subscription'].create(subscription_info)
print('ssssss',subscription_pak)
#works
add_subscription_pak = {
'product_id': subscription_pak.id,
'partner_id': add_subscription.id,
}
link_user_to_subscription = self.env['sale.subscription.line'].create(add_subscription_pak)
我正在创建订阅,但找不到用于向行添加产品的字段
你能帮忙吗
您的 subscription_pak 类型为 product.template
(产品模板),但 sale.subscription.line
的 product_id 字段需要 product.product
(产品(变体)) (不能 link 因为它是 Odoo Enterprise)
所以这应该有效(如果您的产品只有一种变体):
...
add_subscription_pak = {
'product_id': subscription_pak.product_variant_id.id,
'partner_id': add_subscription.id,
}
...
对于多个变体:
...
add_subscription_pak = {
'product_id': subscription_pak.product_variant_ids.filter(lambda pv: pv.attribute == 'value')[0].id,
'partner_id': add_subscription.id,
}
...
感谢 YouTube 上的 odoo Mates,此视频来自 odoo Mates 频道 How To Update One2many Field From OnChange Of Field in Odoo 和@bigbear3001
这对我有用
supsctiption_pak = self.env['product.product'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1)
supsctiption_info = {
'partner_id': vals['name'],
}
add_supsctiption = self.env['sale.subscription'].create(supsctiption_info)
supsctiption_to_pak = self.env['sale.subscription'].search([('partner_id', '=', vals['name'])], limit=1)
add_supsctiption_pak = {
'product_id': supsctiption_pak.product_variant_id.id,
'uom_id': supsctiption_pak.uom_id.id,
'price_unit': supsctiption_pak.list_price,
}
supsctiption_to_pak.write({'recurring_invoice_line_ids':[(5, 0, 0),(0,0,add_supsctiption_pak)]})
无法弄清楚如何使用另一个模型
的创建函数向 sale.subscription 添加一行 subscription_pak = self.env['product.template'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1)
subscription_info = {
'partner_id': vals['name'],
}
add_subscription = self.env['sale.subscription'].create(subscription_info)
print('ssssss',subscription_pak)
#works
add_subscription_pak = {
'product_id': subscription_pak.id,
'partner_id': add_subscription.id,
}
link_user_to_subscription = self.env['sale.subscription.line'].create(add_subscription_pak)
我正在创建订阅,但找不到用于向行添加产品的字段
你能帮忙吗
您的 subscription_pak 类型为 product.template
(产品模板),但 sale.subscription.line
的 product_id 字段需要 product.product
(产品(变体)) (不能 link 因为它是 Odoo Enterprise)
所以这应该有效(如果您的产品只有一种变体):
...
add_subscription_pak = {
'product_id': subscription_pak.product_variant_id.id,
'partner_id': add_subscription.id,
}
...
对于多个变体:
...
add_subscription_pak = {
'product_id': subscription_pak.product_variant_ids.filter(lambda pv: pv.attribute == 'value')[0].id,
'partner_id': add_subscription.id,
}
...
感谢 YouTube 上的 odoo Mates,此视频来自 odoo Mates 频道 How To Update One2many Field From OnChange Of Field in Odoo 和@bigbear3001
这对我有用
supsctiption_pak = self.env['product.product'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1)
supsctiption_info = {
'partner_id': vals['name'],
}
add_supsctiption = self.env['sale.subscription'].create(supsctiption_info)
supsctiption_to_pak = self.env['sale.subscription'].search([('partner_id', '=', vals['name'])], limit=1)
add_supsctiption_pak = {
'product_id': supsctiption_pak.product_variant_id.id,
'uom_id': supsctiption_pak.uom_id.id,
'price_unit': supsctiption_pak.list_price,
}
supsctiption_to_pak.write({'recurring_invoice_line_ids':[(5, 0, 0),(0,0,add_supsctiption_pak)]})