'Odoo Sale order : wrong calcul qty_delivered in kit bom

I'm on Odoo 11, I'm on a particular case : I've got a product (GRI002) which has a BoM of "Kit" type. GRI002STK is the only component : enter image description here

When I do a sale order, I set 2 GRI002 for the ordered qty. I confirm. I go to the Delivery and I set 1 quantity done : enter image description here

It show me I can do a backorder, I clic Yes. So for the first picking I've got 1 Initial demand and 1 Done, and for the backorder I've got 1 Initial demand and 0 Done : enter image description here

In the sale order I should have 2 Ordererd qty and 1 delivered, but the problem is : I have 2 Ordererd qty and 0 delivered. enter image description here I have tested for products without BOM, and BoM to manufacure, it works in both cases.

So what is the function to compute the ordered qty ? I will patch it.

Do you have this problem ? I can't edit the BoM to kits because it does make Manifacturing Orders, and my customer doesn't want it.



Solution 1:[1]

I succeed by doing super() and recalculating :

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'


    @api.multi
    def _get_delivered_qty(self):
        self.ensure_one()

        #Hérite de sale/models/sale.py, de sale_stock/models/sale_order.py et de sale_mrp/models/sale_mrp.py
        qty = super(SaleOrderLine, self)._get_delivered_qty()

        #On recherche la nomenclature avec le produit actuel
        bom = self.env['mrp.bom']._bom_find(product=self.product_id)

        #Si c'est une nomenclature en kit
        if bom and bom.type == 'phantom':
            qty = 0   #obligé sinon les quantités seraient comptées 2x

            for move in self.move_ids:
                if move.state == 'done':
                    #on ajoute autant de quantité qu'il y en a dans le stock_move
                    qty = qty + move.quantity_done
        return qty

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kishiro