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.

35 lines
1.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import uuid
  2. from odoo import api, fields, models
  3. class MemberCard(models.Model):
  4. def _get_current_user(self):
  5. return self.env.uid
  6. def _compute_bar_code(self):
  7. rule = self.env["barcode.rule"].search(
  8. [("name", "=", "Customer Barcodes")]
  9. )[0]
  10. size = 13 - len(rule.pattern)
  11. ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size]
  12. return ean[0:12] + str(
  13. self.env["barcode.nomenclature"].ean_checksum(ean)
  14. )
  15. _name = "member.card"
  16. _order = "create_date desc"
  17. _description = "Member Card"
  18. valid = fields.Boolean(default=True, string="Active")
  19. barcode = fields.Char(
  20. "Barcode", oldname="ean13", default=_compute_bar_code
  21. )
  22. partner_id = fields.Many2one(
  23. "res.partner"
  24. ) # , default=_get_current_client)
  25. responsible_id = fields.Many2one(
  26. "res.users", default=_get_current_user, string="Responsible"
  27. )
  28. end_date = fields.Date(readonly=True, string="Expiration Date")
  29. comment = fields.Char("Reason", required=True)