Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
965 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona

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

Risposta migliore

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

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
3
lug 25
2031
1
giu 25
2396
2
mag 25
2006
1
mag 25
1214
1
feb 25
38