user3676872
user3676872

Reputation: 204

can't adapt type 'product.product' from v8 to v10

in odoo store there is a module called product_pack, it contains a file product.py, this file contains the function bellow in version 8 which is made to check product availability .

so, after trying to convert it to version 10 I got an error exactly in line 6 and line 11. so my problem is exactly in converting res = super(product_product, self)._product_available(cr, uid, list(set(ids) - set(pack_product_ids)),field_names, arg, context)

it raises:

pobjs = [adapt(o) for o in self._seq] ProgrammingError: can't adapt type 'product.product'

Thanks in advance

Upvotes: 1

Views: 247

Answers (2)

user3676872
user3676872

Reputation: 204

it did work using this one;

@api.multi
def _product_available(self, field_names=None, arg=False):
    pack_products = self.filtered(lambda p: p.pack == True)
    res = super(product_product, self - pack_products)._product_available(field_names, arg)

    for product in pack_products:
        pack_qty_available = []
        pack_virtual_available = []
        for pack_line in product.pack_line_ids:
            subproduct_stock = pack_line.product_id._product_available(field_names, arg)[pack_line.product_id.id]
            sub_qty = pack_line.quantity
            if sub_qty:
                pack_qty_available.append(math.floor(
                    subproduct_stock['qty_available'] / sub_qty))
                pack_virtual_available.append(math.floor(
                    subproduct_stock['virtual_available'] / sub_qty))
        # TODO calcular correctamente pack virtual available para negativos
        res[product.id] = {
            'qty_available': (
                pack_qty_available and min(pack_qty_available) or False),
            'incoming_qty': 0,
            'outgoing_qty': 0,
            'virtual_available': (
                pack_virtual_available and min(pack_virtual_available) or False),
        }
    return res

Upvotes: 0

imad
imad

Reputation: 189

try this one:

@api.depends('stock_quant_ids', 'stock_move_ids')
def _compute_quantities(self):
    packs = self.filtered('pack')
    no_packs = (self + packs.mapped('pack_line_ids.product_id')) - packs
    res = super(ProductProduct, no_packs)._compute_quantities()
    for product in packs:
        pack_qty_available = []
        pack_virtual_available = []
        for subproduct in product.pack_line_ids:
            subproduct_stock = res[subproduct.product_id.id]
            sub_qty = subproduct.quantity
            if sub_qty:
                pack_qty_available.append(math.floor(
                    subproduct_stock['qty_available'] / sub_qty))
                pack_virtual_available.append(math.floor(
                    subproduct_stock['virtual_available'] / sub_qty))
        # TODO calcular correctamente pack virtual available para negativos
        res[product.id] = {
            'qty_available': (
                pack_qty_available and min(pack_qty_available) or False),
            'incoming_qty': 0,
            'outgoing_qty': 0,
            'virtual_available': (
                pack_virtual_available and
                max(min(pack_virtual_available), 0) or False),
        }
    return res

Upvotes: -1

Related Questions