I am trying to use automated actions to add subscription lines to an existing subscription when one or more source records are created.
The quantity field from the source (record.x_studio_prod_qty) is populating correctly. Just not the product_id. It seems to default to the first product that appears alphabetically. The full code is below:
prod_int_id = record.x_studio_ret_prod_id
subscription_check = env['product.product'].search([('product_variant_id', '=', int(prod_int_id)),('recurring_invoice', '=', True)], limit=1)
subscription_header = env['sale.subscription'].search([('x_studio_parent_code', '=',
record.x_studio_parent_number)], limit=1)
add_subscription_check = {
'product_id': subscription_check.product_variant_ids[0].id,
'uom_id': subscription_check.uom_id.id,
'price_unit': subscription_check.list_price,
'quantity': record.x_studio_prod_qty
}
subscription_header.write({'recurring_invoice_line_ids':[(5, 0, 0),(0,0,add_subscription_check)]})
It works fine if the product_id is hardcoded in (as below) however, that defeats the purpose.....
'product_id': "800",
I have cobbled information together from other posts to get this far so would appreciate this final hurdle getting resolved.