2
# -*- encoding: utf-8 -*-
4
# Module Writen to OpenERP, Open Source Management Solution
6
# Copyright (c) 2014 Vauxoo - http://www.vauxoo.com/
8
# info Vauxoo (info@vauxoo.com)
10
# Coded by: vauxoo consultores (info@vauxoo.com)
13
# This program is free software: you can redistribute it and/or modify
14
# it under the terms of the GNU Affero General Public License as
15
# published by the Free Software Foundation, either version 3 of the
16
# License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU Affero General Public License for more details.
23
# You should have received a copy of the GNU Affero General Public License
24
# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
from openerp.tests.common import TransactionCase
28
from openerp.exceptions import AccessError
29
from openerp.osv.orm import except_orm
30
from openerp import SUPERUSER_ID
32
from openerp.addons.invoice_datetime.invoice import account_invoice
33
from openerp.tools import mute_logger
38
class TestInvoiceDatetime(TransactionCase):
40
super(TestInvoiceDatetime, self).setUp()
41
self.user = self.registry('res.users')
42
self.data = self.registry('ir.model.data')
43
self.invoice = self.registry('account.invoice')
45
@mute_logger('openerp.addons.base.ir.ir_model', 'openerp.osv.orm')
46
def test_get_datetime(self):
47
cr, uid = self.cr, self.uid
48
# get datetime of server in string
49
dt_server = time.strftime('%Y-%m-%d %H:%M:%S')
50
# I generate object of type datetime to send at function _get_datetime_with_user_tz
51
datetime_object = datetime.datetime.strptime(dt_server,
53
# create list with tz to apply in datetime
54
tz_to_user = ['America/Caracas', 'America/Mexico_City']
56
self.user.write(cr, uid, uid, {'tz': tz}) #Assign tz to user
57
#call the function _get_datetime_with_user_tz to get the date with tz applied
58
datetime_tz = self.invoice._get_datetime_with_user_tz(cr, uid,
60
print datetime_tz, 'Datetime with tz: %s applied'%tz
61
# Create an invoice with last tz of cycle America/Mexico_City
62
res_id = self.invoice.create(cr, uid, {
65
'invoice_datetime': dt_server})
66
dt_res = self.invoice.read(cr, uid, res_id, []).get('date_invoice_tz')
67
# compare date calculated with function vs date of invoice record .
68
self.assertEquals(datetime_tz,
69
dt_res, 'Date calculated and date of invoice are not equals')