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.

72 lines
2.2 KiB

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