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.

77 lines
2.6 KiB

7 years ago
  1. # Copyright 2017 Akretion (http://www.akretion.com)
  2. # Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
  3. import os
  4. from odoo import api, fields, models, tools
  5. import logging
  6. _logger = logging.getLogger(__name__)
  7. testing = tools.config.get('test_enable') or os.environ.get('ODOO_TEST_ENABLE')
  8. if testing:
  9. class PurchaseTest(models.Model):
  10. _inherit = 'base.exception'
  11. _name = "base.exception.test.purchase"
  12. _description = "Base Ecxeption Test Model"
  13. rule_group = fields.Selection(
  14. selection_add=[('test_base', 'test')],
  15. default='test_base',
  16. )
  17. name = fields.Char(required=True)
  18. user_id = fields.Many2one('res.users', string='Responsible')
  19. state = fields.Selection(
  20. [('draft', 'New'), ('cancel', 'Cancelled'),
  21. ('purchase', 'Purchase'),
  22. ('to approve', 'To approve'), ('done', 'Done')],
  23. string="Status", readonly=True, default='draft')
  24. active = fields.Boolean(default=True)
  25. partner_id = fields.Many2one('res.partner', string='Partner')
  26. line_ids = fields.One2many(
  27. 'base.exception.test.purchase.line', 'lead_id')
  28. amount_total = fields.Float(
  29. compute='_compute_amount_total', store=True)
  30. @api.depends('line_ids')
  31. def _compute_amount_total(self):
  32. for record in self:
  33. for line in record.line_ids:
  34. record.amount_total += line.amount * line.qty
  35. @api.constrains('ignore_exception', 'line_ids', 'state')
  36. def test_purchase_check_exception(self):
  37. orders = self.filtered(lambda s: s.state == 'purchase')
  38. if orders:
  39. orders._check_exception()
  40. @api.multi
  41. def button_approve(self, force=False):
  42. self.write({'state': 'to approve'})
  43. return {}
  44. @api.multi
  45. def button_draft(self):
  46. self.write({'state': 'draft'})
  47. return {}
  48. @api.multi
  49. def button_confirm(self):
  50. self.write({'state': 'purchase'})
  51. return True
  52. @api.multi
  53. def button_cancel(self):
  54. self.write({'state': 'cancel'})
  55. def test_base_get_lines(self):
  56. self.ensure_one()
  57. return self.line_ids
  58. class LineTest(models.Model):
  59. _name = "base.exception.test.purchase.line"
  60. _description = "Base Ecxeption Test Model Line"
  61. name = fields.Char()
  62. lead_id = fields.Many2one('base.exception.test.purchase',
  63. ondelete='cascade')
  64. qty = fields.Float()
  65. amount = fields.Float()