不能适应类型产品。产品'从v8到v10

时间:2018-01-24 10:24:37

标签: python odoo-8 odoo

在odoo商店中有一个名为product_pack的模块,它包含一个文件product.py,该文件包含version 8中的函数,用于检查产品的可用性。

所以,在尝试将其转换为version 10之后,我在第6行和第11行中得到了一个错误。所以我的问题正是在转换res = super(product_product, self)._product_available(cr, uid, list(set(ids) - set(pack_product_ids)),field_names, arg, context)

它提出了:

  

pobjs = [在self._seq中适应(o)for o]       ProgrammingError:无法调整类型&product; product.product'

  • 第8版

    def _product_available(self, cr, uid, ids, field_names=None, arg=False, context=None):
    
        pack_product_ids = self.search(cr, uid, [('pack', '=', True),
        ('id', 'in', ids),])
        res = super(product_product, self)._product_available(
            cr, uid, list(set(ids) - set(pack_product_ids)),
            field_names, arg, context)
        for product in self.browse(cr, uid, pack_product_ids, context=context):
            pack_qty_available = []
            pack_virtual_available = []
            for subproduct in product.pack_line_ids:
                subproduct_stock = self._product_available(cr, uid, [subproduct.product_id.id], field_names, arg,
                    context)[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))
            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
    
  • 第10版

    def _product_available(self, field_names=None, arg=False):
    
            pack_product_ids = self.search([('pack', '=', True)])
            ###res = super(product_product, self)._product_available(field_names, arg)
            for product in self.browse(pack_product_ids):
                pack_qty_available = []
                pack_virtual_available = []
            for subproduct in product.pack_line_ids:
                subproduct_stock = self._product_available([subproduct.product_id.id], field_names, arg)[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))
            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
    

提前致谢

2 个答案:

答案 0 :(得分:0)

它确实可以使用这个;

@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

答案 1 :(得分:-1)

试试这个:

@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