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.

97 lines
3.8 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Point Of Sale - Multiple Cash Control 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.orm import Model
  23. from openerp.osv.osv import except_osv
  24. from openerp.tools.translate import _
  25. class account_bank_statement_line(Model):
  26. _inherit = 'account.bank.statement.line'
  27. _POS_PAYMENT_ALLOW_WRITE = [
  28. 'sequence', 'move_ids',
  29. ]
  30. # Private Function Section
  31. def _check_allow_change_pos_payment(
  32. self, cr, uid, ids, vals, context=None):
  33. """Allow or block change of account bank statement line, linked to
  34. a non draft POS Order.
  35. * if 'change_pos_payment' is in the context, changes are allowed;
  36. * otherwise:
  37. * allow write of some fields only;
  38. * forbid deletion;"""
  39. context = context or {}
  40. values = vals.copy() if vals else {}
  41. check_pos_order = False
  42. po_obj = self.pool['pos.order']
  43. if not ids:
  44. return True
  45. if values:
  46. # Allow some write
  47. for key in self._POS_PAYMENT_ALLOW_WRITE:
  48. if key in values:
  49. del values[key]
  50. if not values:
  51. return True
  52. # Allow changes, if user use the wizard
  53. if context.get('change_pos_payment', False):
  54. check_pos_order = True
  55. for absl in self.browse(cr, uid, ids, context=context):
  56. if absl.pos_statement_id:
  57. if absl.pos_statement_id.state != 'draft':
  58. if check_pos_order:
  59. po_obj._allow_change_payments(
  60. cr, uid, [absl.pos_statement_id.id],
  61. context=context)
  62. else:
  63. if values.keys() == ['partner_id']:
  64. po_obj._allow_change_payments(
  65. cr, uid, [absl.pos_statement_id.id],
  66. context=context)
  67. else:
  68. raise except_osv(
  69. _('Error!'),
  70. _("""You can not change payments of POS by"""
  71. """ this way. Please use the regular"""
  72. """ wizard in POS view!"""))
  73. return True
  74. # Overload Section
  75. def write(self, cr, uid, ids, vals, context=None):
  76. self._check_allow_change_pos_payment(
  77. cr, uid, ids, vals, context=context)
  78. res = super(account_bank_statement_line, self).write(
  79. cr, uid, ids, vals, context=context)
  80. return res
  81. def unlink(self, cr, uid, ids, context=None):
  82. self._check_allow_change_pos_payment(
  83. cr, uid, ids, None, context=context)
  84. res = super(account_bank_statement_line, self).unlink(
  85. cr, uid, ids, context=context)
  86. return res