~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to invoice_datetime/tests/test_invoice_datetime.py

  • Committer: Luis Ernesto Garcia Medina
  • Date: 2014-09-02 23:17:12 UTC
  • mto: (543.413.2 alan_original_datetime)
  • mto: This revision was merged to the branch mainline in revision 896.
  • Revision ID: ernesto_gm@vauxoo.com-20140902231712-6jld8x9roxivkvow
[REF][invoice_datetime] tests are added to validate that the date stored in the invoice corresponds to the date calculated in _get_datetime_with_user_tz function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
#
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#
 
6
#    Copyright (c) 2014 Vauxoo - http://www.vauxoo.com/
 
7
#    All Rights Reserved.
 
8
#    info Vauxoo (info@vauxoo.com)
 
9
#
 
10
#    Coded by: vauxoo consultores (info@vauxoo.com)
 
11
#
 
12
#
 
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.
 
17
#
 
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.
 
22
#
 
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/>.
 
25
#
 
26
 
 
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
 
31
import mock
 
32
from openerp.addons.invoice_datetime.invoice import account_invoice
 
33
from openerp.tools import mute_logger
 
34
import pytz
 
35
import time
 
36
import datetime
 
37
 
 
38
class TestInvoiceDatetime(TransactionCase):
 
39
    def setUp(self):
 
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')
 
44
 
 
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,
 
52
                                                     '%Y-%m-%d %H:%M:%S')
 
53
        # create list with tz to apply in datetime
 
54
        tz_to_user = ['America/Caracas', 'America/Mexico_City']
 
55
        for tz in tz_to_user:
 
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,
 
59
                                                             datetime_object)
 
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, {
 
63
                                                'partner_id':1,
 
64
                                                'account_id':1,
 
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')