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.

145 lines
5.1 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Point Of Sale - Change Payment module for Odoo
  5. # Copyright (C) 2015-Today GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. #from openerp.osv import fields
  23. #from openerp.osv.osv import except_osv
  24. from openerp.exceptions import ValidationError
  25. from openerp import models, api, fields
  26. from openerp.tools.translate import _
  27. class PosSwitchJournalWizard(models.TransientModel):
  28. _name = 'pos.switch.journal.wizard'
  29. # Default Section
  30. def _default_statement_line_id(self):
  31. return self._context.get('active_id')
  32. # Column Section
  33. statement_line_id = fields.Many2one(
  34. comodel_name='account.bank.statement.line', string='Statement',
  35. required=True, readonly=True, default=_default_statement_line_id)
  36. old_journal_id = fields.Many2one(
  37. comodel_name='account.journal', string='Old Journal', required=True,
  38. readonly=True)
  39. available_journal_ids = fields.Many2many(
  40. comodel_name='account.journal',
  41. compute='_compute_available_journal_ids')
  42. new_journal_id = fields.Many2one(
  43. comodel_name='account.journal', string='New Journal',
  44. domain="[('id', 'in', available_journal_ids)]")
  45. amount = fields.Float(string='Amount', readonly=True)
  46. new_statement_id = fields.Many2one()
  47. # Compute Section
  48. @api.one
  49. @api.depends('statement_line_id')
  50. def _compute_available_journal_ids(self):
  51. res = []
  52. for statement in self.statement_line_id.pos_statement_id\
  53. .session_id.statement_ids:
  54. res.append(statement.journal_id.id)
  55. self.available_journal_ids = res
  56. # selection='_get_new_statement_id', string='New Journal',
  57. # required=True),
  58. # @api.model
  59. # def _get_new_statement_id(self, cr, uid, context=None):
  60. # absl_obj = self.pool['account.bank.statement.line']
  61. # abs_obj = self.pool['account.bank.statement']
  62. # if context.get('active_model', False) != 'account.bank.statement.line':
  63. # return True
  64. # absl = absl_obj.browse(
  65. # cr, uid, context.get('active_id'), context=context)
  66. # abs_ids = [
  67. # x.id for x in absl.pos_statement_id.session_id.statement_ids]
  68. # res = abs_obj.read(
  69. # cr, uid, abs_ids, ['id', 'journal_id'], context=context)
  70. # res = [(
  71. # r['id'], r['journal_id'][1])
  72. # for r in res if r['id'] != absl.statement_id.id]
  73. # return res
  74. # _columns = {
  75. # }
  76. # View Section
  77. # @api.model
  78. # def default_get(self, fields):
  79. # statement_line_obj = self.env['account.bank.statement.line']
  80. # res = super(PosSwitchJournalWizard, self).default_get(fields)
  81. # statement_line = statement_line_obj.browse(
  82. # self._context.get('active_id'))
  83. # self.statement_line_id = statement_line.id
  84. # res.update({
  85. ## 'statement_line_id': statement_line.id,
  86. # 'old_journal_id': statement_line.journal_id.id,
  87. # 'amount': statement_line.amount,
  88. # })
  89. # return res
  90. # Action section
  91. @api.one
  92. def button_switch_journal(self):
  93. # if self.statement_line_id.pos_statement_id:
  94. self.statement_line_id.pos_statement_id._allow_change_payments()
  95. # TODO : FIXME when upstream is fixed.
  96. # We do 2 write, one in the old statement, one in the new, with
  97. # 'amount' value each time to recompute all the functional fields
  98. # of the Account Bank Statements
  99. # self.statement_line_id.with_context(change_pos_payment=True).write({
  100. # 'amount': 0,
  101. # })
  102. # self.statement_line_id.with_context(change_pos_payment=True).write({
  103. # 'amount': self.statement_line_id.amount,
  104. # 'statement_id': self.new_statement_id.id,
  105. # })
  106. # amount = absl.amount
  107. # ctx = context.copy()
  108. # ctx['change_pos_payment'] = True
  109. # absl_obj.write(cr, uid, [absl.id], {
  110. # 'amount': 0,
  111. # }, context=ctx)
  112. # # Change statement of the statement line
  113. # absl_obj.write(cr, uid, [absl.id], {
  114. # 'amount': amount,
  115. # 'statement_id': int(psjw.new_statement_id),
  116. # }, context=ctx)
  117. return {
  118. 'type': 'ir.actions.client',
  119. 'tag': 'reload',
  120. }