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.

69 lines
2.1 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 PurchaseTest(models.Model):
  5. _inherit = 'base.exception'
  6. _name = "base.exception.test.purchase"
  7. _description = "Base Ecxeption Test Model"
  8. name = fields.Char(required=True)
  9. user_id = fields.Many2one('res.users', string='Responsible')
  10. state = fields.Selection(
  11. [('draft', 'New'), ('cancel', 'Cancelled'),
  12. ('purchase', 'Purchase'),
  13. ('to approve', 'To approve'), ('done', 'Done')],
  14. string="Status", readonly=True, default='draft')
  15. active = fields.Boolean(default=True)
  16. partner_id = fields.Many2one('res.partner', string='Partner')
  17. line_ids = fields.One2many(
  18. 'base.exception.test.purchase.line', 'lead_id')
  19. amount_total = fields.Float(
  20. compute='_compute_amount_total', store=True)
  21. @api.depends('line_ids')
  22. def _compute_amount_total(cls):
  23. for record in cls:
  24. for line in record.line_ids:
  25. record.amount_total += line.amount * line.qty
  26. @api.constrains('ignore_exception', 'line_ids', 'state')
  27. def test_purchase_check_exception(cls):
  28. orders = cls.filtered(lambda s: s.state == 'purchase')
  29. if orders:
  30. orders._check_exception()
  31. @api.multi
  32. def button_approve(cls, force=False):
  33. cls.write({'state': 'to approve'})
  34. return {}
  35. @api.multi
  36. def button_draft(cls):
  37. cls.write({'state': 'draft'})
  38. return {}
  39. @api.multi
  40. def button_confirm(cls):
  41. cls.write({'state': 'purchase'})
  42. return True
  43. @api.multi
  44. def button_cancel(cls):
  45. cls.write({'state': 'cancel'})
  46. @api.multi
  47. def _reverse_field(self):
  48. return 'test_purchase_ids'
  49. class LineTest(models.Model):
  50. _name = "base.exception.test.purchase.line"
  51. _description = "Base Exception Test Model Line"
  52. name = fields.Char()
  53. lead_id = fields.Many2one('base.exception.test.purchase',
  54. ondelete='cascade')
  55. qty = fields.Float()
  56. amount = fields.Float()