Skip to Content
Menú
This question has been flagged

Hi,

i need custom that named "Service Fee %" in sales order line like image below,


i noticed the service fee that i input didn't automatically change the total amount(field : subtotal) of in sales order line, i think i need an automation rule so the total amount change when i input the service fee. So, i did like this

BUT, when i make new sales order and input the quantity, price, etc and save it. Seem like an error appear and my Odoo frezeed. Any solution of this or the best approach for this case? 

Avatar
Descartar
Best Answer

Hii,

Solution (No Code, No Studio)

1. Stop updating price_subtotal — it's a computed field.

2. Do this instead:

  • Create a new float field: x_service_fee_percent on sale.order.line
  • Create a new monetary field: x_adjusted_subtotal on sale.order.line (linked to currency_id)
  • Automation Rule (Safe Calculation)
  • Go to Settings → Technical → Automation → Automated Actions → Create:
    • Model: Sale Order Line
    • Trigger: On Creation & Update
    • Trigger Fields: x_service_fee_percent, price_unit, product_uom_qty, discount
    • Action To Do: Update the Record
  • Field to update:
  • x_adjusted_subtotal → Use this expression:

add this code in automation rule:

((record.price_unit * record.product_uom_qty) * (1 - (record.discount or 0)/100.0)) * (1 + (record.x_service_fee_percent or 0)/100.0)
i hope it is usefull

Avatar
Descartar
Autor

Hi, Thank you so much that work really well, but i still have an issue. Please check my new reply, i hope u can help

Best Answer

Hello @Zulfikri,

 

Add the Action named 'Execute Python code' in Your Automated Action as shown in below image.

 



After that add below Python code in your automated action.

 

# Step-by-step safe evaluation of subtotal with service fee

 

# Step 1: Get quantity

qty = record.product_uom_qty or 0.0

 

# Step 2: Get unit price

price = record.price_unit or 0.0

 

# Step 3: Get service fee (as percentage, e.g. 0.10 = 10%)

fee = record.x_studio_service_fee or 0.0

 

# Step 4: Compute multiplier

multiplier = 1.0 + fee

 

# Step 5: Calculate total with service fee

total_with_fee = qty * price * multiplier

 

# Step 6: Store in custom field

record.write({'x_studio_service_fee' : total_with_fee})

 

If you have any questions or need further assistance, feel free to reach out.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Avatar
Descartar
Autor

Hi, thank you so much, i have tried something like that, seems like it only make an change visually, am i right?. I still cant change the total on the bottom of the order line, invoice, and for the journal item as well

Autor Best Answer

Hi Desk Enterprise,

Thank you so much that work really well, but i still have an issue. How to change the "Total" (which I marked with a red box) below the sales order line so it can updated based on "Total Amount" that we already customized?


Avatar
Descartar

Override price_subtotal (Recommended for direct integration)
Instead of using x_adjusted_subtotal, override the standard field price_subtotal with your formula.
Update your Automation Rule:
Model: Sale Order Line

Trigger: On Update & Create

Trigger Fields: x_service_fee_percent, price_unit, discount, product_uom_qty

Action: Update the Record

Update Field: price_subtotal

Value:
((record.price_unit * record.product_uom_qty) * (1 - (record.discount or 0)/100.0)) * (1 + (record.x_service_fee_percent or 0)/100.0)
i hope this is solve the error

Best Answer

Dear Zulfikri,

here's how to implement this entirely through the Odoo interface:

Method 1: Using Studio (Recommended)
  1. Install Studio
    • Go to Settings → Apps → Search for "Studio" → Install
  2. Add the Service Fee % Field
    • Open any Sales Order
    • Click the "Edit Form" button (pencil icon) in top-right
    • Click "+" to add a new field
    • Field Name: x_service_fee_percent
    • Field Label: "Service Fee %"
    • Field Type: Float
    • Widget: Percentage (or Monetary if you prefer currency format)
    • Save the field
  3. Create an Automated Action
    • Go to Settings → Technical → Automation → Automated Actions
    • Create a new record:
      • Name: "Update Subtotal with Service Fee"
      • Model: Sales Order Line
      • Trigger: On Update
      • Apply On: [Your specific domain if needed, or leave blank]
    • In "Actions To Do" tab:
      • Add Action → Execute Python Code
      • Paste this (simplified version that won't cause recursion):

python

for line in records:
    price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
    fees = line.x_service_fee_percent or 0.0
    line.price_subtotal = price * line.product_uom_qty * (1 + fees / 100.0)
Method 2: Using Only Standard Features

If you can't use Studio, try this workaround:

  1. Create a Discount Field Workaround
    • Go to Settings → Technical → Database Structure → Fields
    • Create a new field:
      • Model: sale.order.line
      • Field Name: x_service_fee_percent
      • Field Type: Float
      • Label: "Service Fee %"
  2. Modify the Sales Order Line View
    • Go to Settings → Technical → User Interface → Views
    • Find the sale.order.line form view
    • Click "Edit" and add your field after price_unit
  3. Use a Computed Field (Still no-code)
    • In the same Fields section, edit your x_service_fee_percent field
    • Check "Computed"
    • For the compute method, use:
      python
      def _compute_service_fee(self):
          for line in self:
              line.x_service_fee_percent = line.price_subtotal * 0.10  # Example 10% fee
Important Notes
  1. Performance Warning: No-code solutions may be less efficient than proper code implementations
  2. Backup First: Always backup your database before making structural changes
  3. Testing: Try this in a test environment first

Alternative: Consider using the "Margin" field that already exists in Sales if it meets your needs

🚀 Did This Solve Your Problem?

If this answer helped you save time, money, or frustration, consider:

✅ Upvoting (👍) to help others find it faster

✅ Marking as "Best Answer" if it resolved your issue

Your feedback keeps the Odoo community strong! 💪

(Need further customization? Drop a comment—I’m happy to refine the solution!)

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
d’abr. 25
771
2
de des. 23
1669
1
de jul. 25
1182
1
de maig 25
1062
2
d’abr. 25
1797