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.

91 lines
2.6 KiB

  1. # Copyright 2016 Akretion Mourad EL HADJ MIMOUNE
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. class ExceptionRule(models.Model):
  5. _inherit = "exception.rule"
  6. _name = "exception.rule"
  7. method = fields.Selection(
  8. selection_add=[('exception_method_no_zip', 'Purchase exception no zip')]
  9. )
  10. class PurchaseTest(models.Model):
  11. _inherit = "base.exception"
  12. _name = "base.exception.test.purchase"
  13. _description = "Base Ecxeption Test Model"
  14. name = fields.Char(required=True)
  15. user_id = fields.Many2one("res.users", string="Responsible")
  16. state = fields.Selection(
  17. [
  18. ("draft", "New"),
  19. ("cancel", "Cancelled"),
  20. ("purchase", "Purchase"),
  21. ("to approve", "To approve"),
  22. ("done", "Done"),
  23. ],
  24. string="Status",
  25. readonly=True,
  26. default="draft",
  27. )
  28. active = fields.Boolean(default=True)
  29. partner_id = fields.Many2one("res.partner", string="Partner")
  30. line_ids = fields.One2many("base.exception.test.purchase.line", "lead_id")
  31. amount_total = fields.Float(compute="_compute_amount_total", store=True)
  32. @api.depends("line_ids")
  33. def _compute_amount_total(cls):
  34. for record in cls:
  35. for line in record.line_ids:
  36. record.amount_total += line.amount * line.qty
  37. @api.constrains("ignore_exception", "line_ids", "state")
  38. def test_purchase_check_exception(cls):
  39. orders = cls.filtered(lambda s: s.state == "purchase")
  40. if orders:
  41. orders._check_exception()
  42. @api.multi
  43. def button_approve(cls, force=False):
  44. cls.write({"state": "to approve"})
  45. return {}
  46. @api.multi
  47. def button_draft(cls):
  48. cls.write({"state": "draft"})
  49. return {}
  50. @api.multi
  51. def button_confirm(cls):
  52. cls.write({"state": "purchase"})
  53. return True
  54. @api.multi
  55. def button_cancel(cls):
  56. cls.write({"state": "cancel"})
  57. @api.multi
  58. def _reverse_field(self):
  59. return "test_purchase_ids"
  60. def exception_method_no_zip(self):
  61. records_fail = self.env["base.exception.test.purchase"]
  62. for rec in self:
  63. if not rec.partner_id.zip:
  64. records_fail += rec
  65. return records_fail
  66. class LineTest(models.Model):
  67. _name = "base.exception.test.purchase.line"
  68. _description = "Base Exception Test Model Line"
  69. name = fields.Char()
  70. lead_id = fields.Many2one(
  71. "base.exception.test.purchase", ondelete="cascade"
  72. )
  73. qty = fields.Float()
  74. amount = fields.Float()