1

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.

Bamidele
  • 11
  • 2

2 Answers2

1

Bamidele

Use id instead of the product_variant_id on the domain while you search the product id.

subscription_check = env['product.product'].search([('id', '=', int(prod_int_id)),('recurring_invoice', '=', True)], limit=1)

The field product_variant_id having on the template level to access the product but here you're getting the product id and also with a search on the product. Also, make sure that the computed field can not use and return the data on a search is it is not store true.

Dipen Shah
  • 2,396
  • 2
  • 9
  • 21
0

I ended up having to use automated action references and values all the way instead of python.

Bamidele
  • 11
  • 2