~openbig/bigconsulting/addons

« back to all changes in this revision

Viewing changes to account_payment_discount_extension/account_payment_discount.py

  • Committer: thomas-dreiling
  • Date: 2010-10-08 10:09:57 UTC
  • Revision ID: thomas-dreiling-20101008100957-vm4abrqpfdsxqtdq
- clean-ups in account_payment_discount_extension
- translations for account_payment_discount_extension

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
class account_invoice(osv.osv):
36
36
    _inherit='account.invoice'
37
37
    _columns={
38
 
        'next_payment_date': fields.date('Next Payment Date', states={'open':[('readonly',True)],'close':[('readonly',True)]},),
 
38
        'next_payment_date': fields.date('Next Payment Date', states={'open': [('readonly', True)], 'close': [('readonly', True)]},),
39
39
    }
40
40
    
41
41
    def action_date_assign(self, cr, uid, ids, *args):
42
 
        data = super(account_invoice,self).action_date_assign(cr, uid, ids, *args)
 
42
        data = super(account_invoice, self).action_date_assign(cr, uid, ids, *args)
43
43
        for inv in self.browse(cr, uid, ids):
44
44
            if inv.payment_term.id:
45
45
                payment_data = self.pool.get('account.payment.term').browse(cr, uid, inv.payment_term.id).cash_discount_ids
46
46
                if payment_data:
47
47
                    delay = payment_data[0].delay
48
48
                    if inv.date_invoice:
49
 
                        date_invoice =inv.date_invoice
 
49
                        date_invoice = inv.date_invoice
50
50
                    else:
51
51
                        date_invoice = time.strftime('%Y-%m-%d')
52
 
                    self.write(cr, uid, [inv.id], {'next_payment_date':(DateTime.strptime(date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=delay)).strftime('%Y-%m-%d')})
 
52
                    self.write(cr, uid, [inv.id], {'next_payment_date': (DateTime.strptime(date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days = delay)).strftime('%Y-%m-%d')})
53
53
        return data
54
54
        
55
55
    def _next_date(self, cr, uid, ids, context=None):
56
56
        payment_term_obj = self.pool.get('account.payment.term')
57
57
        current_date = time.strftime('%Y-%m-%d')
58
 
        ids = self.search(cr, uid, [('state','=','open')])
 
58
        ids = self.search(cr, uid, [('state', '=', 'open')])
59
59
        for id in ids:
60
60
            invoice_data = self.browse(cr, uid, id, context=context)
61
61
            next_pay_date = invoice_data.next_payment_date
64
64
            if next_pay_date: 
65
65
                if next_pay_date < current_date:
66
66
                    for dis_line in payment_data.cash_discount_ids:
67
 
                        discount_date  =  (DateTime.strptime(invoice_data.date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=dis_line.delay)).strftime('%Y-%m-%d')
 
67
                        discount_date = (DateTime.strptime(invoice_data.date_invoice, '%Y-%m-%d') + DateTime.RelativeDateTime(days=dis_line.delay)).strftime('%Y-%m-%d')
68
68
                        if discount_date > current_date:
69
 
                            self.write(cr, uid, [id], {'next_payment_date':discount_date})
 
69
                            self.write(cr, uid, [id], {'next_payment_date': discount_date})
70
70
                            break
71
71
        return True
72
72
    
77
77
        if default is None:
78
78
            default = {}
79
79
        default = default.copy()
80
 
        default.update({'next_payment_date':False})
 
80
        default.update({'next_payment_date': False})
81
81
        return super(account_invoice, self).copy(cr, uid, id, default, context)
82
82
 
83
83
account_invoice()
97
97
    _columns = {
98
98
        'property_customer_cash_discount_account': fields.property(
99
99
            'account.account',
100
 
            type='many2one',
101
 
            relation='account.account',
102
 
            string="Customer Cash Discount Account",
103
 
            method=True,
104
 
            view_load=True,
105
 
            required=True),
 
100
            type = 'many2one',
 
101
            relation = 'account.account',
 
102
            string = "Customer Cash Discount Account",
 
103
            method = True,
 
104
            view_load = True,
 
105
            required = True),
106
106
        'property_supplier_cash_discount_account': fields.property(
107
107
            'account.account',
108
 
            type='many2one',
109
 
            relation='account.account',
110
 
            string="Supplier Cash Discount Account",
111
 
            method=True,
112
 
            view_load=True,
113
 
            required=True),
 
108
            type = 'many2one',
 
109
            relation = 'account.account',
 
110
            string = "Supplier Cash Discount Account",
 
111
            method = True,
 
112
            view_load = True,
 
113
            required = True),
114
114
      }
115
115
res_partner()