stock_orderpoint_snooze.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models
  4. from odoo.tools.date_utils import add
  5. class StockOrderpointSnooze(models.TransientModel):
  6. _name = 'stock.orderpoint.snooze'
  7. _description = 'Snooze Orderpoint'
  8. orderpoint_ids = fields.Many2many('stock.warehouse.orderpoint')
  9. predefined_date = fields.Selection([
  10. ('day', '1 Day'),
  11. ('week', '1 Week'),
  12. ('month', '1 Month'),
  13. ('custom', 'Custom')
  14. ], string='Snooze for', default='day')
  15. snoozed_until = fields.Date('Snooze Date')
  16. @api.onchange('predefined_date')
  17. def _onchange_predefined_date(self):
  18. today = fields.Date.context_today(self)
  19. if self.predefined_date == 'day':
  20. self.snoozed_until = add(today, days=1)
  21. elif self.predefined_date == 'week':
  22. self.snoozed_until = add(today, weeks=1)
  23. elif self.predefined_date == 'month':
  24. self.snoozed_until = add(today, months=1)
  25. def action_snooze(self):
  26. self.orderpoint_ids.write({
  27. 'snoozed_until': self.snoozed_until
  28. })