odoo_dev 开发培训作业:图书管理系统
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

20 lines
682B

  1. from odoo import fields, models
  2. class Book(models.Model):
  3. _inherit = 'library.book'
  4. is_available = fields.Boolean('Is Available?')
  5. isbn = fields.Char(help="Use a valid ISBN-13 or ISBN-10.")
  6. publisher_id = fields.Many2one(index=True)
  7. def _check_isbn(self):
  8. self.ensure_one()
  9. isbn = self.isbn.replace('-', '')
  10. digits = [int(x) for x in isbn if x.isdigit()]
  11. if len(digits) == 10:
  12. ponderators = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  13. total = sum(a * b for a, b in zip(digits[:9], ponderators))
  14. check = total % 11
  15. return digits[-1] == check
  16. else:
  17. return super()._check_isbn()
上海开阖软件有限公司 沪ICP备12045867号-1