Skip to content

Commit

Permalink
improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gurneyalex committed Feb 6, 2014
1 parent 5655870 commit ae207a9
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions sale_stock_global_delivery_lead_time/sale_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ def _min_max_date_planned(self, cr, uid, ids, field_names, arg, context=None):
if not ids:
return res
order_line_obj = self.pool.get('sale.order.line')
sale_infos = self.read(cr, uid, ids, ['delay', 'date_order'],
context=context, load='_classic_write')
line_ids = order_line_obj.search(cr, uid, [('order_id', 'in', ids)],
sale_infos = self.read(cr, uid, ids,
['delay', 'date_order'],
context=context,
load='_classic_write')
line_ids = order_line_obj.search(cr, uid,
[('order_id', 'in', ids)],
context=context)
line_delays = order_line_obj.read(cr, uid, line_ids,
['order_id', 'delay'],
Expand All @@ -47,19 +50,18 @@ def _min_max_date_planned(self, cr, uid, ids, field_names, arg, context=None):
for sale_info in sale_infos:
sale_id = sale_info['id']
res[sale_id] = {}
start_date = datetime.strptime(
self.date_to_datetime(cr, uid, sale_info['date_order'], context),
DEFAULT_SERVER_DATETIME_FORMAT
)
start_date = datetime.strptime(self.date_to_datetime(cr, uid,
sale_info['date_order'],
context),
DEFAULT_SERVER_DATETIME_FORMAT)
min_delay = sale_info['delay'] + min(order_line_delays.get(sale_id, [0]))
max_delay = sale_info['delay'] + max(order_line_delays.get(sale_id, [0]))
min_date = start_date + relativedelta(days=min_delay)
max_date = start_date + relativedelta(days=max_delay)
print min_date, max_date
for name in field_names:
if name.startswith('min'):
if name == 'min_date_planned':
date = min_date
elif name.startswith('max'):
elif name == 'max_date_planned':
date = max_date
else:
continue
Expand All @@ -69,10 +71,10 @@ def _min_max_date_planned(self, cr, uid, ids, field_names, arg, context=None):
_columns = {
'delay': fields.float('Delivery Lead Time',
required=True,
help="Number of days between the order"
" confirmation and the shipping of the products"
" to the customer. This lead time is added"
" to the lead time of each line.",
help="Number of days between the order "
"confirmation and the shipping of the products "
"to the customer. This lead time is added "
"to the lead time of each line.",
readonly=True,
states={'draft': [('readonly', False)]}),
'min_date_planned': fields.function(_min_max_date_planned,
Expand All @@ -83,13 +85,15 @@ def _min_max_date_planned(self, cr, uid, ids, field_names, arg, context=None):
type='date',
string='Latest date planned',
method=True, multi='date_planned'),
}
}
_defaults = {'delay': 0,
}

def _get_date_planned(self, cr, uid, order, line, start_date, context=None):
date_planned = super(sale_order, self)._get_date_planned(
cr, uid, order, line, start_date, context)
date_planned = datetime.strptime(date_planned, DEFAULT_SERVER_DATETIME_FORMAT)
date_planned = date_planned + relativedelta(days=order.delay or 0.0)
date_planned = super(sale_order, self)._get_date_planned(cr, uid, order,
line, start_date,
context)
date_planned = datetime.strptime(date_planned,
DEFAULT_SERVER_DATETIME_FORMAT)
date_planned += relativedelta(days=order.delay or 0.0)
return date_planned.strftime(DEFAULT_SERVER_DATETIME_FORMAT)

0 comments on commit ae207a9

Please sign in to comment.