Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

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

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

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

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

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

    Key error! 扩展product模块错误

    Odoo 开发与实施交流
    1
    3
    7673
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • W
      Wingedox 最后由 编辑

      个人觉得Tiny ERP 在小企业应用中非常适合。灵活,模块化,而且应该开发难度不高。现有的模块已经具备基本功能,有些特殊的需求能很快开发出扩展模块,自带workfolw 引擎,能满足业务流程定制,自定义报表。。。。

      现在正在研究模块开发,现在遇到一些问题,希望能得到高人指点。

      我写的测试模块是在原有product 模块基础上扩展部分功能,原有的product 模块没有产品属性,只有产品分类

      实体类文件product_new.py:[code]from osv import fields, osv

      class product_property(osv.osv):
      def name_get(self, cr, uid, ids, context={}):
      if not len(ids):
      return []
      reads = self.read(cr, uid, ids, ['name','parent_id'], context)
      res = []
      for record in reads:
      name = record['name']
      if record['parent_id']:
      name = record['parent_id'][1]+' / '+name
      res.append((record['id'], name))
      return res

          def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, unknow_dict):
                  res = self.name_get(cr, uid, ids)
                  return dict(res)
          def _check_recursion(self, cr, uid, ids):
                  level = 100
                  while len(ids):
                          cr.execute('select distinct parent_id from product_property where id in ('+','.join(map(str,ids))+')')
                          ids = filter(None, map(lambda x:x[0], cr.fetchall()))
                          if not level:
                                  return False
                          level -= 1
                  return True
      
          _description='Prodcut Property'
          _name = 'product.property'
          _columns = {
                  'name': fields.char('Property Name', required=True, size=64),
                  'parent_id': fields.many2one('product.property', 'Parent Property', select=True),
                  'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Name'),
                  'child_ids': fields.one2many('product.property', 'parent_id', 'Childs Category'),
                  'active' : fields.boolean('Active'),
          }
          _constraints = [
                  (_check_recursion, 'Error ! You can not create recursive properties.', ['parent_id'])
          ]
          _defaults = {
                  'active' : lambda *a: 1,
          }
          _order = 'parent_id,name'
      

      product_property()

      class product_product(osv.osv):
      _name = "product.product"
      _inherit = "product.product"
      _columns = {
      'property_ids': fields.many2many("product.property", "product_property_rel", "product_id", "property_id", "roperties"),
      }
      product_product()[/code]
      视图定义product_new_view.xml

      发不上来,见附件

      报错信息:[code]Traceback (most recent call last):
      File "netsvc.pyo", line 200, in _dispatch
      File "serviceweb_services.pyo", line 366, in execute
      File "osvosv.pyo", line 111, in execute
      File "osvosv.pyo", line 92, in execute_cr
      File "osvorm.pyo", line 1544, in fields_view_get
      File "osvorm.pyo", line 1409, in __view_look_dom_arch
      KeyError: u'property_ids'[/code]找了很久不知错误在哪里,请帮忙指点。

      [[i] 本帖最后由 Wingedox 于 2008-4-3 20:30 编辑 [/i]]

      1 条回复 最后回复 回复 引用 0
      • W
        Wingedox 最后由 编辑

        手工写代码的确容易错误,把product.template 写成了product.product ,因此在product.template 中根本就没有property_ids 属性,所以报错。现在基本通过,没有什么使用价值纯粹学习用,发上来供参考。

        如果熟练后写模块应该是比较快的,和其他的ERP 相比Tiny ERP 的确相当灵活

        [[i] 本帖最后由 Wingedox 于 2008-4-3 21:08 编辑 [/i]]

        1 条回复 最后回复 回复 引用 0
        • First post
          Last post