GoodERP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 satır
2.7KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class ResCurrency(models.Model):
  5. _inherit = 'res.currency'
  6. company_id = fields.Many2one(
  7. 'res.company',
  8. string='公司',
  9. change_default=True,
  10. default=lambda self: self.env.company)
  11. @api.model
  12. def rmb_upper(self, value):
  13. """
  14. 人民币大写
  15. 来自:http://topic.csdn.net/u/20091129/20/b778a93d-9f8f-4829-9297-d05b08a23f80.html
  16. 传入浮点类型的值返回 unicode 字符串
  17. :param 传入阿拉伯数字
  18. :return 返回值是对应阿拉伯数字的绝对值的中文数字
  19. """
  20. rmbmap = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]
  21. unit = ["分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿",
  22. "拾", "佰", "仟", "万", "拾", "佰", "仟", "兆"]
  23. # 冲红负数处理
  24. xflag = 0
  25. if value < 0:
  26. xflag = value
  27. value = abs(value)
  28. # 先把value 数字进行格式化保留两位小数,转成字符串然后去除小数点
  29. nums = list(map(int, list(str('%0.2f' % value).replace('.', ''))))
  30. words = []
  31. zflag = 0 # 标记连续0次数,以删除万字,或适时插入零字
  32. start = len(nums) - 3
  33. for i in range(start, -3, -1): # 使i对应实际位数,负数为角分
  34. # 大部分情况对应数字不等于零 或者是刚开始循环
  35. if 0 != nums[start - i] or len(words) == 0:
  36. if zflag:
  37. words.append(rmbmap[0])
  38. zflag = 0
  39. words.append(rmbmap[nums[start - i]]) # 数字对应的中文字符
  40. words.append(unit[i + 2]) # 列表此位置的单位
  41. # 控制‘万/元’ 万和元比较特殊,如2拾万和2拾1万 无论有没有这个1 万字是必须的
  42. elif 0 == i or (0 == i % 4 and zflag < 3):
  43. # 上面那种情况定义了 2拾1万 的显示 这个是特殊对待的 2拾万(一类)的显示
  44. words.append(unit[i + 2])
  45. # 元(控制条件为 0 == i )和万(控制条为(0 == i % 4 and zflag < 3))的情况的处理是一样的
  46. zflag = 0
  47. else:
  48. zflag += 1
  49. if words[-1] != unit[0]: # 结尾非‘分’补整字 最小单位 如果最后一个字符不是最小单位(分)则要加一个整字
  50. words.append("整")
  51. if xflag < 0: # 如果为负数则要在数字前面加上‘负’字
  52. words.insert(0, "负")
  53. return ''.join(words)
上海开阖软件有限公司 沪ICP备12045867号-1