Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

如何在BOM清单明细中增加编码字段?



  • 请教大神:产品/零件中有个barcode字段,录入了产品/零件的编码(一串数字)。创建清单明细时,我想增加一个编码字段,让该字段内容为产品/零件的barcode字段的内容。这样我建立清单明显时,选择相应的零件,自动带出barcode到编码字段。

    或者说,在创建清单明细时,希望自动带出所选零件/产品的一些字段的内容,比如barcode、单价等。
    该怎么弄呢?

    谢谢


  • 管理员

    如果想要再BOM明细中引用产品上的字段,可以设置related字段,比如:

    barcode = fields.Char(related='product_id.barcode')
    price = fields.Float(related='product_id.price')
    

  • 管理员

    如果想要再BOM明细中引用产品上的字段,可以设置related字段,比如:

    barcode = fields.Char(related='product_id.barcode')
    price = fields.Float(related='product_id.price')
    


  • 谢谢 digitalsatori大神回复!
    请问,是将上述语句加入到odoo\addons\mrp\models\mrp_bom.py中,然后再修改xml文件吗?



  • @floatingdudu如何在BOM清单明细中增加编码字段? 中说:

    谢谢 digitalsatori大神回复!
    请问,是将上述语句加入到odoo\addons\mrp\models\mrp_bom.py中,然后再修改xml文件吗?

    我在mrp_bom.py中增加如上代码后,重启服务,出现如下错误:

    Odoo Server Error
    Traceback (most recent call last):
    File "F:\greenodoo12-win\odoo12\odoo\api.py", line 1039, in get
    value = self._data[key][field][record.id]
    KeyError: 46

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "F:\greenodoo12-win\odoo12\odoo\fields.py", line 960, in get
    value = record.env.cache.get(record, self)
    File "F:\greenodoo12-win\odoo12\odoo\api.py", line 1041, in get
    raise CacheMiss(record, field)
    odoo.exceptions.CacheMiss: ('product.template(46,).currency_id', None)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "F:\greenodoo12-win\odoo12\odoo\http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
    File "F:\greenodoo12-win\odoo12\odoo\http.py", line 312, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
    File "F:\greenodoo12-win\odoo12\odoo\tools\pycompat.py", line 87, in reraise
    raise value
    File "F:\greenodoo12-win\odoo12\odoo\http.py", line 696, in dispatch
    result = self._call_function(**self.params)
    File "F:\greenodoo12-win\odoo12\odoo\http.py", line 344, in _call_function
    return checked_call(self.db, *args, **kwargs)
    File "F:\greenodoo12-win\odoo12\odoo\service\model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
    File "F:\greenodoo12-win\odoo12\odoo\http.py", line 337, in checked_call
    result = self.endpoint(*a, **kw)
    File "F:\greenodoo12-win\odoo12\odoo\http.py", line 939, in call
    return self.method(*args, **kw)
    File "F:\greenodoo12-win\odoo12\odoo\http.py", line 517, in response_wrap
    response = f(*args, **kw)
    File "F:\greenodoo12-win\odoo12\addons\web\controllers\main.py", line 904, in search_read
    return self.do_search_read(model, fields, offset, limit, domain, sort)
    File "F:\greenodoo12-win\odoo12\addons\web\controllers\main.py", line 926, in do_search_read
    offset=offset or 0, limit=limit or False, order=sort or False)
    File "F:\greenodoo12-win\odoo12\odoo\models.py", line 4532, in search_read
    result = records.read(fields)
    File "F:\greenodoo12-win\odoo12\odoo\models.py", line 2776, in read
    values[name] = field.convert_to_read(record[name], record, use_name_get)
    File "F:\greenodoo12-win\odoo12\odoo\models.py", line 5055, in getitem
    return self._fields[key].get(self, type(self))
    File "F:\greenodoo12-win\odoo12\odoo\fields.py", line 964, in get
    self.determine_value(record)
    File "F:\greenodoo12-win\odoo12\odoo\fields.py", line 1075, in determine_value
    self.compute_value(recs)
    File "F:\greenodoo12-win\odoo12\odoo\fields.py", line 1031, in compute_value
    self._compute_value(records)
    File "F:\greenodoo12-win\odoo12\odoo\fields.py", line 1022, in _compute_value
    getattr(records, self.compute)()
    File "F:\greenodoo12-win\odoo12\addons\product\models\product_template.py", line 179, in _compute_currency_id
    main_company = self.env['res.company']._get_main_company()
    AttributeError: 'res.company' object has no attribute '_get_main_company'


  • 管理员

    @floatingdudu 你应该创建你自己的addon,在你的addon里继承mrp.bom.line,然后同样的,视图view也是可以继承修改的。

    应该避免直接修改在原有代码上,这样的操作没有任何可维护性。



  • 谢谢 digitalsatori大神回复!
    刚试了下,貌似原有的py文件做任何修改后都会出异常。
    我创建addon试试。第一次接触,建addon目前对我有点难了,本来想直接在原来的上面修改省点事情。



  • 问题已经解决。谢谢digitalsatori


Log in to reply