Chris Biersbach (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.1-opw-581667-cbi into 
lp:openobject-addons/6.1.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-581667-cbi/+merge/139396

The issue that was encounteres: In multiple places (pickings, invoices, journal 
entries, payments, etc.), date default values moved to the next day too early. 

The reason: The code to compute dates and datetimes was mostly 
timezone-oblivious. For example, time.strftime was used for generating default 
values for date fields, which is wrong, a new function was created exactly for 
this purpose.

The fix: I replaced timezone-oblivious code with its timezone-aware counterpart
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-581667-cbi/+merge/139396
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.1-opw-581667-cbi.
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py	2012-10-05 12:58:20 +0000
+++ account/account_invoice.py	2012-12-12 08:05:24 +0000
@@ -492,7 +492,10 @@
         res = {}
         pt_obj = self.pool.get('account.payment.term')
         if not date_invoice:
-            date_invoice = time.strftime('%Y-%m-%d')
+            user_obj = self.pool.get('res.users')
+            user = user_obj.browse(cr, uid, [uid])[0]
+            context = {'tz': user.context_tz}
+            date_invoice = fields.date.context_today(self,cr,uid,context=context)
 
         pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice)
 
@@ -824,8 +827,13 @@
             
             ctx = context.copy()
             ctx.update({'lang': inv.partner_id.lang})
+            user_obj = self.pool.get('res.users');
+            user = user_obj.browse(cr, uid, [uid])[0]
+            user_tz = user.context_tz or 'utc'
+            ctx['tz'] = user_tz
             if not inv.date_invoice:
-                self.write(cr, uid, [inv.id], {'date_invoice': fields.date.context_today(self,cr,uid,context=context)}, context=ctx)
+                self.write(cr, uid, [inv.id], {'date_invoice': fields.date.context_today(self,cr,uid,context=ctx)}, context=ctx)
+                inv = self.browse(cr, uid, [inv.id], context=ctx)[0]
             company_currency = inv.company_id.currency_id.id
             # create the analytical lines
             # one move line per invoice line

=== modified file 'account/account_move_line.py'
--- account/account_move_line.py	2012-09-06 14:35:17 +0000
+++ account/account_move_line.py	2012-12-12 08:05:24 +0000
@@ -520,7 +520,7 @@
         if context is None:
             context or {}
         period_obj = self.pool.get('account.period')
-        dt = time.strftime('%Y-%m-%d')
+        dt = fields.date.context_today(self, cr, uid, context=context)
         if ('journal_id' in context) and ('period_id' in context):
             cr.execute('SELECT date FROM account_move_line ' \
                     'WHERE journal_id = %s AND period_id = %s ' \
@@ -647,7 +647,7 @@
         if not partner_id:
             return {'value':val}
         if not date:
-            date = datetime.now().strftime('%Y-%m-%d')
+            date = fields.date.context_today(self,cr,uid,context=context)
         part = partner_obj.browse(cr, uid, partner_id)
 
         if part.property_payment_term:
@@ -933,7 +933,7 @@
         if lines and lines[0]:
             partner_id = lines[0].partner_id and lines[0].partner_id.id or False
             if partner_id and context and context.get('stop_reconcile', False):
-                partner_obj.write(cr, uid, [partner_id], {'last_reconciliation_date': time.strftime('%Y-%m-%d %H:%M:%S')})
+                partner_obj.write(cr, uid, [partner_id], {'last_reconciliation_date': fields.date.context_today(self, cr, uid, context=context)})
         return r_id
 
     def view_header_get(self, cr, user, view_id, view_type, context=None):
@@ -1280,7 +1280,7 @@
                 if journal.sequence_id:
                     #name = self.pool.get('ir.sequence').next_by_id(cr, uid, journal.sequence_id.id)
                     v = {
-                        'date': vals.get('date', time.strftime('%Y-%m-%d')),
+                        'date': vals.get('date', fields.date.context_today(self, cr, uid, context=context)),
                         'period_id': context['period_id'],
                         'journal_id': context['journal_id']
                     }
@@ -1320,7 +1320,7 @@
             if journal.analytic_journal_id:
                 vals['analytic_lines'] = [(0,0, {
                         'name': vals['name'],
-                        'date': vals.get('date', time.strftime('%Y-%m-%d')),
+                        'date': vals.get('date', fields.date.context_today(self, cr, uid, context=context)),
                         'account_id': vals.get('analytic_account_id', False),
                         'unit_amount': vals.get('quantity', 1.0),
                         'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0),

=== modified file 'account_voucher/account_voucher.py'
--- account_voucher/account_voucher.py	2012-12-05 17:57:01 +0000
+++ account_voucher/account_voucher.py	2012-12-12 08:05:24 +0000
@@ -318,7 +318,7 @@
         'state': 'draft',
         'pay_now': 'pay_later',
         'name': '',
-        'date': lambda *a: time.strftime('%Y-%m-%d'),
+        'date': fields.date.context_today,
         'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
         'tax_id': _get_tax,
         'payment_option': 'without_writeoff',

=== modified file 'stock/stock.py'
--- stock/stock.py	2012-10-05 07:47:57 +0000
+++ stock/stock.py	2012-12-12 08:05:24 +0000
@@ -661,7 +661,7 @@
         'move_type': 'direct',
         'type': 'in',
         'invoice_state': 'none',
-        'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
+        'date': fields.datetime.now,
         'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.picking', context=c)
     }
     _sql_constraints = [
@@ -1690,9 +1690,9 @@
         'priority': '1',
         'product_qty': 1.0,
         'scrapped' :  False,
-        'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
+        'date': fields.datetime.now,
         'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),
-        'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
+        'date_expected': fields.datetime.now,
     }
 
     def write(self, cr, uid, ids, vals, context=None):
@@ -2273,7 +2273,7 @@
                     'product_id': move.product_id and move.product_id.id or False,
                     'quantity': move.product_qty,
                     'ref': move.picking_id and move.picking_id.name or False,
-                    'date': time.strftime('%Y-%m-%d'),
+                    'date': fields.date.context_today(self, cr, uid, context=context),
                     'partner_id': partner_id,
                     'debit': reference_amount,
                     'account_id': dest_account_id,
@@ -2283,7 +2283,7 @@
                     'product_id': move.product_id and move.product_id.id or False,
                     'quantity': move.product_qty,
                     'ref': move.picking_id and move.picking_id.name or False,
-                    'date': time.strftime('%Y-%m-%d'),
+                    'date': fields.date.context_today(self, cr, uid, context=context),
                     'partner_id': partner_id,
                     'credit': reference_amount,
                     'account_id': src_account_id,

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to