跳至内容
菜单
此问题已终结
5369 查看

Here is my code:

 barcode_ids = fields.One2many('product.template.barcode','product_id','barcode',store=True ,compute='_compute_barcode',inverse='_set_barcode')#Нэмэлтээр бар код үүсгэх
  @api.depends('product_variant_ids', 'product_variant_ids.barcode_ids')
  def _compute_barcode(self):
  unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1)
  for template in unique_variants:
  template.barcode_ids.barcode = template.product_variant_ids.barcode_ids.barcode
  for template in (self-unique_variants):
  template.barcode_ids.barcode = ''
  @api.one
  def _set_barcode(self):
  if len(self.product_variant_ids) == 1:
  for line in self:
  line.product_variant_ids.barcode_ids.barcode = self.barcode_ids.barcode
class ProductTemplateBarcode(models.Model):
  _name = 'product.template.barcode'
  barcode = fields.Char('Barcode',store=True)
  product_id = fields.Many2one('product.product',store=True)

error is:

ValueError: Expected singleton: product.template.barcode(29, <odoo.models.NewId object at 0x7f7b7c4ff6d0>)

How to fix?  Can any one guide me please
\\My goal is "The barcode adds to the product bar and does not add to the product"

                        "The barcode adds to the product and add to the product variant"

形象
丢弃

you have too many results. it says " I want one,don't throw everything at once" means iterate through....

相关帖文 回复 查看 活动
1
9月 22
2485
4
5月 18
11485
1
1月 16
21422
1
11月 24
40279
0
3月 23
5540