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.

93 lines
4.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Eficent Business and IT Consulting Services S.L.
  3. # © 2016 Serpent Consulting Services Pvt. Ltd.
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from openerp import api, fields, models
  6. from openerp.tools import misc
  7. from openerp.exceptions import Warning
  8. from openerp.tools.translate import _
  9. class SummaryReport(models.TransientModel):
  10. _name = 'wiz.bank.unreconcile'
  11. @api.model
  12. def _get_unreconcile_entries(self):
  13. cr, uid, context = self.env.args
  14. context = dict(context)
  15. statement_line_obj = self.env['account.bank.statement.line']
  16. move_line_obj = self.env['account.move.line']
  17. bank_id = context.get('active_id')
  18. self.env.args = cr, uid, misc.frozendict(context)
  19. bank = self.env['account.bank.statement'].browse(bank_id)
  20. clearing_account_id = bank.journal_id and\
  21. bank.journal_id.default_credit_account_id and\
  22. bank.journal_id.default_credit_account_id.clearing_account_id and\
  23. bank.journal_id.default_credit_account_id.clearing_account_id.id
  24. if clearing_account_id:
  25. to_add_move_lines = move_line_obj.browse()
  26. account_move_line_records = self.env['account.move.line'].search([
  27. ('account_id', '=', clearing_account_id),
  28. ('account_id.reconcile', '=', True),
  29. '|',
  30. ('reconcile_id', '=', False),
  31. ('reconcile_partial_id', '!=', False)
  32. ], order='date')
  33. statements = statement_line_obj.search(
  34. [('statement_id', '=', bank_id),
  35. ('clearing_move_line_id', 'in',
  36. account_move_line_records.ids)])
  37. in_statement_clearing_lines = []
  38. for statement in statements:
  39. in_statement_clearing_lines += \
  40. statement.clearing_move_line_id
  41. for move_line in account_move_line_records:
  42. if move_line not in in_statement_clearing_lines:
  43. to_add_move_lines += move_line
  44. else:
  45. raise Warning(_("Create an Clearing Account to get "
  46. "the Unreconciled Journal Items."))
  47. return to_add_move_lines
  48. line_ids = fields.Many2many('account.move.line',
  49. 'wiz_unreconciles_move_line_rel',
  50. 'reconciles_id', 'accounts_id',
  51. 'Journal Items to Reconcile',
  52. default=_get_unreconcile_entries)
  53. @api.multi
  54. def process_wiz(self):
  55. context = dict(self._context)
  56. bank_stmt_obj = self.env['account.bank.statement']
  57. currency_obj = self.env['res.currency']
  58. statement = bank_stmt_obj.browse(context.get('active_ids'))
  59. lines = []
  60. for line in self.line_ids:
  61. currency_obj = currency_obj.with_context(date=statement.date)
  62. amount = 0.0
  63. if line.debit > 0:
  64. amount = line.debit
  65. elif line.credit > 0:
  66. amount = -line.credit
  67. if line.amount_currency:
  68. if line.company_id.currency_id.id != statement.currency.id:
  69. amount = line.currency_id.with_context(
  70. date=statement.date).compute(line.amount_currency,
  71. statement.currency)
  72. elif (line.currency_id and
  73. line.currency_id.id != statement.currency.id):
  74. amount = line.currency_id.with_context(
  75. date=statement.date).compute(amount,
  76. statement.currency)
  77. lines.append((0, 0, {
  78. 'name': line.name or '?',
  79. 'ref': line.ref,
  80. 'partner_id': line.partner_id.id,
  81. 'amount': amount,
  82. 'date': line.date,
  83. 'amount_currency': line.amount_currency,
  84. 'currency_id': line.currency_id.id,
  85. 'clearing_move_line_id': line.id,
  86. }))
  87. statement.write({'line_ids': lines})
  88. return True