Merge lp:~openerp-dev/openobject-addons/6.1-opw-581667-cbi into lp:openobject-addons/6.1

Proposed by Chris Biersbach (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/6.1-opw-581667-cbi
Merge into: lp:openobject-addons/6.1
Diff against target: 135 lines (+21/-13)
4 files modified
account/account_invoice.py (+10/-2)
account/account_move_line.py (+5/-5)
account_voucher/account_voucher.py (+1/-1)
stock/stock.py (+5/-5)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.1-opw-581667-cbi
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+139396@code.launchpad.net

Description of the change

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

To post a comment you must log in.

Unmerged revisions

7086. By Chris Biersbach (OpenERP)

[FIX] More timezone fixes in account_voucher and stock

7085. By Chris Biersbach (OpenERP)

[FIX] This fixes various timezone issues in picking, invoice and journal entry

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
492 res = {}492 res = {}
493 pt_obj = self.pool.get('account.payment.term')493 pt_obj = self.pool.get('account.payment.term')
494 if not date_invoice:494 if not date_invoice:
495 date_invoice = time.strftime('%Y-%m-%d')495 user_obj = self.pool.get('res.users')
496 user = user_obj.browse(cr, uid, [uid])[0]
497 context = {'tz': user.context_tz}
498 date_invoice = fields.date.context_today(self,cr,uid,context=context)
496499
497 pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice)500 pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice)
498501
@@ -824,8 +827,13 @@
824 827
825 ctx = context.copy()828 ctx = context.copy()
826 ctx.update({'lang': inv.partner_id.lang})829 ctx.update({'lang': inv.partner_id.lang})
830 user_obj = self.pool.get('res.users');
831 user = user_obj.browse(cr, uid, [uid])[0]
832 user_tz = user.context_tz or 'utc'
833 ctx['tz'] = user_tz
827 if not inv.date_invoice:834 if not inv.date_invoice:
828 self.write(cr, uid, [inv.id], {'date_invoice': fields.date.context_today(self,cr,uid,context=context)}, context=ctx)835 self.write(cr, uid, [inv.id], {'date_invoice': fields.date.context_today(self,cr,uid,context=ctx)}, context=ctx)
836 inv = self.browse(cr, uid, [inv.id], context=ctx)[0]
829 company_currency = inv.company_id.currency_id.id837 company_currency = inv.company_id.currency_id.id
830 # create the analytical lines838 # create the analytical lines
831 # one move line per invoice line839 # one move line per invoice line
832840
=== 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 @@
520 if context is None:520 if context is None:
521 context or {}521 context or {}
522 period_obj = self.pool.get('account.period')522 period_obj = self.pool.get('account.period')
523 dt = time.strftime('%Y-%m-%d')523 dt = fields.date.context_today(self, cr, uid, context=context)
524 if ('journal_id' in context) and ('period_id' in context):524 if ('journal_id' in context) and ('period_id' in context):
525 cr.execute('SELECT date FROM account_move_line ' \525 cr.execute('SELECT date FROM account_move_line ' \
526 'WHERE journal_id = %s AND period_id = %s ' \526 'WHERE journal_id = %s AND period_id = %s ' \
@@ -647,7 +647,7 @@
647 if not partner_id:647 if not partner_id:
648 return {'value':val}648 return {'value':val}
649 if not date:649 if not date:
650 date = datetime.now().strftime('%Y-%m-%d')650 date = fields.date.context_today(self,cr,uid,context=context)
651 part = partner_obj.browse(cr, uid, partner_id)651 part = partner_obj.browse(cr, uid, partner_id)
652652
653 if part.property_payment_term:653 if part.property_payment_term:
@@ -933,7 +933,7 @@
933 if lines and lines[0]:933 if lines and lines[0]:
934 partner_id = lines[0].partner_id and lines[0].partner_id.id or False934 partner_id = lines[0].partner_id and lines[0].partner_id.id or False
935 if partner_id and context and context.get('stop_reconcile', False):935 if partner_id and context and context.get('stop_reconcile', False):
936 partner_obj.write(cr, uid, [partner_id], {'last_reconciliation_date': time.strftime('%Y-%m-%d %H:%M:%S')})936 partner_obj.write(cr, uid, [partner_id], {'last_reconciliation_date': fields.date.context_today(self, cr, uid, context=context)})
937 return r_id937 return r_id
938938
939 def view_header_get(self, cr, user, view_id, view_type, context=None):939 def view_header_get(self, cr, user, view_id, view_type, context=None):
@@ -1280,7 +1280,7 @@
1280 if journal.sequence_id:1280 if journal.sequence_id:
1281 #name = self.pool.get('ir.sequence').next_by_id(cr, uid, journal.sequence_id.id)1281 #name = self.pool.get('ir.sequence').next_by_id(cr, uid, journal.sequence_id.id)
1282 v = {1282 v = {
1283 'date': vals.get('date', time.strftime('%Y-%m-%d')),1283 'date': vals.get('date', fields.date.context_today(self, cr, uid, context=context)),
1284 'period_id': context['period_id'],1284 'period_id': context['period_id'],
1285 'journal_id': context['journal_id']1285 'journal_id': context['journal_id']
1286 }1286 }
@@ -1320,7 +1320,7 @@
1320 if journal.analytic_journal_id:1320 if journal.analytic_journal_id:
1321 vals['analytic_lines'] = [(0,0, {1321 vals['analytic_lines'] = [(0,0, {
1322 'name': vals['name'],1322 'name': vals['name'],
1323 'date': vals.get('date', time.strftime('%Y-%m-%d')),1323 'date': vals.get('date', fields.date.context_today(self, cr, uid, context=context)),
1324 'account_id': vals.get('analytic_account_id', False),1324 'account_id': vals.get('analytic_account_id', False),
1325 'unit_amount': vals.get('quantity', 1.0),1325 'unit_amount': vals.get('quantity', 1.0),
1326 'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0),1326 'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0),
13271327
=== 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 @@
318 'state': 'draft',318 'state': 'draft',
319 'pay_now': 'pay_later',319 'pay_now': 'pay_later',
320 'name': '',320 'name': '',
321 'date': lambda *a: time.strftime('%Y-%m-%d'),321 'date': fields.date.context_today,
322 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),322 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
323 'tax_id': _get_tax,323 'tax_id': _get_tax,
324 'payment_option': 'without_writeoff',324 'payment_option': 'without_writeoff',
325325
=== 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 @@
661 'move_type': 'direct',661 'move_type': 'direct',
662 'type': 'in',662 'type': 'in',
663 'invoice_state': 'none',663 'invoice_state': 'none',
664 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),664 'date': fields.datetime.now,
665 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.picking', context=c)665 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.picking', context=c)
666 }666 }
667 _sql_constraints = [667 _sql_constraints = [
@@ -1690,9 +1690,9 @@
1690 'priority': '1',1690 'priority': '1',
1691 'product_qty': 1.0,1691 'product_qty': 1.0,
1692 'scrapped' : False,1692 'scrapped' : False,
1693 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),1693 'date': fields.datetime.now,
1694 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),1694 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),
1695 'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),1695 'date_expected': fields.datetime.now,
1696 }1696 }
16971697
1698 def write(self, cr, uid, ids, vals, context=None):1698 def write(self, cr, uid, ids, vals, context=None):
@@ -2273,7 +2273,7 @@
2273 'product_id': move.product_id and move.product_id.id or False,2273 'product_id': move.product_id and move.product_id.id or False,
2274 'quantity': move.product_qty,2274 'quantity': move.product_qty,
2275 'ref': move.picking_id and move.picking_id.name or False,2275 'ref': move.picking_id and move.picking_id.name or False,
2276 'date': time.strftime('%Y-%m-%d'),2276 'date': fields.date.context_today(self, cr, uid, context=context),
2277 'partner_id': partner_id,2277 'partner_id': partner_id,
2278 'debit': reference_amount,2278 'debit': reference_amount,
2279 'account_id': dest_account_id,2279 'account_id': dest_account_id,
@@ -2283,7 +2283,7 @@
2283 'product_id': move.product_id and move.product_id.id or False,2283 'product_id': move.product_id and move.product_id.id or False,
2284 'quantity': move.product_qty,2284 'quantity': move.product_qty,
2285 'ref': move.picking_id and move.picking_id.name or False,2285 'ref': move.picking_id and move.picking_id.name or False,
2286 'date': time.strftime('%Y-%m-%d'),2286 'date': fields.date.context_today(self, cr, uid, context=context),
2287 'partner_id': partner_id,2287 'partner_id': partner_id,
2288 'credit': reference_amount,2288 'credit': reference_amount,
2289 'account_id': src_account_id,2289 'account_id': src_account_id,