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.

71 lines
2.2 KiB

7 years ago
  1. # Copyright 2017 Akretion (http://www.akretion.com)
  2. # Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
  3. from odoo import fields, models, api
  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('base.exception.test.model.line', 'lead_id')
  22. amount_total = fields.Float(compute='_compute_amount_total', store=True)
  23. @api.depends('line_ids')
  24. def _compute_amount_total(self):
  25. for record in self:
  26. for line in record.line_ids:
  27. record.amount_total += line.amount * line.qty
  28. @api.constrains('ignore_exception', 'line_ids', 'state')
  29. def test_purchase_check_exception(self):
  30. orders = self.filtered(lambda s: s.state == 'purchase')
  31. if orders:
  32. orders._check_exception()
  33. @api.multi
  34. def button_approve(self, force=False):
  35. self.write({'state': 'to approve'})
  36. return {}
  37. @api.multi
  38. def button_draft(self):
  39. self.write({'state': 'draft'})
  40. return {}
  41. @api.multi
  42. def button_confirm(self):
  43. self.write({'state': 'purchase'})
  44. return True
  45. @api.multi
  46. def button_cancel(self):
  47. self.write({'state': 'cancel'})
  48. def test_base_get_lines(self):
  49. self.ensure_one()
  50. return self.line_ids
  51. class LineTest(models.Model):
  52. _name = "base.exception.test.model.line"
  53. _description = "Base Ecxeption Test Model Line"
  54. name = fields.Char()
  55. lead_id = fields.Many2one('base.exception.test.model', ondelete='cascade')
  56. qty = fields.Float()
  57. amount = fields.Float()