[FIX] all: use newly introduced fields.date.context_today
Following the introduction of fields.date.context_today, correct the main cases where we need to use the user's timezone instead of the default UTC one. There are probably many minor cases where this may be useful, but those cases should be easy to fix now that there is a common way to fix them. lp bug: https://launchpad.net/bugs/925361 fixed bzr revid: odo@openerp.com-20120213180741-4hvd4p7wsep0fomf
This commit is contained in:
parent
e7ca80cdeb
commit
5fc1a9fc7b
|
@ -933,11 +933,12 @@ class account_fiscalyear(osv.osv):
|
|||
if de.strftime('%Y-%m-%d') > fy.date_stop:
|
||||
de = datetime.strptime(fy.date_stop, '%Y-%m-%d')
|
||||
|
||||
context_today = fields.date.context_today(cr,uid,context=context)
|
||||
period_obj.create(cr, uid, {
|
||||
'name': ds.strftime('%m/%Y'),
|
||||
'code': ds.strftime('%m/%Y'),
|
||||
'date_start': ds.strftime('%Y-%m-%d'),
|
||||
'date_stop': de.strftime('%Y-%m-%d'),
|
||||
'date_start': context_today,
|
||||
'date_stop': context_today,
|
||||
'fiscalyear_id': fy.id,
|
||||
})
|
||||
ds = ds + relativedelta(months=interval)
|
||||
|
@ -950,7 +951,7 @@ class account_fiscalyear(osv.osv):
|
|||
def finds(self, cr, uid, dt=None, exception=True, context=None):
|
||||
if context is None: context = {}
|
||||
if not dt:
|
||||
dt = time.strftime('%Y-%m-%d')
|
||||
dt = fields.date.context_today(cr,uid,context=context)
|
||||
args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
|
||||
if context.get('company_id', False):
|
||||
args.append(('company_id', '=', context['company_id']))
|
||||
|
@ -1039,7 +1040,7 @@ class account_period(osv.osv):
|
|||
def find(self, cr, uid, dt=None, context=None):
|
||||
if context is None: context = {}
|
||||
if not dt:
|
||||
dt = time.strftime('%Y-%m-%d')
|
||||
dt = fields.date.context_today(cr,uid,context=context)
|
||||
#CHECKME: shouldn't we check the state of the period?
|
||||
args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
|
||||
if context.get('company_id', False):
|
||||
|
@ -1280,7 +1281,7 @@ class account_move(osv.osv):
|
|||
'name': '/',
|
||||
'state': 'draft',
|
||||
'period_id': _get_period,
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today,
|
||||
'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
|
||||
}
|
||||
|
||||
|
@ -2269,7 +2270,7 @@ class account_model(osv.osv):
|
|||
'ref': entry['name'],
|
||||
'period_id': period_id,
|
||||
'journal_id': model.journal_id.id,
|
||||
'date': context.get('date',time.strftime('%Y-%m-%d'))
|
||||
'date': context.get('date', fields.date.context_today(cr,uid,context=context))
|
||||
})
|
||||
move_ids.append(move_id)
|
||||
for line in model.lines_id:
|
||||
|
@ -2306,7 +2307,7 @@ class account_model(osv.osv):
|
|||
'account_id': line.account_id.id,
|
||||
'move_id': move_id,
|
||||
'partner_id': line.partner_id.id,
|
||||
'date': context.get('date',time.strftime('%Y-%m-%d')),
|
||||
'date': context.get('date', fields.date.context_today(cr,uid,context=context)),
|
||||
'date_maturity': date_maturity
|
||||
})
|
||||
account_move_line_obj.create(cr, uid, val, context=ctx)
|
||||
|
@ -2359,7 +2360,7 @@ class account_subscription(osv.osv):
|
|||
'lines_id': fields.one2many('account.subscription.line', 'subscription_id', 'Subscription Lines')
|
||||
}
|
||||
_defaults = {
|
||||
'date_start': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date_start': fields.date.context_today,
|
||||
'period_type': 'month',
|
||||
'period_total': 12,
|
||||
'period_nbr': 1,
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from osv import fields
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
|
@ -41,7 +39,7 @@ class account_analytic_line(osv.osv):
|
|||
}
|
||||
|
||||
_defaults = {
|
||||
'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.analytic.line', context=c),
|
||||
}
|
||||
_order = 'date desc'
|
||||
|
|
|
@ -163,7 +163,7 @@ class account_bank_statement(osv.osv):
|
|||
|
||||
_defaults = {
|
||||
'name': "/",
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today,
|
||||
'state': 'draft',
|
||||
'journal_id': _default_journal_id,
|
||||
'period_id': _get_period,
|
||||
|
@ -483,7 +483,7 @@ class account_bank_statement_line(osv.osv):
|
|||
}
|
||||
_defaults = {
|
||||
'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'),
|
||||
'date': lambda self,cr,uid,context={}: context.get('date', time.strftime('%Y-%m-%d')),
|
||||
'date': lambda self,cr,uid,context={}: context.get('date', fields.date.context_today(cr,uid,context=context)),
|
||||
'type': 'general',
|
||||
}
|
||||
|
||||
|
|
|
@ -814,7 +814,7 @@ class account_invoice(osv.osv):
|
|||
ctx = context.copy()
|
||||
ctx.update({'lang': inv.partner_id.lang})
|
||||
if not inv.date_invoice:
|
||||
self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')}, context=ctx)
|
||||
self.write(cr, uid, [inv.id], {'date_invoice': fields.date.context_today(cr,uid,context=context)}, context=ctx)
|
||||
company_currency = inv.company_id.currency_id.id
|
||||
# create the analytical lines
|
||||
# one move line per invoice line
|
||||
|
|
|
@ -550,7 +550,7 @@ class account_move_line(osv.osv):
|
|||
'blocked': False,
|
||||
'centralisation': 'normal',
|
||||
'date': _get_date,
|
||||
'date_created': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date_created': fields.date.context_today,
|
||||
'state': 'draft',
|
||||
'currency_id': _get_currency,
|
||||
'journal_id': lambda self, cr, uid, c: c.get('journal_id', False),
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
from osv import osv, fields
|
||||
import decimal_precision as dp
|
||||
import netsvc
|
||||
|
@ -81,7 +80,7 @@ class coda_bank_account(osv.osv):
|
|||
_defaults = {
|
||||
'currency': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
|
||||
'state': 'normal',
|
||||
'coda_st_naming': lambda *a: '%(code)s/%(y)s/%(coda)s',
|
||||
'coda_st_naming': '%(code)s/%(y)s/%(coda)s',
|
||||
'active': True,
|
||||
'find_bbacom': True,
|
||||
'find_partner': True,
|
||||
|
@ -137,7 +136,7 @@ class account_coda(osv.osv):
|
|||
'company_id': fields.many2one('res.company', 'Company', readonly=True)
|
||||
}
|
||||
_defaults = {
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today,
|
||||
'user_id': lambda self,cr,uid,context: uid,
|
||||
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'account.coda', context=c),
|
||||
}
|
||||
|
|
|
@ -567,7 +567,7 @@ class account_coda_import(osv.osv_memory):
|
|||
'name' : codafilename,
|
||||
'coda_data': codafile,
|
||||
'coda_creation_date' : coda_statement['date'],
|
||||
'date': time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today(cr, uid, context=context),
|
||||
'user_id': uid,
|
||||
})
|
||||
context.update({'coda_id': coda_id})
|
||||
|
|
|
@ -102,7 +102,7 @@ class res_partner(osv.osv):
|
|||
self.write(cr, uid, [partner.id], {
|
||||
'partner_latitude': result[0],
|
||||
'partner_longitude': result[1],
|
||||
'date_localization': time.strftime('%Y-%m-%d')
|
||||
'date_localization': fields.date.context_today(cr,uid,context=context)
|
||||
}, context=context)
|
||||
return True
|
||||
res_partner()
|
||||
|
@ -128,7 +128,7 @@ class crm_lead(osv.osv):
|
|||
partners = self.pool.get('res.partner').browse(cr, uid, [partner_assigned_id], context=context)
|
||||
user_id = partners[0] and partners[0].user_id.id or False
|
||||
return {'value':
|
||||
{'date_assign': time.strftime('%Y-%m-%d'),
|
||||
{'date_assign': fields.date.context_today(cr,uid,context=context),
|
||||
'user_id' : user_id}
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ class crm_lead(osv.osv):
|
|||
if partner.user_id:
|
||||
for lead_id in ids:
|
||||
self.allocate_salesman(cr, uid, [lead_id], [partner.user_id.id], context=context)
|
||||
self.write(cr, uid, [lead.id], {'date_assign': time.strftime('%Y-%m-%d'), 'partner_assigned_id': partner_id}, context=context)
|
||||
self.write(cr, uid, [lead.id], {'date_assign': fields.date.context_today(cr,uid,context=context), 'partner_assigned_id': partner_id}, context=context)
|
||||
return res
|
||||
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ class hr_expense_expense(osv.osv):
|
|||
}
|
||||
_defaults = {
|
||||
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'hr.employee', context=c),
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today,
|
||||
'state': 'draft',
|
||||
'employee_id': _employee_get,
|
||||
'user_id': lambda cr, uid, id, c={}: id,
|
||||
|
|
|
@ -149,7 +149,7 @@ class hr_analytic_timesheet(osv.osv):
|
|||
'product_id': _getEmployeeProduct,
|
||||
'general_account_id': _getGeneralAccount,
|
||||
'journal_id': _getAnalyticJournal,
|
||||
'date': lambda self, cr, uid, ctx: ctx.get('date', time.strftime('%Y-%m-%d')),
|
||||
'date': lambda self, cr, uid, ctx: ctx.get('date', fields.date.context_today(cr,uid,context=ctx)),
|
||||
'user_id': lambda obj, cr, uid, ctx: ctx.get('user_id', uid),
|
||||
}
|
||||
def on_change_account_id(self, cr, uid, ids, account_id):
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
import time
|
||||
|
||||
class lunch_category(osv.osv):
|
||||
""" Lunch category """
|
||||
|
@ -146,7 +145,7 @@ class lunch_order(osv.osv):
|
|||
|
||||
_defaults = {
|
||||
'user_id': lambda self, cr, uid, context: uid,
|
||||
'date': lambda self, cr, uid, context: time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today,
|
||||
'state': lambda self, cr, uid, context: 'draft',
|
||||
}
|
||||
|
||||
|
|
|
@ -375,7 +375,7 @@ class mrp_bom_revision(osv.osv):
|
|||
|
||||
_defaults = {
|
||||
'author_id': lambda x, y, z, c: z,
|
||||
'date': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today,
|
||||
}
|
||||
|
||||
mrp_bom_revision()
|
||||
|
|
|
@ -151,7 +151,7 @@ class pos_return(osv.osv_memory):
|
|||
'name': 'Refund %s'%order_id.name,
|
||||
'statement_id': order_id.statement_ids[0].statement_id.id,
|
||||
'pos_statement_id': new_order,
|
||||
'date': time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today(cr, uid, context=context),
|
||||
'account_id': order_id.partner_id and order_id.partner_id.property_account_payable \
|
||||
and order_id.partner_id.property_account_payable.id or account_def.id,
|
||||
'amount': -amount,
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
##############################################################################
|
||||
|
||||
import netsvc
|
||||
import time
|
||||
|
||||
from osv import fields, osv
|
||||
|
||||
|
@ -49,7 +48,7 @@ class make_procurement(osv.osv_memory):
|
|||
}
|
||||
|
||||
_defaults = {
|
||||
'date_planned': lambda *args: time.strftime('%Y-%m-%d'),
|
||||
'date_planned': fields.date.context_today,
|
||||
'qty': lambda *args: 1.0,
|
||||
}
|
||||
|
||||
|
|
|
@ -1207,7 +1207,7 @@ class project_task_history(osv.osv):
|
|||
'user_id': fields.many2one('res.users', 'Responsible'),
|
||||
}
|
||||
_defaults = {
|
||||
'date': lambda s,c,u,ctx: time.strftime('%Y-%m-%d')
|
||||
'date': fields.date.context_today,
|
||||
}
|
||||
project_task_history()
|
||||
|
||||
|
|
|
@ -136,8 +136,8 @@ class report_account_analytic_planning(osv.osv):
|
|||
'total_free': fields.function(_get_total_free, string='Total Free'),
|
||||
}
|
||||
_defaults = {
|
||||
'date_from': lambda *a: time.strftime('%Y-%m-01'),
|
||||
'date_to': lambda *a: (datetime.now()+relativedelta(months=1, day=1, days=-1)).strftime('%Y-%m-%d'),
|
||||
'date_from': lambda self,cr,uid,ctx: fields.date.context_today(cr,uid,today=(datetime.now()+relativedelta(day=1)),context=ctx),
|
||||
'date_to': lambda self,cr,uid,ctx: fields.date.context_today(cr,uid,today=(datetime.now()+relativedelta(months=1, day=1, days=-1)),context=ctx),
|
||||
'user_id': lambda self, cr, uid, c: uid,
|
||||
'state': 'draft',
|
||||
'business_days': 20,
|
||||
|
|
|
@ -209,7 +209,7 @@ class purchase_order(osv.osv):
|
|||
'company_id': fields.many2one('res.company','Company',required=True,select=1),
|
||||
}
|
||||
_defaults = {
|
||||
'date_order': lambda *a: time.strftime('%Y-%m-%d'),
|
||||
'date_order': fields.date.context_today,
|
||||
'state': 'draft',
|
||||
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'purchase.order'),
|
||||
'shipped': 0,
|
||||
|
@ -274,7 +274,7 @@ class purchase_order(osv.osv):
|
|||
return {'value':{'partner_address_id': supplier_address['default'], 'pricelist_id': pricelist, 'fiscal_position': fiscal_position}}
|
||||
|
||||
def wkf_approve_order(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state': 'approved', 'date_approve': time.strftime('%Y-%m-%d')})
|
||||
self.write(cr, uid, ids, {'state': 'approved', 'date_approve': fields.date.context_today(cr,uid,context=context)})
|
||||
return True
|
||||
|
||||
#TODO: implement messages system
|
||||
|
@ -758,7 +758,7 @@ class purchase_order_line(osv.osv):
|
|||
|
||||
# - determine product_qty and date_planned based on seller info
|
||||
if not date_order:
|
||||
date_order = time.strftime('%Y-%m-%d')
|
||||
date_order = fields.date.context_today(cr,uid,context=context)
|
||||
|
||||
qty = qty or 1.0
|
||||
seller_delay = 0
|
||||
|
|
|
@ -269,7 +269,7 @@ class sale_order(osv.osv):
|
|||
}
|
||||
_defaults = {
|
||||
'picking_policy': 'direct',
|
||||
'date_order': lambda *a: time.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
||||
'date_order': fields.date.context_today,
|
||||
'order_policy': 'manual',
|
||||
'state': 'draft',
|
||||
'user_id': lambda obj, cr, uid, context: uid,
|
||||
|
@ -626,14 +626,14 @@ class sale_order(osv.osv):
|
|||
self.write(cr, uid, ids, {'state': 'cancel'})
|
||||
return True
|
||||
|
||||
def action_wait(self, cr, uid, ids, *args):
|
||||
def action_wait(self, cr, uid, ids, context=None):
|
||||
for o in self.browse(cr, uid, ids):
|
||||
if not o.order_line:
|
||||
raise osv.except_osv(_('Error !'),_('You cannot confirm a sale order which has no line.'))
|
||||
if (o.order_policy == 'manual'):
|
||||
self.write(cr, uid, [o.id], {'state': 'manual', 'date_confirm': time.strftime(DEFAULT_SERVER_DATE_FORMAT)})
|
||||
self.write(cr, uid, [o.id], {'state': 'manual', 'date_confirm': fields.date.context_today(cr, uid, context=context)})
|
||||
else:
|
||||
self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': time.strftime(DEFAULT_SERVER_DATE_FORMAT)})
|
||||
self.write(cr, uid, [o.id], {'state': 'progress', 'date_confirm': fields.date.context_today(cr, uid, context=context)})
|
||||
self.pool.get('sale.order.line').button_confirm(cr, uid, [x.id for x in o.order_line])
|
||||
message = _("The quotation '%s' has been converted to a sales order.") % (o.name,)
|
||||
self.log(cr, uid, o.id, message)
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
import time
|
||||
|
||||
|
||||
class crm_make_sale(osv.osv_memory):
|
||||
|
@ -98,7 +97,7 @@ class crm_make_sale(osv.osv_memory):
|
|||
'partner_invoice_id': partner_addr['invoice'],
|
||||
'partner_order_id': partner_addr['contact'],
|
||||
'partner_shipping_id': partner_addr['delivery'],
|
||||
'date_order': time.strftime('%Y-%m-%d'),
|
||||
'date_order': fields.date.context_today(cr,uid,context=context),
|
||||
'fiscal_position': fpos,
|
||||
}
|
||||
if partner.id:
|
||||
|
|
|
@ -1482,7 +1482,7 @@ class stock_production_lot_revision(osv.osv):
|
|||
|
||||
_defaults = {
|
||||
'author_id': lambda x, y, z, c: z,
|
||||
'date': time.strftime('%Y-%m-%d'),
|
||||
'date': fields.date.context_today,
|
||||
}
|
||||
|
||||
stock_production_lot_revision()
|
||||
|
|
Loading…
Reference in New Issue