跳至内容
菜单
此问题已终结
1 回复
191 查看

Hi,


I've setup odoo with the product catalogue of our company.


We sell food products per box, and pricing is per item.

For example we have a can of cola, and a tray of 24 cans. The price is per can.

I've created packaging (piece and box). 


So when I do an entry in an order, when i sell 2 trays, i enter 48. And it calculates that it's 2 trays. 

Installed this module : https://github.com/OCA/sale-workflow/tree/16.0/sale_packaging_default to make entry based on tray's instead of items. Which helps us.


When looking at picking / invoicing / orders. It's displayed as :  48 units (2 box), which is good.


So now my question:

Sometimes it happens that we sell 40 items instead of 48 (because there is nothing more in stock, or some other reason). That means that we have 1 full tray and 16 pieces.

Odoo changes that into 40 items.

 

I would rather have it displaying on my documents as : 40 units (1 box + 16 pieces).

Anyone have a suggestion how to create this? I'm pretty good in qweb xpath.

An option (although not preferred) is to have 2 order-lines (1 box on one line, the 16 pieces on another line).

形象
丢弃
最佳答案

You're on the right track with your current setup using the sale_packaging_default module. It’s great that Odoo is showing “48 units (2 box)” - that means the packaging configuration is working as intended.

To achieve your desired output of mixed packaging display like:

40 units (1 box + 16 pieces)

…you’d need a bit of customization in the QWeb report templates and a small addition in the compute logic for how packaging is represented.

✅ Here's how you can do it:

1. Custom Compute Method

Create a custom computed field (inherited on sale.order.line) to store a "packaging breakdown" string.

Example Python logic (in a custom module):

from odoo import models, fields, api


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'


    packaging_info = fields.Char(string="Packaging Info", compute="_compute_packaging_info")


    @api.depends('product_uom_qty', 'product_id')

    def _compute_packaging_info(self):

        for line in self:

            if line.product_id and line.product_id.packaging_ids:

                # Assume box packaging is defined

                box_pack = line.product_id.packaging_ids.filtered(lambda p: 'box' in p.name.lower())

                if box_pack:

                    box_qty = int(line.product_uom_qty // box_pack.qty)

                    rem_qty = int(line.product_uom_qty % box_pack.qty)

                    if box_qty > 0 or rem_qty > 0:

                        line.packaging_info = f"{int(line.product_uom_qty)} units ({box_qty} box + {rem_qty} pieces)"

                    else:

                        line.packaging_info = f"{int(line.product_uom_qty)} units"

                else:

                    line.packaging_info = f"{int(line.product_uom_qty)} units"


2. Customize QWeb Reports

Now in your QWeb report (like sale.order, stock.picking, or account.move), use XPath to replace the default quantity field with this new packaging_info field.

xml

CopyEdit

<t t-if="line.packaging_info"> <span t-esc="line.packaging_info"/> </t>


At Yantradhiagham, we specialize in custom Odoo solutions for FMCG and distribution companies, including advanced packaging, unit conversions, and report customization. If you'd like hands-on help or want to discuss how we can streamline your sales workflow even further — feel free to DM or reach out! sagar.s@yalabs.in

形象
丢弃
相关帖文 回复 查看 活动
1
6月 25
420
1
6月 25
551
3
5月 25
624
3
5月 25
914
1
5月 25
645