跳至內容
選單
此問題已被標幟
2 回覆
906 瀏覽次數

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

頭像
捨棄
最佳答案

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.

頭像
捨棄

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

最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
7月 25
1922
1
6月 25
2185
2
5月 25
1921
1
5月 25
1163
1
2月 25
38