Is it possible to have a line item that is percentage based of the other lines on the sales order/invoices?
This wouldn't be a tax but a supplies charge that is based off the price of the other items being sold.
I've tried making a field in studio and making an automation but it doesn't seem to be working.
# Check if 'x_studio_shop_supplies' exists on any of the order lines lines_with_supplies = record.order_line.filtered(lambda line: line.x_studio_shop_supplies > 0) if lines_with_supplies: # Get the percentage value from the first line with 'x_studio_shop_supplies' percentage = lines_with_supplies[0].x_studio_shop_supplies / 100 # Calculate the sales order total (excluding taxes and any existing "Shop Supplies" lines) total = sum(line.price_subtotal for line in record.order_line if line.product_id.name != 'Shop Supplies') # Calculate the shop supplies fee based on the percentage shop_supplies_fee = total * percentage # Search for the "Shop Supplies" product fee_product = env['product.product'].search([('name', '=', 'Shop Supplies')], limit=1) if fee_product: # Check if a "Shop Supplies" line already exists existing_fee_line = record.order_line.filtered(lambda line: line.product_id == fee_product) if existing_fee_line: # Update the existing "Shop Supplies" line existing_fee_line.write({ 'price_unit': shop_supplies_fee }) else: # Add a new line using the Command namespace record.write({ 'order_line': [ Command.create({ 'product_id': fee_product.id, 'product_uom_qty': 1, 'price_unit': shop_supplies_fee, }) ] }) else: raise UserError("No order line with 'x_studio_shop_supplies' found.")