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.

75 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Guewen Baconnier
  5. # Copyright 2015 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #
  21. from openerp import models, fields, api
  22. class ResPartnerRevision(models.Model):
  23. _name = 'res.partner.revision'
  24. _description = 'Partner Revision'
  25. _order = 'date desc'
  26. _rec_name = 'date'
  27. partner_id = fields.Many2one(comodel_name='res.partner',
  28. string='Partner',
  29. required=True)
  30. change_ids = fields.One2many(comodel_name='res.partner.revision.change',
  31. inverse_name='revision_id',
  32. string='Changes')
  33. date = fields.Datetime(default=fields.Datetime.now)
  34. note = fields.Text()
  35. @api.multi
  36. def apply(self):
  37. self.mapped('change_ids').apply()
  38. class ResPartnerRevisionChange(models.Model):
  39. _name = 'res.partner.revision.change'
  40. _description = 'Partner Revision Change'
  41. _rec_name = 'new_value'
  42. revision_id = fields.Many2one(comodel_name='res.partner.revision',
  43. required=True,
  44. string='Revision',
  45. ondelete='cascade')
  46. field_id = fields.Many2one(comodel_name='ir.model.fields',
  47. string='Field',
  48. required=True)
  49. # TODO: different types of fields
  50. current_value = fields.Char('Current')
  51. new_value = fields.Char('New')
  52. state = fields.Selection(
  53. selection=[('draft', 'Waiting'),
  54. ('done', 'Accepted'),
  55. ('cancel', 'Refused'),
  56. ],
  57. required=True,
  58. default='draft',
  59. )
  60. @api.multi
  61. def apply(self):
  62. for change in self:
  63. if change.state in ('cancel', 'done'):
  64. continue
  65. partner = change.revision_id.partner_id
  66. partner.write({change.field_id.name: change.new_value})