From e19d5e4685d3d98fcb3b9f6020e4717542d85726 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Mon, 13 May 2013 16:53:18 +0200 Subject: [PATCH 1/3] [FIX]purchase/stock: when validating a PO, information on scheduled_date was not correct, should take into account, schedule_date for each product instead of PO date. Also add a message in chatter whenever we receive a product. Added a function in tools/misc/py for the purpose of printing correct date in user timezone + timezone information. bzr revid: csn@openerp.com-20130513145318-qterabm7vmjkezi4 --- addons/purchase/purchase.py | 2 +- addons/stock/stock.py | 10 +++++++--- addons/stock/stock_view.xml | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index b1f552b64cc..a7973a40a47 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -641,7 +641,7 @@ class purchase_order(osv.osv): 'product_uom': order_line.product_uom.id, 'product_uos': order_line.product_uom.id, 'date': self.date_to_datetime(cr, uid, order.date_order, context), - 'date_expected': self.date_to_datetime(cr, uid, order.date_order, context), + 'date_expected': self.date_to_datetime(cr, uid, order_line.date_planned, context), 'location_id': order.partner_id.property_stock_supplier.id, 'location_dest_id': order.location_id.id, 'picking_id': picking_id, diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 6d9cb1aae84..fbbee7771b1 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -29,7 +29,7 @@ from openerp.osv import fields, osv from openerp.tools.translate import _ from openerp import netsvc from openerp import tools -from openerp.tools import float_compare +from openerp.tools import float_compare, DEFAULT_SERVER_DATETIME_FORMAT, server_to_local_timestamp_info import openerp.addons.decimal_precision as dp import logging _logger = logging.getLogger(__name__) @@ -651,7 +651,7 @@ class stock_picking(osv.osv): ), 'min_date': fields.function(get_min_max_date, fnct_inv=_set_minimum_date, multi="min_max_date", store=True, type='datetime', string='Scheduled Time', select=1, help="Scheduled time for the shipment to be processed"), - 'date': fields.datetime('Time', help="Creation time, usually the time of the order.", select=True, states={'done':[('readonly', True)], 'cancel':[('readonly',True)]}), + 'date': fields.datetime('Creation Date', help="Creation date, usually the time of the order.", select=True, states={'done':[('readonly', True)], 'cancel':[('readonly',True)]}), 'date_done': fields.datetime('Date of Transfer', help="Date of Completion", states={'done':[('readonly', True)], 'cancel':[('readonly',True)]}), 'max_date': fields.function(get_min_max_date, fnct_inv=_set_maximum_date, multi="min_max_date", store=True, type='datetime', string='Max. Expected Date', select=2), @@ -2360,6 +2360,10 @@ class stock_move(osv.osv): if move.picking_id: picking_ids.append(move.picking_id.id) + #add a message in chatter to say that product has been received + user_time = server_to_local_timestamp_info(fields.datetime.now(),context=context) + message = _('Product \'%s\' has been received at \'%s\'') % (move.name, user_time) + move.picking_id.message_post(body = message) if move.move_dest_id.id and (move.state != 'done'): # Downstream move should only be triggered if this move is the last pending upstream move other_upstream_move_ids = self.search(cr, uid, [('id','!=',move.id),('state','not in',['done','cancel']), @@ -2380,7 +2384,7 @@ class stock_move(osv.osv): if todo: self.action_confirm(cr, uid, todo, context=context) - self.write(cr, uid, move_ids, {'state': 'done', 'date': time.strftime('%Y-%m-%d %H:%M:%S')}, context=context) + self.write(cr, uid, move_ids, {'state': 'done', 'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}, context=context) for id in move_ids: wf_service.trg_trigger(uid, 'stock.move', id, cr) diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 83362ab5d6f..5865ad31994 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -1253,7 +1253,7 @@ - + From 55b4b2d1d066cd7ac88ed76cf54223499e769573 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Mon, 13 May 2013 17:45:46 +0200 Subject: [PATCH 2/3] [FIX]stock: add method that was added in server here to prevent user to have to update base do not forward in trunk bzr revid: csn@openerp.com-20130513154546-v5zqi6723aeiymxl --- addons/stock/stock.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index fbbee7771b1..bacea01968f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -29,7 +29,7 @@ from openerp.osv import fields, osv from openerp.tools.translate import _ from openerp import netsvc from openerp import tools -from openerp.tools import float_compare, DEFAULT_SERVER_DATETIME_FORMAT, server_to_local_timestamp_info +from openerp.tools import float_compare, DEFAULT_SERVER_DATETIME_FORMAT, server_to_local_timestamp import openerp.addons.decimal_precision as dp import logging _logger = logging.getLogger(__name__) @@ -2334,6 +2334,31 @@ class stock_move(osv.osv): 'line_id': move_lines, 'ref': move.picking_id and move.picking_id.name}) + #Should be add in server/tools/misc.py in trunk + def server_to_local_timestamp_info(self, str_date, src_format, context=None): + """ + Convert a source timestamp string into a destination timestamp string, attempting to apply the + correct offset if both the server and local timezone are recognized, or no + offset at all if they aren't. + This will return a string representing the date in the timezone of the user with the details of + which timezone is used (for example UTC+0200 (CEST)) + + @param src_date: the str value containing the timestamp in the server timezone. + @param src_format: the format to use when parsing the server timestamp. + @param context: context to be used (should contain the user local timezone) + + @return local/client formatted timestamp, expressed in the local/client timezone if possible + and add information about that timezone. + example: str_date = '2013-03-10 10:35:00' (if server timezone is UTC), if user is in UTC+0200 + return: '2013-03-10 10:35:00 UTC+0200 (CEST)' + """ + if not str_date: + return False + if not context: + context = {} + dst_format = src_format + ' UTC%z (%Z)' + return server_to_local_timestamp(str_date, src_format, dst_format, context.get('tz') or 'UTC') + def action_done(self, cr, uid, ids, context=None): """ Makes the move done and if all moves are done, it will finish the picking. @@ -2361,7 +2386,7 @@ class stock_move(osv.osv): if move.picking_id: picking_ids.append(move.picking_id.id) #add a message in chatter to say that product has been received - user_time = server_to_local_timestamp_info(fields.datetime.now(),context=context) + user_time = self.server_to_local_timestamp_info(fields.datetime.now(), DEFAULT_SERVER_DATETIME_FORMAT, context=context) message = _('Product \'%s\' has been received at \'%s\'') % (move.name, user_time) move.picking_id.message_post(body = message) if move.move_dest_id.id and (move.state != 'done'): From a4c6c62e75966f6bd58dcaab593c944c76a7fe45 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Tue, 14 May 2013 11:19:14 +0200 Subject: [PATCH 3/3] [FIX]stock: remove message from chatter, useless since information appears with tracking state and change view so that schedule date appears when product hasn't been received and date of reception appears when it has been received bzr revid: csn@openerp.com-20130514091914-rod821mkj7v4s97c --- addons/stock/stock.py | 32 +------------------------------- addons/stock/stock_view.xml | 4 ++-- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index bacea01968f..fca3d9ff073 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -29,7 +29,7 @@ from openerp.osv import fields, osv from openerp.tools.translate import _ from openerp import netsvc from openerp import tools -from openerp.tools import float_compare, DEFAULT_SERVER_DATETIME_FORMAT, server_to_local_timestamp +from openerp.tools import float_compare, DEFAULT_SERVER_DATETIME_FORMAT import openerp.addons.decimal_precision as dp import logging _logger = logging.getLogger(__name__) @@ -2334,32 +2334,6 @@ class stock_move(osv.osv): 'line_id': move_lines, 'ref': move.picking_id and move.picking_id.name}) - #Should be add in server/tools/misc.py in trunk - def server_to_local_timestamp_info(self, str_date, src_format, context=None): - """ - Convert a source timestamp string into a destination timestamp string, attempting to apply the - correct offset if both the server and local timezone are recognized, or no - offset at all if they aren't. - This will return a string representing the date in the timezone of the user with the details of - which timezone is used (for example UTC+0200 (CEST)) - - @param src_date: the str value containing the timestamp in the server timezone. - @param src_format: the format to use when parsing the server timestamp. - @param context: context to be used (should contain the user local timezone) - - @return local/client formatted timestamp, expressed in the local/client timezone if possible - and add information about that timezone. - example: str_date = '2013-03-10 10:35:00' (if server timezone is UTC), if user is in UTC+0200 - return: '2013-03-10 10:35:00 UTC+0200 (CEST)' - """ - if not str_date: - return False - if not context: - context = {} - dst_format = src_format + ' UTC%z (%Z)' - return server_to_local_timestamp(str_date, src_format, dst_format, context.get('tz') or 'UTC') - - def action_done(self, cr, uid, ids, context=None): """ Makes the move done and if all moves are done, it will finish the picking. @return: @@ -2385,10 +2359,6 @@ class stock_move(osv.osv): if move.picking_id: picking_ids.append(move.picking_id.id) - #add a message in chatter to say that product has been received - user_time = self.server_to_local_timestamp_info(fields.datetime.now(), DEFAULT_SERVER_DATETIME_FORMAT, context=context) - message = _('Product \'%s\' has been received at \'%s\'') % (move.name, user_time) - move.picking_id.message_post(body = message) if move.move_dest_id.id and (move.state != 'done'): # Downstream move should only be triggered if this move is the last pending upstream move other_upstream_move_ids = self.search(cr, uid, [('id','!=',move.id),('state','not in',['done','cancel']), diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 5865ad31994..3c3967e2e2e 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -1252,8 +1252,8 @@ - - + +