Skip to content

Commit

Permalink
[PEP8]
Browse files Browse the repository at this point in the history
  • Loading branch information
nbessi committed Jan 31, 2014
1 parent ded9991 commit 5655870
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 37 deletions.
22 changes: 11 additions & 11 deletions sale_stock_global_delivery_lead_time/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
#
##############################################################################
{
'name' : 'Sale global delivery lead time',
'version' : '0.1',
'category' : 'Sales Management',
'name': 'Sale global delivery lead time',
'version': '0.1',
'category': 'Sales Management',
'description': '''
Provides a way of setting a delivery lead time for all lines of a sale order
''',
'author' : 'Camptocamp',
'website' : 'http://www.camptocamp.com',
'depends' : ['sale_stock'],
'data' : ['sale_stock_view.xml'],
'demo' : [],
'test' : [],
'author': 'Camptocamp',
'website': 'http://www.camptocamp.com',
'depends': ['sale_stock'],
'data': ['sale_stock_view.xml'],
'demo': [],
'test': [],
'installable': True,
'auto_install' : False,
'application' : False,
'auto_install': False,
'application': False,
}

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
63 changes: 37 additions & 26 deletions sale_stock_global_delivery_lead_time/sale_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from datetime import datetime, timedelta
from datetime import datetime
from dateutil.relativedelta import relativedelta

from openerp.osv import orm, fields
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT


class sale_order(orm.Model):
Expand All @@ -33,18 +33,24 @@ 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)], context=context)
line_delays = order_line_obj.read(cr, uid, line_ids, ['order_id', 'delay'], context=context, load='_classic_write')
order_line_delays = {} # dict order_id: [line delays]
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'],
context=context,
load='_classic_write')
order_line_delays = {} # dict order_id: [line delays]
for line_info in line_delays:
order_line_delays.setdefault(line_info['order_id'], []).append(line_info['delay'])
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)
print start_date, sale_info['delay'], order_line_delays.get(sale_id, [0])
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)
Expand All @@ -58,27 +64,32 @@ def _min_max_date_planned(self, cr, uid, ids, field_names, arg, context=None):
else:
continue
res[sale_id][name] = date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
print res
return res

_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.",
readonly=True,
states={'draft': [('readonly', False)]}),
'min_date_planned': fields.function(_min_max_date_planned,
type='date',
string='Earliest date planned',
method=True, multi='date_planned'),
'max_date_planned': fields.function(_min_max_date_planned,
type='date',
string='Latest date planned',
method=True, multi='date_planned'),
}
_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.",
readonly=True,
states={'draft': [('readonly', False)]}),
'min_date_planned': fields.function(_min_max_date_planned,
type='date',
string='Earliest date planned',
method=True, multi='date_planned'),
'max_date_planned': fields.function(_min_max_date_planned,
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) + 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 = date_planned + relativedelta(days=order.delay or 0.0)
return date_planned.strftime(DEFAULT_SERVER_DATETIME_FORMAT)

0 comments on commit 5655870

Please sign in to comment.