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.

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