Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
921 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć

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

Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
lip 25
1937
1
cze 25
2211
2
maj 25
1932
1
maj 25
1171
1
lut 25
38