-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathproduction_lot.py
37 lines (29 loc) · 1.26 KB
/
production_lot.py
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
35
36
37
# © 2008-2022 Deltatech
# See README.rst file on addons root folder for license details
import datetime
from odoo import api, fields, models
class StockProductionLot(models.Model):
_inherit = "stock.lot"
production_date = fields.Datetime()
def _get_dates(self, product_id=None):
"""Returns dates based on number of days configured in current lot's product."""
mapped_fields = {
"expiration_date": "expiration_time",
"use_date": "use_time",
"removal_date": "removal_time",
"alert_date": "alert_time",
}
res = dict.fromkeys(mapped_fields, False)
product = self.env["product.product"].browse(product_id) or self.product_id
production_date = self.production_date or datetime.datetime.now()
if product:
for field in mapped_fields:
duration = getattr(product, mapped_fields[field])
if duration:
date = production_date + datetime.timedelta(days=duration)
res[field] = fields.Datetime.to_string(date)
return res
@api.onchange("production_date")
def onchange_production_date(self):
if not self.production_date:
self.production_date = self.create_date