跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. Openerp onchange 金额自动转为大写

Openerp onchange 金额自动转为大写

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
12 帖子 8 发布者 7.4k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • R 离线
    R 离线
    rufeng1199
    写于 最后由 编辑
    #1

    1.对象里定义

    <br />contract_amount&#039;: fields.float(&#039;合同金额&#039;, digits_compute=dp.get_precision(&#039;contract_amount&#039;),required=True),&#039;contract_amount_big&#039;: fields.char(&#039;合同金额大写&#039;, required=True),<br /><br /><br />
    






    2. xml里  onchange 



    <field name="contract_amount" on_change="onchange_contractamount(contract_amount)"/>




    3. 方法实现


    <br />def onchange_contractamount(self, cr, uid, ids, contract_amount):&nbsp; &nbsp; &nbsp; &nbsp; if contract_amount &gt; 0 :&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; big = self.numtoCny(contract_amount)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return {&#039;value&#039;:{&#039;contract_amount_big&#039;: big}}&nbsp; &nbsp; &nbsp; &nbsp; else :&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return {}<br />
    




    4.需要注意的是 因为onchange里再次调用了其他方法,导致总是报参数个数不统一的异常,莫名其妙


    经过 [font=verdana]@重庆-mrshelly @南京-海飞 @上海-gavin @南京-ccdos [/font]

    [font=verdana]尤其是 总监大人解释后才明白[/font]


    重庆-mrshelly(49812643)  15:30:23
    因为你使用了 self.numtoCny 所以,  有一个默认的 self 参数传过去了.


    所以  只需要将  中文金额大写 的函数传参时注意一下就好了

    <br />&nbsp; &nbsp;  #人民币金额转大写程序Python版本<br />&nbsp; &nbsp; #Copyright: zinges at foxmail.com<br />&nbsp; &nbsp; #blog: http://zingers.iteye.com br />&nbsp; &nbsp; #感谢zinges提供了Python的版本<br /><br /><br />&nbsp; &nbsp; def numtoCny(self,contract_amount):<br /><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; capUnit = &#91;&#039;万&#039;,&#039;亿&#039;,&#039;万&#039;,&#039;圆&#039;,&#039;&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; capDigit = { 2:&#91;&#039;角&#039;,&#039;分&#039;,&#039;&#039;], 4:&#91;&#039;仟&#039;,&#039;佰&#039;,&#039;拾&#039;,&#039;&#039;]}<br />&nbsp; &nbsp; &nbsp; &nbsp; capNum=&#91;&#039;零&#039;,&#039;壹&#039;,&#039;贰&#039;,&#039;叁&#039;,&#039;肆&#039;,&#039;伍&#039;,&#039;陆&#039;,&#039;柒&#039;,&#039;捌&#039;,&#039;玖&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; snum = str(&#039;%019.02f&#039;) % contract_amount<br />&nbsp; &nbsp; &nbsp; &nbsp; if snum.index(&#039;.&#039;)&gt;16:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &#039;&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; ret,nodeNum,subret,subChr=&#039;&#039;,&#039;&#039;,&#039;&#039;,&#039;&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; CurChr=&#91;&#039;&#039;,&#039;&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; for i in range(5):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; j=int(i*4+math.floor(i/4))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subret=&#039;&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nodeNum=snum[j:j+4]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lens=len(nodeNum)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for k in range(lens):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if int(nodeNum[k:])==0:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CurChr[k%2] = capNum[int(nodeNum[k:k+1])]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if nodeNum[k:k+1] != &#039;0&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CurChr[k%2] += capDigit[lens][k]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if&nbsp; not ((CurChr[0]==CurChr[1]) and (CurChr[0]==capNum[0])):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not((CurChr[k%2] == capNum[0]) and (subret==&#039;&#039;) and (ret==&#039;&#039;)):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subret += CurChr[k%2]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subChr = [subret,subret+capUnit][subret!=&#039;&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not ((subChr == capNum[0]) and (ret==&#039;&#039;)):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret += subChr<br /><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; return [ret,capNum[0]+capUnit[3]][ret==&#039;&#039;]<br /> 
    



    1 条回复 最后回复
    0
    • mrshellyM 离线
      mrshellyM 离线
      mrshelly
      写于 最后由 编辑
      #2

      不明觉厉.....................

      分享便是极好的....

      1 条回复 最后回复
      0
      • C 离线
        C 离线
        ccdos
        写于 最后由 编辑
        #3

        这个 金额转大写  完美不 ?

        1 条回复 最后回复
        0
        • R 离线
          R 离线
          rufeng1199
          写于 最后由 编辑
          #4

          我简单测试了下,一直测到9位数,表现良好

          1 条回复 最后回复
          0
          • O 离线
            O 离线
            openerp_feng
            写于 最后由 编辑
            #5

            测试程序代码正常,在数据维护时出现错误:
                subChr = [subret,subret+capUnit][subret!='']
            TypeError: cannot concatenate 'str' and 'list' objects

            有待解决!

            1 条回复 最后回复
            0
            • R 离线
              R 离线
              rufeng1199
              写于 最后由 编辑
              #6

              [quote author=openerp_feng link=topic=14575.msg27073#msg27073 date=1387183648]
              测试程序代码正常,在数据维护时出现错误:
                  subChr = [subret,subret+capUnit][subret!='']
              TypeError: cannot concatenate 'str' and 'list' objects

              有待解决!
              [/quote]


              测试数据呢,请提供一下

              1 条回复 最后回复
              0
              • O 离线
                O 离线
                openerp_feng
                写于 最后由 编辑
                #7

                123
                123.785
                随便录几个数字都是同样的错误

                1 条回复 最后回复
                0
                • L 离线
                  L 离线
                  laoliu
                  写于 最后由 编辑
                  #8

                  因为出现这样的错误提示:
                      subChr = [subret,subret+capUnit][subret!='']
                  TypeError: cannot concatenate 'str' and 'list' objects

                  所以,需要这样修改:
                  subChr = [subret,subret+[color=red]"".join([/color]capUnit[color=red])[/color]][subret!='']

                  1 条回复 最后回复
                  0
                  • ieitzybI 离线
                    ieitzybI 离线
                    ieitzyb
                    写于 最后由 编辑
                    #9

                    有价值的东东,我也极想要

                    http://www.OuduPLM.com/ 苏州欧度软件,专注服装行业(鳴謝:37signals,Trello,ProcessON,重庆慧积,上海开阖)

                    1 条回复 最后回复
                    0
                    • N 离线
                      N 离线
                      nmglyy
                      写于 最后由 编辑
                      #10

                      可以参考下如文件,进行转换大写金额。。

                      1 条回复 最后回复
                      0
                      • W 离线
                        W 离线
                        wallerzhang
                        写于 最后由 编辑
                        #11

                        很有价值,谢谢分享,有待测试。

                        1 条回复 最后回复
                        0

                        • 登录

                        • 没有帐号? 注册

                        • 登录或注册以进行搜索。
                        • 第一个帖子
                          最后一个帖子
                        0
                        • 版块
                        • 标签
                        • 热门
                        • 用户
                        • 群组