GoodERP
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

85 Zeilen
4.0KB

  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 Currency(models.Model):
  5. _inherit = 'res.currency'
  6. def get_rate_silent(self, date, currency_id):
  7. currency = self.env['res.currency'].search([('id', '=', currency_id)])
  8. rate = currency.rate
  9. return rate
  10. class RatePeriod(models.Model):
  11. """记录本月结算汇兑损益时的汇率,用于反结算后,汇兑损益正确时汇率正确"""
  12. _name = "rate.period"
  13. _description = '记录本月结算汇兑损益时的汇率'
  14. name = fields.Many2one('res.currency', '币别', required=True)
  15. account_accumulated_depreciation = fields.Many2one(
  16. 'finance.account', '累计折旧科目', required=True)
  17. account_asset = fields.Many2one(
  18. 'finance.account', '固定资产科目', required=True)
  19. account_depreciation = fields.Many2one(
  20. 'finance.account', '折旧费用科目', required=True)
  21. company_id = fields.Many2one(
  22. 'res.company',
  23. string='公司',
  24. change_default=True,
  25. default=lambda self: self.env.company)
  26. class Partner(models.Model):
  27. _inherit = 'partner'
  28. c_currency_id = fields.Many2one('res.currency', '客户币种',
  29. compute='_compute_c_currency_id',
  30. store=True,
  31. help='客户默认币种,从客户核算类别科目继承')
  32. s_currency_id = fields.Many2one('res.currency', '供应商币种',
  33. compute='_compute_s_currency_id',
  34. store=True,
  35. help='供应商默认币种,从供应商核算类别科目继承')
  36. currency_ids = fields.Many2many('res.currency', 'partner_currency_rel',
  37. 'partner_id', 'currency_id', '可用币种',
  38. compute='_compute_currency_ids',
  39. help='从核算类别科目计算得出的可用币种列表')
  40. @api.depends('c_category_id', 's_category_id', 'c_core_category_ids', 's_core_category_ids')
  41. def _compute_currency_ids(self):
  42. for partner in self:
  43. currency_ids = self.env['res.currency']
  44. # 从 c_category_id 和 s_category_id 获取币种
  45. if partner.c_category_id and partner.c_category_id.account_id:
  46. currency_ids |= partner.c_category_id.account_id.currency_id
  47. if partner.s_category_id and partner.s_category_id.account_id:
  48. currency_ids |= partner.s_category_id.account_id.currency_id
  49. # 从 c_core_category_ids 获取币种
  50. for category in partner.c_core_category_ids:
  51. if category.account_id and category.account_id.currency_id:
  52. currency_ids |= category.account_id.currency_id
  53. # 从 s_core_category_ids 获取币种
  54. for category in partner.s_core_category_ids:
  55. if category.account_id and category.account_id.currency_id:
  56. currency_ids |= category.account_id.currency_id
  57. partner.currency_ids = currency_ids
  58. @api.depends('c_category_id')
  59. def _compute_c_currency_id(self):
  60. for partner in self:
  61. if partner.c_category_id and partner.c_category_id.account_id:
  62. partner.c_currency_id = partner.c_category_id.account_id.currency_id
  63. if not partner.c_currency_id:
  64. partner.c_currency_id = partner.company_id.currency_id
  65. @api.depends('s_category_id')
  66. def _compute_s_currency_id(self):
  67. for partner in self:
  68. if partner.s_category_id and partner.s_category_id.account_id:
  69. partner.s_currency_id = partner.s_category_id.account_id.currency_id
  70. if not partner.s_currency_id:
  71. partner.s_currency_id = partner.company_id.currency_id
上海开阖软件有限公司 沪ICP备12045867号-1