summaryrefslogtreecommitdiff
path: root/addons/stock/wizard/stock_orderpoint_snooze.py
blob: 00808dbb1820ef17d9d8aa096976e4872858d149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models
from odoo.tools.date_utils import add


class StockOrderpointSnooze(models.TransientModel):
    _name = 'stock.orderpoint.snooze'
    _description = 'Snooze Orderpoint'

    orderpoint_ids = fields.Many2many('stock.warehouse.orderpoint')
    predefined_date = fields.Selection([
        ('day', '1 Day'),
        ('week', '1 Week'),
        ('month', '1 Month'),
        ('custom', 'Custom')
    ], string='Snooze for', default='day')
    snoozed_until = fields.Date('Snooze Date')

    @api.onchange('predefined_date')
    def _onchange_predefined_date(self):
        today = fields.Date.today()
        if self.predefined_date == 'day':
            self.snoozed_until = add(today, days=1)
        elif self.predefined_date == 'week':
            self.snoozed_until = add(today, weeks=1)
        elif self.predefined_date == 'month':
            self.snoozed_until = add(today, months=1)

    def action_snooze(self):
        self.orderpoint_ids.write({
            'snoozed_until': self.snoozed_until
        })