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.

47 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. from random import randint
  4. import uuid
  5. class MemberCard(models.Model):
  6. def _get_current_user(self):
  7. return self.env.uid
  8. def _get_current_client(self):
  9. # TODO : this does not work
  10. return self.env['res.partner'].search([('id', '=',self.env.context['active_id'])])
  11. def _compute_bar_code(self):
  12. rule = self.env['barcode.rule'].search([('name', '=', 'Customer Barcodes')])[0]
  13. nomenclature = self.env['barcode.nomenclature']
  14. size = 13-len(rule.pattern)
  15. ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size] #str(randint(10**(size-1), 10**size-1))
  16. code = ean[0:12] + str(nomenclature.ean_checksum(ean))
  17. nomenclature.check_encoding(code,'ean13')
  18. return code
  19. _name = 'member.card'
  20. _order = 'activation_date desc'
  21. valid = fields.Boolean(default=True, string="Active")
  22. barcode = fields.Char("Code barre", oldname='ean13', default=_compute_bar_code)
  23. partner_id = fields.Many2one('res.partner') #, default=_get_current_client)
  24. responsible_id = fields.Many2one('res.users', default=_get_current_user, string="Responsable")
  25. activation_date = fields.Date(default=fields.Date.today, readonly=True, string="Date de création")
  26. end_date = fields.Date(readonly=True, string="Date d'expiration")
  27. comment = fields.Char("Raison", required=True)
  28. # A transient model for the creation of a new card. The user can only define the raison why
  29. # a new card is needed and the eater/worker that is concerned.
  30. class MemberCardWizard(models.TransientModel):
  31. _name = 'membercard.wizard'
  32. new_comment = fields.Char('Raison', required=True)
  33. @api.multi
  34. def create_new_card(self):
  35. client = self.env['res.partner'].search([('id', '=',self.env.context['active_id'])])
  36. client._deactivate_active_cards()
  37. client._new_card(self.new_comment)