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.

76 lines
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, tools
  4. from odoo.exceptions import UserError
  5. from odoo.tools import misc
  6. import re
  7. import base64
  8. # 成本计算方法,这里选择后商品上可以不选,从这里取
  9. CORE_COST_METHOD = [('average', '全月一次加权平均法'),
  10. ('std', '定额成本'),
  11. ('fifo', '个别计划法'),
  12. ]
  13. class ResCompany(models.Model):
  14. _inherit = 'res.company'
  15. @api.constrains('email')
  16. def _check_email(self):
  17. ''' 验证 email 合法性 '''
  18. for company in self:
  19. if company.email:
  20. res = re.match(
  21. '^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$',
  22. company.email)
  23. if not res:
  24. raise UserError('请检查邮箱格式是否正确: %s' % company.email)
  25. start_date = fields.Date(
  26. '启用日期',
  27. required=True,
  28. default=lambda self: fields.Date.context_today(self))
  29. cost_method = fields.Selection(
  30. CORE_COST_METHOD,
  31. '存货计价方法',
  32. help='''GoodERP仓库模块使用个别计价规则匹配
  33. 每次出库对应入库成本和数量,但不实时记账。
  34. 财务月结时使用此方法相应调整发出成本''',
  35. default='average', required=True)
  36. draft_invoice = fields.Boolean(
  37. '根据发票确认应收应付',
  38. help='勾选这里,所有新建的结算单不会自动记账')
  39. import_tax_rate = fields.Float(string="默认进项税税率")
  40. output_tax_rate = fields.Float(string="默认销项税税率")
  41. bank_account_id = fields.Many2one('bank.account', string='开户行')
  42. sign = fields.Binary('签章')
  43. def _get_logo(self):
  44. return self._get_logo_impl()
  45. def _get_logo_impl(self):
  46. ''' 默认取 core/static/description 下的 logo.png 作为 logo'''
  47. return base64.b64encode(
  48. open(misc.file_open(
  49. 'core/static/description/logo.png').name, 'rb'
  50. ).read())
  51. def _get_html_table(self, vl):
  52. # vl = {'col':[],'val':[[]]}
  53. res = "<table style='width:100%;text-align:right'><tr>"
  54. for th in vl['col']:
  55. res += "<th>%s</th>" % th
  56. res += "</tr>"
  57. for line in vl['val']:
  58. res += "<tr>"
  59. for v in line:
  60. res += "<td>%s</td>" % v
  61. res += "</tr>"
  62. res += "</table>"
  63. return res
  64. logo = fields.Binary(related='partner_id.image_1920',
  65. default=_get_logo, attachment=True)
上海开阖软件有限公司 沪ICP备12045867号-1