|
- # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-
- from odoo import api, fields, models
-
-
- class Currency(models.Model):
- _inherit = 'res.currency'
-
- def get_rate_silent(self, date, currency_id):
- currency = self.env['res.currency'].search([('id', '=', currency_id)])
- rate = currency.rate
- return rate
-
-
- class RatePeriod(models.Model):
- """记录本月结算汇兑损益时的汇率,用于反结算后,汇兑损益正确时汇率正确"""
- _name = "rate.period"
- _description = '记录本月结算汇兑损益时的汇率'
-
- name = fields.Many2one('res.currency', '币别', required=True)
- account_accumulated_depreciation = fields.Many2one(
- 'finance.account', '累计折旧科目', required=True)
- account_asset = fields.Many2one(
- 'finance.account', '固定资产科目', required=True)
- account_depreciation = fields.Many2one(
- 'finance.account', '折旧费用科目', required=True)
- company_id = fields.Many2one(
- 'res.company',
- string='公司',
- change_default=True,
- default=lambda self: self.env.company)
-
-
- class Partner(models.Model):
- _inherit = 'partner'
-
- c_currency_id = fields.Many2one('res.currency', '客户币种',
- compute='_compute_c_currency_id',
- store=True,
- help='客户默认币种,从客户核算类别科目继承')
- s_currency_id = fields.Many2one('res.currency', '供应商币种',
- compute='_compute_s_currency_id',
- store=True,
- help='供应商默认币种,从供应商核算类别科目继承')
- currency_ids = fields.Many2many('res.currency', 'partner_currency_rel',
- 'partner_id', 'currency_id', '可用币种',
- compute='_compute_currency_ids',
- help='从核算类别科目计算得出的可用币种列表')
-
- @api.depends('c_category_id', 's_category_id', 'c_core_category_ids', 's_core_category_ids')
- def _compute_currency_ids(self):
- for partner in self:
- currency_ids = self.env['res.currency']
- # 从 c_category_id 和 s_category_id 获取币种
- if partner.c_category_id and partner.c_category_id.account_id:
- currency_ids |= partner.c_category_id.account_id.currency_id
- if partner.s_category_id and partner.s_category_id.account_id:
- currency_ids |= partner.s_category_id.account_id.currency_id
- # 从 c_core_category_ids 获取币种
- for category in partner.c_core_category_ids:
- if category.account_id and category.account_id.currency_id:
- currency_ids |= category.account_id.currency_id
- # 从 s_core_category_ids 获取币种
- for category in partner.s_core_category_ids:
- if category.account_id and category.account_id.currency_id:
- currency_ids |= category.account_id.currency_id
- partner.currency_ids = currency_ids
-
- @api.depends('c_category_id')
- def _compute_c_currency_id(self):
- for partner in self:
- if partner.c_category_id and partner.c_category_id.account_id:
- partner.c_currency_id = partner.c_category_id.account_id.currency_id
- if not partner.c_currency_id:
- partner.c_currency_id = partner.company_id.currency_id
-
- @api.depends('s_category_id')
- def _compute_s_currency_id(self):
- for partner in self:
- if partner.s_category_id and partner.s_category_id.account_id:
- partner.s_currency_id = partner.s_category_id.account_id.currency_id
- if not partner.s_currency_id:
- partner.s_currency_id = partner.company_id.currency_id
|