This question has been flagged
1 Reply
3875 Views

I want to set a Commission Rate on each subscription product on the Sales Order.

I then want that same Rate shown on the Subscription Line on the related Subscription.

I then want to show that same rate on the Invoice, so that when I report on Invoice lines, I know what to pay each person based on the percentage on the Sales Order.

I also need to update the Subscription Line percentages - as in some cases the original Rate will go up after the first renewal.

Avatar
Discard
Best Answer

A Sale Order Line has a Subscription ID.

You can navigate from the Sale Order Line to the Subscription to the Subscription Lines, find the matching product and move the commission rate over that way.

Note:  This code sample doesn't do anything apart from look for a matching product.  If you have different rates for the same product on the Sales Order it won't work - this is just meant to get you started.

You can probably create a related field on the Invoice to grab the rate from the Subscription Line.

1. Create a Server Action that you add to the Form View of the Sales Order via a custom BUTTON. 

# confirm the Sales Order
record.action_confirm()

# do we have order lines?
if record.order_line:

# loop through order lines
for so_line in record.order_line:

#do we have a subscription created and linked to the so line
if so_line.subscription_id:

#do we have lines on the subscription?
if so_line.subscription_id.recurring_invoice_line_ids:

#loop through the subscription lines
for sub_line in so_line.subscription_id.recurring_invoice_line_ids:

#do the products match?
if so_line.product_id.id == sub_line.product_id.id:

#copy commission
sub_line['x_commission'] = so_line.x_commission


2. Hide the CONFIRM ORDER button so users use your button instead.

Avatar
Discard