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
1=== modified file 'account/account_invoice.py'
2--- account/account_invoice.py 2012-10-05 12:58:20 +0000
3+++ account/account_invoice.py 2012-12-12 08:05:24 +0000
4@@ -492,7 +492,10 @@
5 res = {}
6 pt_obj = self.pool.get('account.payment.term')
7 if not date_invoice:
8- date_invoice = time.strftime('%Y-%m-%d')
9+ user_obj = self.pool.get('res.users')
10+ user = user_obj.browse(cr, uid, [uid])[0]
11+ context = {'tz': user.context_tz}
12+ date_invoice = fields.date.context_today(self,cr,uid,context=context)
13
14 pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice)
15
16@@ -824,8 +827,13 @@
17
18 ctx = context.copy()
19 ctx.update({'lang': inv.partner_id.lang})
20+ user_obj = self.pool.get('res.users');
21+ user = user_obj.browse(cr, uid, [uid])[0]
22+ user_tz = user.context_tz or 'utc'
23+ ctx['tz'] = user_tz
24 if not inv.date_invoice:
25- self.write(cr, uid, [inv.id], {'date_invoice': fields.date.context_today(self,cr,uid,context=context)}, context=ctx)
26+ self.write(cr, uid, [inv.id], {'date_invoice': fields.date.context_today(self,cr,uid,context=ctx)}, context=ctx)
27+ inv = self.browse(cr, uid, [inv.id], context=ctx)[0]
28 company_currency = inv.company_id.currency_id.id
29 # create the analytical lines
30 # one move line per invoice line
31
32=== modified file 'account/account_move_line.py'
33--- account/account_move_line.py 2012-09-06 14:35:17 +0000
34+++ account/account_move_line.py 2012-12-12 08:05:24 +0000
35@@ -520,7 +520,7 @@
36 if context is None:
37 context or {}
38 period_obj = self.pool.get('account.period')
39- dt = time.strftime('%Y-%m-%d')
40+ dt = fields.date.context_today(self, cr, uid, context=context)
41 if ('journal_id' in context) and ('period_id' in context):
42 cr.execute('SELECT date FROM account_move_line ' \
43 'WHERE journal_id = %s AND period_id = %s ' \
44@@ -647,7 +647,7 @@
45 if not partner_id:
46 return {'value':val}
47 if not date:
48- date = datetime.now().strftime('%Y-%m-%d')
49+ date = fields.date.context_today(self,cr,uid,context=context)
50 part = partner_obj.browse(cr, uid, partner_id)
51
52 if part.property_payment_term:
53@@ -933,7 +933,7 @@
54 if lines and lines[0]:
55 partner_id = lines[0].partner_id and lines[0].partner_id.id or False
56 if partner_id and context and context.get('stop_reconcile', False):
57- partner_obj.write(cr, uid, [partner_id], {'last_reconciliation_date': time.strftime('%Y-%m-%d %H:%M:%S')})
58+ partner_obj.write(cr, uid, [partner_id], {'last_reconciliation_date': fields.date.context_today(self, cr, uid, context=context)})
59 return r_id
60
61 def view_header_get(self, cr, user, view_id, view_type, context=None):
62@@ -1280,7 +1280,7 @@
63 if journal.sequence_id:
64 #name = self.pool.get('ir.sequence').next_by_id(cr, uid, journal.sequence_id.id)
65 v = {
66- 'date': vals.get('date', time.strftime('%Y-%m-%d')),
67+ 'date': vals.get('date', fields.date.context_today(self, cr, uid, context=context)),
68 'period_id': context['period_id'],
69 'journal_id': context['journal_id']
70 }
71@@ -1320,7 +1320,7 @@
72 if journal.analytic_journal_id:
73 vals['analytic_lines'] = [(0,0, {
74 'name': vals['name'],
75- 'date': vals.get('date', time.strftime('%Y-%m-%d')),
76+ 'date': vals.get('date', fields.date.context_today(self, cr, uid, context=context)),
77 'account_id': vals.get('analytic_account_id', False),
78 'unit_amount': vals.get('quantity', 1.0),
79 'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0),
80
81=== modified file 'account_voucher/account_voucher.py'
82--- account_voucher/account_voucher.py 2012-12-05 17:57:01 +0000
83+++ account_voucher/account_voucher.py 2012-12-12 08:05:24 +0000
84@@ -318,7 +318,7 @@
85 'state': 'draft',
86 'pay_now': 'pay_later',
87 'name': '',
88- 'date': lambda *a: time.strftime('%Y-%m-%d'),
89+ 'date': fields.date.context_today,
90 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
91 'tax_id': _get_tax,
92 'payment_option': 'without_writeoff',
93
94=== modified file 'stock/stock.py'
95--- stock/stock.py 2012-10-05 07:47:57 +0000
96+++ stock/stock.py 2012-12-12 08:05:24 +0000
97@@ -661,7 +661,7 @@
98 'move_type': 'direct',
99 'type': 'in',
100 'invoice_state': 'none',
101- 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
102+ 'date': fields.datetime.now,
103 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.picking', context=c)
104 }
105 _sql_constraints = [
106@@ -1690,9 +1690,9 @@
107 'priority': '1',
108 'product_qty': 1.0,
109 'scrapped' : False,
110- 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
111+ 'date': fields.datetime.now,
112 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),
113- 'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
114+ 'date_expected': fields.datetime.now,
115 }
116
117 def write(self, cr, uid, ids, vals, context=None):
118@@ -2273,7 +2273,7 @@
119 'product_id': move.product_id and move.product_id.id or False,
120 'quantity': move.product_qty,
121 'ref': move.picking_id and move.picking_id.name or False,
122- 'date': time.strftime('%Y-%m-%d'),
123+ 'date': fields.date.context_today(self, cr, uid, context=context),
124 'partner_id': partner_id,
125 'debit': reference_amount,
126 'account_id': dest_account_id,
127@@ -2283,7 +2283,7 @@
128 'product_id': move.product_id and move.product_id.id or False,
129 'quantity': move.product_qty,
130 'ref': move.picking_id and move.picking_id.name or False,
131- 'date': time.strftime('%Y-%m-%d'),
132+ 'date': fields.date.context_today(self, cr, uid, context=context),
133 'partner_id': partner_id,
134 'credit': reference_amount,
135 'account_id': src_account_id,