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.

66 lines
2.3 KiB

  1. # coding: utf-8
  2. # Copyright (C) 2015-Today GRAP (http://www.grap.coop)
  3. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import _, api, models
  6. from openerp.exceptions import ValidationError
  7. class AccountBankStatementLine(models.Model):
  8. _inherit = 'account.bank.statement.line'
  9. _POS_PAYMENT_ALLOW_WRITE = [
  10. 'sequence', 'journal_entry_id',
  11. ]
  12. # Private Function Section
  13. @api.multi
  14. def _check_allow_change_pos_payment(self, vals):
  15. """Allow or block change of account bank statement line, linked to
  16. a non draft POS Order.
  17. * if 'change_pos_payment' is in the context, changes are allowed;
  18. * otherwise:
  19. * allow write of some fields only;
  20. * forbid deletion;"""
  21. values = vals.copy() if vals else {}
  22. check_pos_order = False
  23. if values:
  24. # Allow some write
  25. for key in self._POS_PAYMENT_ALLOW_WRITE:
  26. if key in values:
  27. del values[key]
  28. if not values:
  29. return
  30. # Allow changes, if user use the wizard
  31. if self._context.get('change_pos_payment', False):
  32. check_pos_order = True
  33. for statement_line in self:
  34. order = statement_line.pos_statement_id
  35. if order:
  36. if order.state != 'draft':
  37. if check_pos_order:
  38. order._allow_change_payments()
  39. else:
  40. if values.keys() == ['partner_id']:
  41. order._allow_change_payments()
  42. else:
  43. raise ValidationError(_(
  44. "You can not change payments of POS by this"
  45. " way. Please use the regular wizard in POS"
  46. " view!"))
  47. # Overload Section
  48. @api.multi
  49. def write(self, vals):
  50. self._check_allow_change_pos_payment(vals)
  51. return super(AccountBankStatementLine, self).write(vals)
  52. @api.multi
  53. def unlink(self):
  54. self._check_allow_change_pos_payment(None)
  55. return super(AccountBankStatementLine, self).unlink()