~vauxoo/openerp-mexico-localization/type_invoice_report_dev_luis

« back to all changes in this revision

Viewing changes to l10n_mx_invoice_datetime/invoice.py

  • Committer: moylop260
  • Date: 2011-10-29 19:41:57 UTC
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: moylop260@vauxoo.com-20111029194157-pqe6oifdnxiccsb0
[ADD] [l10n_mx_invoice_datetime] Add new module l10n_mx_invoice_datetime

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2010 moylop260 - http://moylop.blogspot.com/
 
6
#    All Rights Reserved.
 
7
#    info moylop260 (moylop260@hotmail.com)
 
8
############################################################################
 
9
#    Coded by: moylop260 (moylop260@hotmail.com)
 
10
#    Launchpad Project Manager for Publication: Nhomar Hernandez - nhomar@openerp.com.ve
 
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
 
 
28
from osv import osv
 
29
from osv import fields
 
30
import tools
 
31
from tools.translate import _
 
32
import netsvc
 
33
import time
 
34
import os
 
35
 
 
36
class account_payment_term(osv.osv):
 
37
    _inherit = "account.payment.term"
 
38
    
 
39
    def compute(self, cr, uid, id, value, date_ref=False, context={}):
 
40
        if date_ref:
 
41
            try:
 
42
                date_ref = time.strftime('%Y-%m-%d', time.strptime(date_ref, '%Y-%m-%d %H:%M:%S'))
 
43
            except:
 
44
                pass
 
45
        return super(account_payment_term, self).compute(cr, uid, id, value, date_ref, context=context)
 
46
account_payment_term()
 
47
 
 
48
class account_invoice(osv.osv):
 
49
    _inherit = 'account.invoice'
 
50
    _order = 'date_invoice asc'
 
51
    
 
52
    _columns = {
 
53
        ##Extract date_invoice from original, but add datetime
 
54
        'date_invoice': fields.datetime('Date Invoiced', states={'open':[('readonly',True)],'close':[('readonly',True)]}, help="Keep empty to use the current date"),
 
55
    }
 
56
    
 
57
    _defaults = {
 
58
        #'date_invoice': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
 
59
    }
 
60
    
 
61
    def action_move_create(self, cr, uid, ids, *args):
 
62
        for inv in self.browse(cr, uid, ids):
 
63
            if inv.move_id:
 
64
                continue
 
65
            if not inv.date_invoice:
 
66
                self.write(cr, uid, [inv.id], {'date_invoice': time.strftime('%Y-%m-%d %H:%M:%S')})
 
67
        return super(account_invoice, self).action_move_create(cr, uid, ids, *args)
 
68
account_invoice()