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.

644 line
28KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.exceptions import UserError, ValidationError
  4. from odoo import fields, models, api
  5. from odoo.tools import float_compare, float_is_zero
  6. class MoneyOrder(models.Model):
  7. _name = 'money.order'
  8. _description = "收付款单"
  9. _inherit = ['mail.thread', 'mail.activity.mixin']
  10. _order = 'id desc'
  11. TYPE_SELECTION = [
  12. ('pay', '付款'),
  13. ('get', '收款'),
  14. ]
  15. @api.model_create_multi
  16. def create(self, vals_list):
  17. # 创建单据时,根据订单类型的不同,生成不同的单据编号
  18. for values in vals_list:
  19. if self.env.context.get('type') == 'pay':
  20. values.update(
  21. {'name': self.env['ir.sequence'].next_by_code('pay.order')})
  22. else:
  23. values.update(
  24. {'name': self.env['ir.sequence'].next_by_code('get.order')})
  25. # 创建时查找该业务伙伴是否存在 未审核 状态下的收付款单
  26. orders = self.env['money.order'].search([
  27. ('partner_id', '=', values.get('partner_id')),
  28. ('state', '=', 'draft'),
  29. ('source_ids', '!=', False),
  30. ('id', '!=', self.id)])
  31. if values.get('source_ids') and orders:
  32. raise UserError('该业务伙伴存在未确认的收/付款单,请先确认')
  33. return super(MoneyOrder, self).create(vals_list)
  34. def write(self, values):
  35. # 修改时查找该业务伙伴是否存在 未审核 状态下的收付款单
  36. if values.get('partner_id'):
  37. orders = self.env['money.order'].search([
  38. ('partner_id', '=', values.get('partner_id')),
  39. ('state', '=', 'draft'),
  40. ('id', '!=', self.id)])
  41. if orders:
  42. raise UserError('业务伙伴(%s)存在未审核的收/付款单,请先审核' %
  43. orders.partner_id.name)
  44. return super(MoneyOrder, self).write(values)
  45. @api.depends('discount_amount',
  46. 'line_ids.amount',
  47. 'source_ids.this_reconcile')
  48. def _compute_advance_payment(self):
  49. """
  50. 计算字段advance_payment(本次预收)
  51. """
  52. for mo in self:
  53. amount, this_reconcile = 0.0, 0.0
  54. for line in mo.line_ids:
  55. amount += line.amount
  56. for line in mo.source_ids:
  57. this_reconcile += line.this_reconcile
  58. if mo.type == 'get':
  59. mo.advance_payment = \
  60. amount - this_reconcile + mo.discount_amount
  61. else:
  62. mo.advance_payment = \
  63. amount - this_reconcile - mo.discount_amount
  64. mo.amount = amount
  65. @api.depends('partner_id', 'type', 'source_ids.currency_id')
  66. def _compute_currency_id(self):
  67. """
  68. 取出币别
  69. :return:
  70. """
  71. for mo in self:
  72. if mo.company_id.is_multi_currency and mo.source_ids:
  73. # 多币种开启时:收付款单币种跟随待核销行的币种
  74. currencies = mo.source_ids.mapped('currency_id')
  75. if len(currencies) == 1:
  76. mo.currency_id = currencies.id
  77. else:
  78. # 待核销行币种不一致,收付款单币种为空
  79. mo.currency_id = False
  80. else:
  81. # 多币种未开启时:从业务伙伴类别科目取币种
  82. partner_currency_id = (mo.type == 'get') \
  83. and mo.partner_id.c_category_id.account_id.currency_id.id \
  84. or mo.partner_id.s_category_id.account_id.currency_id.id
  85. mo.currency_id = \
  86. partner_currency_id or mo.env.user.company_id.currency_id.id
  87. state = fields.Selection([
  88. ('draft', '草稿'),
  89. ('done', '已完成'),
  90. ('cancel', '已作废'),
  91. ], string='状态', readonly=True, default='draft', copy=False, index=True,
  92. help='收/付款单状态标识,新建时状态为草稿;确认后状态为已完成')
  93. partner_id = fields.Many2one('partner', string='往来单位', required=True,
  94. ondelete='restrict',
  95. help='该单据对应的业务伙伴,单据确认时会影响他的应收应付余额')
  96. date = fields.Date(string='单据日期',
  97. default=lambda self: fields.Date.context_today(self),
  98. help='单据创建日期')
  99. name = fields.Char(string='单据编号', copy=False, readonly=True,
  100. help='单据编号,创建时会根据类型自动生成')
  101. note = fields.Text(string='备注', help='可以为该单据添加一些需要的标识信息')
  102. currency_id = fields.Many2one(
  103. 'res.currency',
  104. '币别',
  105. compute='_compute_currency_id',
  106. store=True,
  107. readonly=True,
  108. tracking=True,
  109. help='业务伙伴的类别科目上对应的外币币别')
  110. is_multi_currency = fields.Boolean('多币种', related='company_id.is_multi_currency')
  111. discount_amount = fields.Float(string='我方承担费用',
  112. readonly=False,
  113. digits='Amount',
  114. help='收/付款时发生的银行手续费或给业务伙伴的现金折扣。')
  115. discount_account_id = fields.Many2one(
  116. 'finance.account', '费用科目',
  117. domain="[('account_type','=','normal')]",
  118. readonly=False,
  119. help='收/付款单确认生成凭证时,手续费或折扣对应的科目')
  120. line_ids = fields.One2many('money.order.line', 'money_id',
  121. string='收/付款单行',
  122. help='收/付款单明细行')
  123. source_ids = fields.One2many('source.order.line', 'money_id',
  124. string='待核销行',
  125. help='收/付款单待核销行')
  126. type = fields.Selection(TYPE_SELECTION, string='类型',
  127. default=lambda self: self.env.context.get('type'),
  128. help='类型:收款单 或者 付款单')
  129. amount = fields.Float(string='总金额', compute='_compute_advance_payment',
  130. digits='Amount',
  131. store=True, readonly=True,
  132. help='收/付款单行金额总和')
  133. advance_payment = fields.Float(
  134. string='本次预付',
  135. compute='_compute_advance_payment',
  136. digits='Amount',
  137. store=True, readonly=True,
  138. help='根据收/付款单行金额总和,原始单据行金额总和及折扣额计算得来的预收/预付款,值>=0')
  139. to_reconcile = fields.Float(string='未核销金额',
  140. digits='Amount',
  141. help='未核销的预收/预付款金额')
  142. reconciled = fields.Float(string='已核销金额',
  143. digits='Amount',
  144. help='已核销的预收/预付款金额')
  145. origin_name = fields.Char('原始单据编号',
  146. help='原始单据编号')
  147. bank_name = fields.Char('开户行',
  148. help='开户行取自业务伙伴,可修改')
  149. bank_num = fields.Char('银行账号',
  150. help='银行账号取自业务伙伴,可修改')
  151. approve_uid = fields.Many2one('res.users', '确认人',
  152. copy=False, ondelete='restrict')
  153. approve_date = fields.Datetime('确认日期', copy=False)
  154. company_id = fields.Many2one(
  155. 'res.company',
  156. string='公司',
  157. change_default=True,
  158. default=lambda self: self.env.company)
  159. voucher_id = fields.Many2one('voucher',
  160. '对应凭证',
  161. readonly=True,
  162. ondelete='restrict',
  163. copy=False,
  164. help='收/付款单确认时生成的对应凭证')
  165. def create_reconcile(self):
  166. self.ensure_one()
  167. if self.env['money.invoice'].search([
  168. ('partner_id', '=', self.partner_id.id),
  169. ('state', '=', 'done'),
  170. ('to_reconcile', '!=', 0),
  171. ], limit=1):
  172. if self.type == 'get':
  173. business_type = 'adv_pay_to_get'
  174. else:
  175. business_type = 'adv_get_to_pay'
  176. recon = self.env['reconcile.order'].create({
  177. 'partner_id': self.partner_id.id,
  178. 'business_type': business_type})
  179. recon.onchange_partner_id()
  180. action = {
  181. 'name': '核销单',
  182. 'type': 'ir.actions.act_window',
  183. 'view_mode': 'form',
  184. 'res_model': 'reconcile.order',
  185. 'res_id': recon.id,
  186. }
  187. return action
  188. else:
  189. raise UserError('没有未核销结算单')
  190. def write_off_reset(self):
  191. """
  192. 单据审核前重置计算单行上的本次核销金额
  193. :return:
  194. """
  195. self.ensure_one()
  196. if self.state != 'draft':
  197. raise ValueError('已确认的单据不能执行这个操作')
  198. for source in self.source_ids:
  199. source.this_reconcile = 0
  200. return True
  201. @api.onchange('date')
  202. def onchange_date(self):
  203. """
  204. 当修改日期时,则根据context中的money的type对客户添加过滤,过滤出是供应商还是客户。
  205. (因为date有默认值所以这个过滤是默认触发的) 其实和date是否变化没有关系,页面加载就触发下面的逻辑
  206. :return:
  207. """
  208. if self.env.context.get('type') == 'get':
  209. return {'domain': {'partner_id': [('c_category_id', '!=', False)]}}
  210. else:
  211. return {'domain': {'partner_id': [('s_category_id', '!=', False)]}}
  212. def _get_source_line(self, invoice):
  213. """
  214. 根据传入的invoice的对象取出对应的值 构造出 source_line的一个dict 包含source line的主要参数
  215. :param invoice: money_invoice对象
  216. :return: dict
  217. """
  218. return {
  219. 'name': invoice.id,
  220. 'category_id': invoice.category_id.id,
  221. 'amount': invoice.amount,
  222. 'date': invoice.date,
  223. 'reconciled': invoice.reconciled,
  224. 'to_reconcile': invoice.to_reconcile,
  225. 'this_reconcile': invoice.to_reconcile,
  226. 'date_due': invoice.date_due,
  227. }
  228. def _get_invoice_search_list(self):
  229. """
  230. 构造出 invoice 搜索的domain
  231. :return:
  232. """
  233. invoice_search_list = [('partner_id', '=', self.partner_id.id),
  234. ('to_reconcile', '!=', 0),
  235. ('state', '=', 'done')]
  236. if self.env.context.get('type') == 'get':
  237. invoice_search_list.append(('category_id.type', '=', 'income'))
  238. else: # type = 'pay':
  239. invoice_search_list.append(('category_id.type', '=', 'expense'))
  240. return invoice_search_list
  241. @api.onchange('partner_id')
  242. def onchange_partner_id(self):
  243. """
  244. 对partner修改的监控当 partner 修改时,
  245. 就对 页面相对应的字段进行修改(bank_name,bank_num,source_ids)
  246. """
  247. if not self.partner_id:
  248. return {}
  249. self.source_ids = False
  250. source_lines = []
  251. self.bank_name = self.partner_id.bank_name
  252. self.bank_num = self.partner_id.bank_num
  253. for invoice in self.env['money.invoice'].search(
  254. self._get_invoice_search_list()):
  255. source_lines.append((0, 0, self._get_source_line(invoice)))
  256. self.source_ids = source_lines
  257. def money_order_done(self):
  258. '''对收付款单的审核按钮'''
  259. for order in self:
  260. if order.state == 'done':
  261. raise UserError('请不要重复确认')
  262. if order.type == 'pay' and \
  263. not order.partner_id.s_category_id.account_id:
  264. raise UserError('请输入供应商类别(%s)上的科目' %
  265. order.partner_id.s_category_id.name)
  266. if order.type == 'get' and \
  267. not order.partner_id.c_category_id.account_id:
  268. raise UserError('请输入客户类别(%s)上的科目' %
  269. order.partner_id.c_category_id.name)
  270. if order.advance_payment < 0 and order.source_ids:
  271. raise UserError('本次核销金额不能大于付款金额。\n差额: %s' %
  272. order.advance_payment)
  273. for line in order.line_ids:
  274. if order.type == 'pay': # 付款账号余额减少, 退款账号余额增加
  275. decimal_amount = self.env.ref('core.decimal_amount')
  276. balance = (
  277. line.currency_id and line.currency_id
  278. != self.env.user.company_id.currency_id
  279. and line.bank_id.currency_amount
  280. or line.bank_id.balance)
  281. if float_compare(
  282. balance, line.amount,
  283. precision_digits=decimal_amount.digits) == -1:
  284. raise UserError('账户余额不足。\n账户余额:%s 付款行金额:%s' %
  285. (balance, line.amount))
  286. if line.currency_id and line.currency_id != self.env.user.company_id.currency_id: # 外币
  287. line.bank_id.currency_amount -= line.amount
  288. line.bank_id.balance -= line.amount
  289. else: # 收款账号余额增加, 退款账号余额减少
  290. if line.currency_id and line.currency_id != self.env.user.company_id.currency_id: # 外币
  291. line.bank_id.currency_amount += line.amount
  292. line.bank_id.balance += line.amount
  293. # 更新结算单的未核销金额、已核销金额
  294. for source in order.source_ids:
  295. decimal_amount = self.env.ref('core.decimal_amount')
  296. if float_compare(
  297. source.this_reconcile,
  298. abs(source.to_reconcile),
  299. precision_digits=decimal_amount.digits) == 1:
  300. raise UserError(
  301. '本次核销金额不能大于未核销金额。\n 核销金额:%s 未核销金额:%s'
  302. % (abs(source.to_reconcile), source.this_reconcile))
  303. source.name.to_reconcile -= source.this_reconcile
  304. source.name.reconciled += source.this_reconcile
  305. if source.this_reconcile == 0: # 如果核销行的本次付款金额为0,删除
  306. source.unlink()
  307. # 生成凭证并审核
  308. if order.type == 'get':
  309. voucher = order.create_money_order_get_voucher(
  310. order.line_ids, order.source_ids, order.partner_id,
  311. order.name, order.note or '')
  312. else:
  313. voucher = order.create_money_order_pay_voucher(
  314. order.line_ids, order.source_ids, order.partner_id,
  315. order.name, order.note or '')
  316. voucher.voucher_done()
  317. return order.write({
  318. 'to_reconcile': order.advance_payment,
  319. 'reconciled': order.amount - order.advance_payment,
  320. 'voucher_id': voucher.id,
  321. 'approve_uid': self.env.uid,
  322. 'approve_date': fields.Datetime.now(self),
  323. 'state': 'done',
  324. })
  325. def money_order_draft(self):
  326. """
  327. 收付款单反审核方法
  328. """
  329. for order in self:
  330. if order.state == 'draft':
  331. raise UserError('请不要重复撤销 %s' % self._description)
  332. # 收/付款单 存在已审核金额不为0的核销单
  333. total_current_reconciled = order.amount - order.advance_payment
  334. decimal_amount = self.env.ref('core.decimal_amount')
  335. if float_compare(order.reconciled,
  336. total_current_reconciled,
  337. precision_digits=decimal_amount.digits) != 0:
  338. raise UserError('单据已核销金额不为0,不能反审核!请检查核销单!')
  339. for line in order.line_ids:
  340. if order.type == 'pay': # 反审核:付款账号余额增加
  341. if line.currency_id and line.currency_id != self.env.user.company_id.currency_id: # 外币
  342. line.bank_id.currency_amount += line.amount
  343. line.bank_id.balance += line.amount
  344. else: # 反审核:收款账号余额减少
  345. balance = (
  346. line.currency_id and line.currency_id
  347. != self.env.user.company_id.currency_id
  348. and line.bank_id.currency_amount
  349. or line.bank_id.balance)
  350. decimal_amount = self.env.ref('core.decimal_amount')
  351. if float_compare(
  352. balance,
  353. line.amount,
  354. precision_digits=decimal_amount.digits) == -1:
  355. raise UserError('账户余额不足。\n 账户余额:%s 收款行金额:%s' %
  356. (balance, line.amount))
  357. if line.currency_id and line.currency_id != self.env.user.company_id.currency_id: # 外币
  358. line.bank_id.currency_amount -= line.amount
  359. line.bank_id.balance -= line.amount
  360. for source in order.source_ids:
  361. source.name.to_reconcile += source.this_reconcile
  362. source.name.reconciled -= source.this_reconcile
  363. voucher = order.voucher_id
  364. order.write({
  365. 'to_reconcile': 0,
  366. 'reconciled': 0,
  367. 'voucher_id': False,
  368. 'approve_uid': False,
  369. 'approve_date': False,
  370. 'state': 'draft',
  371. })
  372. # 反审核凭证并删除
  373. if voucher.state == 'done':
  374. voucher.voucher_draft()
  375. voucher.unlink()
  376. return True
  377. def _prepare_vouch_line_data(self, line, name, account_id, debit, credit,
  378. voucher_id, partner_id, currency_id):
  379. rate_silent = currency_amount = 0
  380. if currency_id:
  381. rate_silent = self.env['res.currency'].get_rate_silent(
  382. self.date, currency_id)
  383. currency_amount = debit or credit
  384. debit = debit * (rate_silent or 1)
  385. credit = credit * (rate_silent or 1)
  386. return {
  387. 'name': name,
  388. 'account_id': account_id,
  389. 'debit': debit,
  390. 'credit': credit,
  391. 'voucher_id': voucher_id,
  392. 'partner_id': partner_id,
  393. 'currency_id': currency_id,
  394. 'currency_amount': currency_amount,
  395. 'rate_silent': rate_silent or ''
  396. }
  397. def _create_voucher_line(self, line, name, account_id, debit, credit,
  398. voucher_id, partner_id, currency_id):
  399. line_data = self._prepare_vouch_line_data(
  400. line, name, account_id, debit, credit,
  401. voucher_id, partner_id, currency_id)
  402. voucher_line = self.env['voucher.line'].create(line_data)
  403. return voucher_line
  404. def create_money_order_get_voucher(self, line_ids, source_ids,
  405. partner, name, note):
  406. """
  407. 为收款单创建凭证
  408. :param line_ids: 收款单明细
  409. :param source_ids: 没用到
  410. :param partner: 客户
  411. :param name: 收款单名称
  412. :return: 创建的凭证
  413. """
  414. vouch_obj = self.env['voucher'].sudo().create(
  415. {'date': self.date, 'ref': '%s,%s' % (self._name, self.id)})
  416. # self.write({'voucher_id': vouch_obj.id})
  417. amount_all = 0.0
  418. line_data = False
  419. for line in line_ids:
  420. line_data = line
  421. if not line.bank_id.account_id:
  422. raise UserError('请配置%s的会计科目' % (line.bank_id.name))
  423. # 生成借方明细行
  424. if line.amount: # 可能输入金额为0的收款单用于核销尾差
  425. self._create_voucher_line(line,
  426. "%s %s" % (name, note),
  427. line.bank_id.account_id.id,
  428. line.amount,
  429. 0,
  430. vouch_obj.id,
  431. '',
  432. line.currency_id.id
  433. )
  434. amount_all += line.amount
  435. if self.discount_amount != 0:
  436. # 生成借方明细行
  437. self._create_voucher_line(
  438. False,
  439. "%s 现金折扣 %s" % (name, note),
  440. self.discount_account_id.id,
  441. self.discount_amount,
  442. 0,
  443. vouch_obj.id,
  444. self.partner_id.id,
  445. line_data and line_data.currency_id.id or self.currency_id.id
  446. )
  447. if partner.c_category_id:
  448. partner_account_id = partner.c_category_id.account_id.id
  449. # 生成贷方明细行
  450. if amount_all + self.discount_amount:
  451. self._create_voucher_line(
  452. '',
  453. "%s %s" % (name, note),
  454. partner_account_id,
  455. 0,
  456. amount_all + self.discount_amount,
  457. vouch_obj.id,
  458. self.partner_id.id,
  459. line_data and line.currency_id.id or self.currency_id.id
  460. )
  461. return vouch_obj
  462. def create_money_order_pay_voucher(self, line_ids, source_ids,
  463. partner, name, note):
  464. """
  465. 为付款单创建凭证
  466. :param line_ids: 付款单明细
  467. :param source_ids: 没用到
  468. :param partner: 供应商
  469. :param name: 付款单名称
  470. :return: 创建的凭证
  471. """
  472. vouch_obj = self.env['voucher'].sudo().create(
  473. {'date': self.date, 'ref': '%s,%s' % (self._name, self.id)})
  474. # self.write({'voucher_id': vouch_obj.id})
  475. amount_all = 0.0
  476. line_data = False
  477. for line in line_ids:
  478. line_data = line
  479. if not line.bank_id.account_id:
  480. raise UserError('请配置%s的会计科目' % (line.bank_id.name))
  481. # 生成贷方明细行 credit
  482. if line.amount: # 支持金额为0的付款用于核销尾差
  483. self._create_voucher_line(line,
  484. "%s %s" % (name, note),
  485. line.bank_id.account_id.id,
  486. 0,
  487. line.amount,
  488. vouch_obj.id,
  489. '',
  490. line.currency_id.id
  491. )
  492. amount_all += line.amount
  493. partner_account_id = partner.s_category_id.account_id.id
  494. # 生成借方明细行 debit
  495. if amount_all - self.discount_amount:
  496. self._create_voucher_line(
  497. '',
  498. "%s %s" % (name, note),
  499. partner_account_id,
  500. amount_all - self.discount_amount,
  501. 0,
  502. vouch_obj.id,
  503. self.partner_id.id,
  504. line_data and line.currency_id.id or self.currency_id.id
  505. )
  506. if self.discount_amount != 0:
  507. # 生成借方明细行 debit
  508. self._create_voucher_line(
  509. line_data and line_data or False,
  510. "%s 手续费 %s" % (name, note),
  511. self.discount_account_id.id,
  512. self.discount_amount,
  513. 0,
  514. vouch_obj.id,
  515. self.partner_id.id,
  516. line_data and line.currency_id.id or self.currency_id.id
  517. )
  518. return vouch_obj
  519. class MoneyOrderLine(models.Model):
  520. _name = 'money.order.line'
  521. _description = '收付款单明细'
  522. @api.depends('bank_id')
  523. def _compute_currency_id(self):
  524. # 校验币别一致行
  525. companies = self.mapped('money_id.company_id')
  526. for company in companies:
  527. if not company.is_multi_currency:
  528. # 多币种未开启时:校验结算账户币种等于业务伙伴币种
  529. lines = self.filtered(lambda m: m.money_id.company_id == company)
  530. for mol in lines:
  531. mol.currency_id = mol.bank_id.account_id.currency_id.id \
  532. or mol.env.user.company_id.currency_id.id
  533. if mol.bank_id and mol.currency_id != mol.money_id.currency_id:
  534. raise ValidationError(
  535. '结算帐户与业务伙伴币别不一致。\n 结算账户币别:%s 业务伙伴币别:%s'
  536. % (mol.currency_id.name, mol.money_id.currency_id.name))
  537. else:
  538. # 多币种开启时:先判断收付款单币种是否为空
  539. lines = self.filtered(lambda m: m.money_id.company_id == company)
  540. for mol in lines:
  541. mol.currency_id = mol.bank_id.account_id.currency_id.id \
  542. or mol.env.user.company_id.currency_id.id
  543. if mol.bank_id:
  544. if not mol.money_id.currency_id:
  545. raise ValidationError(
  546. '请先保证待核销行的币别一致。\n 收付款单币别为空')
  547. if mol.currency_id != mol.money_id.currency_id:
  548. raise ValidationError(
  549. '结算帐户与收付款单币别不一致。\n 结算账户币别:%s 收付款单币别:%s'
  550. % (mol.currency_id.name, mol.money_id.currency_id.name))
  551. money_id = fields.Many2one('money.order', string='收付款单',
  552. ondelete='cascade',
  553. help='订单行对应的收付款单')
  554. bank_id = fields.Many2one('bank.account', string='结算账户', required=True, ondelete='restrict',
  555. help='本次收款/付款所用的计算账户,确认收付款单会修改对应账户的金额')
  556. amount = fields.Float(string='金额',
  557. digits='Amount',
  558. help='本次结算金额')
  559. mode_id = fields.Many2one('settle.mode', string='结算方式',
  560. ondelete='restrict',
  561. help='结算方式:支票、信用卡等')
  562. currency_id = fields.Many2one(
  563. 'res.currency', '币别',
  564. compute='_compute_currency_id',
  565. store=True, readonly=True,
  566. help='结算账户对应的外币币别')
  567. is_multi_currency = fields.Boolean('多币种', related='company_id.is_multi_currency')
  568. number = fields.Char(string='结算号',
  569. help='本次结算号')
  570. note = fields.Char(string='备注',
  571. help='可以为本次结算添加一些需要的标识信息')
  572. company_id = fields.Many2one(
  573. 'res.company',
  574. string='公司',
  575. change_default=True,
  576. default=lambda self: self.env.company)
  577. amount_in_base_currency = fields.Float(
  578. string='本位币金额', readonly=True,
  579. compute='_compute_amount_in_base_currency',
  580. digits='Amount',
  581. help='按当日汇率折算为本位币的金额')
  582. @api.depends('amount', 'currency_id', 'company_id')
  583. def _compute_amount_in_base_currency(self):
  584. for line in self:
  585. if line.currency_id and line.currency_id != line.company_id.currency_id:
  586. rate = line.currency_id.get_rate_silent(
  587. line.money_id.date, line.currency_id.id) or 1
  588. line.amount_in_base_currency = line.amount * rate
  589. else:
  590. line.amount_in_base_currency = line.amount
上海开阖软件有限公司 沪ICP备12045867号-1