【问题标题】:How to merge Lot/Serial number如何合并批号/序列号
【发布时间】:2021-09-05 04:41:29
【问题描述】:

我想添加一个具有'stock.production.lot' 的Many2many 字段的向导,仅显示具有双倍Lot/Serial Number 的记录 我做了获取过滤记录的功能,现在我需要显示它

class DoublingNumber(models.TransientModel):
    _name = 'doubling.number'
    

    double_number_id =fields.Many2many('stock.production.lot' ,string="Numéros en doublant" )

     @api.multi
        def _default_double_number(self):
            log.warning("Hola")
            double_record = []
            records =self.env['stock.production.lot'].search([])
            for record in records :
                for record2 in records :
                    if record.name == record2.name and record.product_id != record2.product_id :
    
                        double_record.append(record2)    
                         
                        break
            return double_record

现在怎么显示??!

【问题讨论】:

  • 您可以使用default关键字指定计算double_number_id字段值并返回记录集的函数。你可以在calendar模块中找到一个例子,函数定义在585行

标签: view odoo wizard odoo-12


【解决方案1】:

尝试在字段定义中调用默认函数,但在字段之前定义函数,并按以下方式定义:

class DoublingNumber(models.TransientModel):
    _name = 'doubling.number'

    @api.model
    def _default_double_number(self):
        log.warning("Hola")
        double_record = self.env['stock.production.lot']
        records =self.env['stock.production.lot'].search([])
        for record in records :
            for record2 in records :
                if record.name == record2.name and record.product_id != record2.product_id :

                    double_record += record2  
                     
                    break
        return double_record
    
    double_number_id =fields.Many2many('stock.production.lot' ,string="Numéros en doublant", default = _default_double_number)

祝你好运:)

【讨论】:

  • 非常感谢,它就像一个魅力!
猜你喜欢
  • 2012-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-16
  • 2015-08-13
相关资源
最近更新 更多