Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
926 Vistas

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.")

Avatar
Descartar
Mejor respuesta

Since you are using the sales module, check out the module "Club SO lines" by intelliversal integrated solutions. This module groups the products written under a section with marked checkbox and shows them as a single product to the customer in their invoice.

Avatar
Descartar

seems marketing the paid apps which is not relevant to the asked question

Mejor respuesta

Can you share what configuration did you used in that automated action(like model, trigger etc) ?

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jul 25
1940
1
jun 25
2216
2
may 25
1935
1
may 25
1173
1
feb 25
38