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.

81 lines
2.8 KiB

  1. # Copyright 2004-2010 Tiny SPRL http://tiny.be
  2. # Copyright 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH
  3. # http://www.camptocamp.at
  4. # Copyright 2015 Antiun Ingenieria, SL (Madrid, Spain)
  5. # http://www.antiun.com
  6. # Antonio Espinosa <antonioea@antiun.com>
  7. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  8. from odoo import api, fields, models
  9. class ResPartnerIdNumber(models.Model):
  10. _name = "res.partner.id_number"
  11. _description = "Partner ID Number"
  12. _order = "name"
  13. @api.constrains("name", "category_id")
  14. def validate_id_number(self):
  15. for record in self:
  16. record.category_id.validate_id_number(record)
  17. name = fields.Char(
  18. string="ID Number",
  19. required=True,
  20. help="The ID itself. For example, Driver License number of this person",
  21. )
  22. category_id = fields.Many2one(
  23. string="Category",
  24. required=True,
  25. comodel_name="res.partner.id_category",
  26. help="ID type defined in configuration. For example, Driver License",
  27. )
  28. partner_id = fields.Many2one(
  29. string="Partner", required=True, comodel_name="res.partner", ondelete="cascade"
  30. )
  31. partner_issued_id = fields.Many2one(
  32. string="Issued by",
  33. comodel_name="res.partner",
  34. help="Another partner, who issued this ID. For example, Traffic "
  35. "National Institution",
  36. )
  37. place_issuance = fields.Char(
  38. string="Place of Issuance",
  39. help="The place where the ID has been issued. For example the country "
  40. "for passports and visa",
  41. )
  42. date_issued = fields.Date(
  43. string="Issued on",
  44. help="Issued date. For example, date when person approved his driving "
  45. "exam, 21/10/2009",
  46. )
  47. valid_from = fields.Date(
  48. string="Valid from", help="Validation period stating date."
  49. )
  50. valid_until = fields.Date(
  51. string="Valid until",
  52. help="Expiration date. For example, date when person needs to renew "
  53. "his driver license, 21/10/2019",
  54. )
  55. comment = fields.Text(string="Notes")
  56. status = fields.Selection(
  57. [
  58. ("draft", "New"),
  59. ("open", "Running"),
  60. ("pending", "To Renew"),
  61. ("close", "Expired"),
  62. ]
  63. )
  64. active = fields.Boolean(string="Active", default=True)
  65. @api.model
  66. def default_get(self, fields):
  67. res = super(ResPartnerIdNumber, self).default_get(fields)
  68. # It seems to be a bug in native odoo that the field partner_id
  69. # is not in the fields list by default. A workaround is required
  70. # to force this.
  71. if "default_partner_id" in self._context and "partner_id" not in fields:
  72. fields.append("partner_id")
  73. res["partner_id"] = self._context.get("default_partner_id")
  74. return res