Odoo 中文社区

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

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

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

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

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

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

    Openerp onchange 金额自动转为大写

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

      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
      • mrshelly
        mrshelly 最后由 编辑

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

        分享便是极好的....

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

          这个 金额转大写  完美不 ?

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

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

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

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

              有待解决!

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

                [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
                  openerp_feng 最后由 编辑

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

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

                    因为出现这样的错误提示:
                        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
                    • ieitzyb
                      ieitzyb 最后由 编辑

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

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

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

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

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

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

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