-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathstock_production_lot.py
More file actions
31 lines (23 loc) · 1.15 KB
/
stock_production_lot.py
File metadata and controls
31 lines (23 loc) · 1.15 KB
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
# Copyright (C) 2018 - TODAY, Open Source Integrators
# Copyright (C) 2021 Serpent Consulting Services
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
DELTA_TYPES = ("day", "week", "month", "year")
class StockProductionLot(models.Model):
_inherit = "stock.lot"
warranty_exp_date = fields.Date(string="Warranty Expiration Date")
def _get_warranty_exp_date(self, start_date=None):
if not start_date:
start_date = fields.Date.context_today(self)
elif hasattr(start_date, "astimezone"):
# Datetime object, convert to date
start_date = fields.Date.context_today(self, timestamp=start_date)
delta_type = self.product_id.product_tmpl_id.warranty_type
duration = self.product_id.product_tmpl_id.warranty
if not duration or delta_type not in DELTA_TYPES:
return False
return start_date + relativedelta(**{f"{delta_type}s": duration})
@api.onchange("product_id")
def _onchange_product_id(self):
self.warranty_exp_date = self._get_warranty_exp_date()