Odoo 中文社区

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

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

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

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

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

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

    請教在Function的return值中如何設定之後顯示view的過濾顯示條件

    Odoo 新手求助
    3
    5
    2923
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • K
      kk071700 最后由 编辑

      小弟寫了個程式(輸入 gp_name以及其他參數然後以此條件寫入DB)
      希望在_create_product執行完後能跳到一頁只顯示剛剛生成的資料(以gp_name為搜尋條件)
      試著用以下方式,但似乎無作用,請問大大是否有建議or解決方法 謝謝
                return {
      [glow=red,2,300][b]                'domain': [('x_group','=',gp_name)],
                      #'domain': [('x_group','in',gp_name)],[/b][/glow]
                      'name': _('create_product_by_group'),
                      'view_type': 'form',
                      'view_mode': 'tree,form',
                      'res_model': 'product.product',
                      'type': 'ir.actions.act_window',
              }


      原始碼如下:

      import wizard
      import pooler
      from datetime import *
      from tools.translate import _ # Used for translations

      import time


      view_form="""<?xml version="1.0"?>
      <form string="Create product by group">
          <group colspan="4" col="4">
          <separator string="Group data" colspan="4"/>
          <field name="gp_name" string="Group:"/>
          </group>
          <group colspan="4" col="4">
      <separator string="Power data" colspan="4"/>
      <field name="sph_from" string="Sphere Power from:"/>
      <field name="sph_to" string="to:"/>
      <field name="cyl_from" string="Cylinder Power from:"/>
      <field name="cyl_to" string="to:"/>
          </group>
      </form>"""

      fields_form = {
      #'gp_name': {'string': ' gp_name ', 'type': 'float', 'default': lambda *a: 0.0 },
      'gp_name': {'string': ' gp_name ', 'type': 'char', 'default': lambda *a: '' },

      'sph_from': {'string': ' Sph_from ', 'type': 'float', 'default': lambda *a: 0.0 },
      'sph_to': {'string': ' Sph_to ', 'type': 'float', 'default': lambda *a: 0.0 },
      'cyl_from': {'string': ' Cyl_from ', 'type': 'float', 'default': lambda a: 0.0 },
      'cyl_to': {'string': ' Cyl_to ', 'type': 'float', 'default': lambda a: 0.0 },
      }

      class wizard_create_product(wizard.interface):

      def _create_product(self, cr, uid, data, context):
                gp_name=(data['form']['gp_name'])
                sph_from=float(data['form']['sph_from'])
                sph_to=float(data['form']['sph_to'])
                cyl_from=float(data['form']['cyl_from'])
                cyl_to=float(data['form']['cyl_to'])

                if gp_name!='':
                      default_code="TEST_CODE"
                      name_template="test_prosuct"
                      list_price="0"
                      standard_price="0"
                      DT="2011-11-11 10:00:00.000"


                              sph_diff=abs(sph_from)+abs(sph_to)
                              count_sph_diff=int(sph_diff/0.25)
                              cyl_diff=abs(cyl_from)+abs(cyl_to)
                              count_cyl_diff=int(cyl_diff/0.25)

                              sph_mark=''
                              cyl_mark=''
                              diff=0.25
                              now_sph=0
                              now_cyl=0

                              for x in range(count_sph_diff):
                                  now_sph=sph_from-(diff
      x)
                                  if now_sph>0:
                                    sph_mark='+'

                                  for y in range(count_cyl_diff):
                                      now_cyl=cyl_from-(diff
      y)
                                      if now_cyl>0:
                                          cyl_mark='+'

                                      DT=str(datetime.now())

                                      default_code=gp_name+sph_mark+str(now_sph)+cyl_mark+str(now_cyl)
                                      name_template=str(gp_name)+'_SPY:'+str(now_sph)+'CYL:'+str(now_cyl)
                                      cr.execute("""select id from product_template where name='"""+str(name_template)+"""'""")
                                      resA = cr.fetchall()
                                      if not resA:
                                          cr.execute("""INSERT INTO product_template(create_uid, create_date, write_date, write_uid, supply_method, list_price, standard_price, mes_type, uom_id,  uos_coeff, purchase_ok,company_id, name, uom_po_id, type,  procure_method, cost_method, rental, sale_ok, sale_delay, produce_delay, categ_id) VALUES('1','"""+DT+"""','"""+DT+"""','1','buy',"""+list_price+""","""+standard_price+""",'fixed','1',1.0,TRUE,'1','"""+name_template+"""','1','product','make_to_stock','standard',FALSE,TRUE,'7','1','22')""")
                                          T_ID="0"
                                          cr.execute("""select id from product_template where name='"""+name_template+"""'""")
                                          res = cr.fetchall()
                                          for row in res:
                                              T_ID=str(row[0])
                                              cr.execute("""INSERT INTO product_product(create_uid, create_date, write_date, write_uid, price_extra,default_code, name_template, active, product_tmpl_id,price_margin, track_production, valuation, track_outgoing, track_incoming) VALUES ('1','"""+DT+"""','"""+DT+"""','1',0,'"""+default_code+"""','"""+name_template+"""',TRUE,'"""+str(T_ID)+"""',1.0,FALSE,'manual_periodic',FALSE,FALSE)""")

                else:
                              warning = {
                              'title': 'No Group name!',
                              'message': 'Please input group name'
                              }
                #return []

                return {
      [glow=red,2,300][b]                'domain': [('x_group','=',gp_name)],
                      #'domain': [('x_group','in',gp_name)],[/b][/glow]
                      'name': _('create_product_by_group'),
                      'view_type': 'form',
                      'view_mode': 'tree,form',
                      'res_model': 'product.product',
                      'type': 'ir.actions.act_window',
              }

      states = {
      'init': {
      'actions': [],
      'result': {
      'type': 'form',
      'arch': view_form,
      'fields': fields_form,
      'state': [
      ('end','Cancel','gtk-cancel'),
      ('finish','Ok','gtk-ok',True),
      ]
      }
      },
      'finish': {
      'actions': [],
      'result': {
      'type': 'action',
      'action': _create_product,
      'state': 'end',
      }
      },
      }
      wizard_create_product('cr_product.create_product_wizard')

      1 条回复 最后回复 回复 引用 0
      • digitalsatori
        digitalsatori 管理员 最后由 编辑

        只有一点小问题,domain 是根据对象字段进行过滤的,而x_group并不是product_product表的字段,至少我没有看到你为该字段插入值

        把domain改成如下试试,

        &#039;domain&#039; : [(&#039;name&#039;, &#039;like&#039;, gp_name)]<br />
        

        【上海先安科技】(tony AT openerp.cn)

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

          [('x_group.name', 'ilike', gp_name)]

          1 条回复 最后回复 回复 引用 0
          • K
            kk071700 最后由 编辑

            感恩各位先進的指導 已經解決了 x_group是我自訂義加在product_product表的字段
            用'domain': [('x_group','=',gp_name)] OK

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