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
722B

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