This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlocation.py
64 lines (55 loc) · 2.04 KB
/
location.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import datetime
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
class Location(metaclass=PoolMeta):
__name__ = 'stock.location'
provisioning_location = fields.Many2One('stock.location',
'Provisioning Location',
states={
'invisible': Eval('type') != 'storage',
},
domain=[
('type', 'in', ['storage', 'view']),
],
help='Leave empty for no default provisioning.')
overflowing_location = fields.Many2One('stock.location',
'Overflowing Location',
states={
'invisible': Eval('type') != 'storage',
},
domain=[
('type', 'in', ['storage', 'view']),
],
help='Leave empty for no default overflowing.')
class LocationLeadTime(metaclass=PoolMeta):
__name__ = 'stock.location.lead_time'
@classmethod
def get_max_lead_time(cls):
"""Return the biggest lead time
increased by the maximum extra lead times"""
lead_time = datetime.timedelta(0)
lead_times = cls.search([])
if lead_times:
lead_time = sum(
(r.lead_time for r in lead_times if r.lead_time),
datetime.timedelta(0))
extra_lead_times = cls._get_extra_lead_times()
if extra_lead_times:
lead_time += max(extra_lead_times)
return lead_time
@classmethod
def _get_extra_lead_times(cls):
'Return a list of extra lead time'
pool = Pool()
ProductSupplier = pool.get('purchase.product_supplier')
extra = []
product_suppliers = ProductSupplier.search(
[('lead_time', '!=', None)],
order=[('lead_time', 'DESC')], limit=1)
if product_suppliers:
product_supplier, = product_suppliers
extra.append(product_supplier.lead_time)
return extra