~vauxoo/openerp-venezuela-localization/ovl70-fr-rev-kty

« back to all changes in this revision

Viewing changes to l10n_ve_withholding_src/model/invoice.py

  • Committer: Katherine Zaoral
  • Date: 2013-01-08 19:12:14 UTC
  • mfrom: (764.1.6 ovl70)
  • Revision ID: katherine.zaoral@vauxoo.com-20130108191214-w1yaavcxrroyz5kx
[MERGE] localization revno 770

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
class account_invoice(osv.osv):
32
32
    _inherit = 'account.invoice'
 
33
     
 
34
    def onchange_partner_id(self, cr, uid, ids, type, partner_id,\
 
35
            date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
 
36
        
 
37
        p = self.pool.get('res.partner').browse(cr, uid, partner_id)
 
38
        c = self.pool.get('res.partner').browse(cr, uid, uid)
 
39
        res = super(account_invoice,self).onchange_partner_id(cr, uid, ids, type, \
 
40
        partner_id, date_invoice,payment_term,partner_bank_id,company_id)
 
41
        
 
42
        if p.wh_src_agent and type in ('out_invoice') and not p.supplier:
 
43
            res['value']['wh_src_rate'] = p.wh_src_rate
 
44
        elif c.wh_src_agent and type in ('in_invoice') and p.supplier:
 
45
            res['value']['wh_src_rate'] = c.wh_src_rate
 
46
        else:
 
47
            res['value']['wh_src_rate'] = 0
 
48
            
 
49
        return res
33
50
    
34
51
    def _retenida(self, cr, uid, ids, name, args, context):
35
52
        res = {}
66
83
            invoice_ids = self.pool.get('account.invoice').search(cr, uid, [('move_id','in',move.keys())], context=context)
67
84
        return invoice_ids
68
85
    
 
86
    def _check_retention(self, cr, uid, ids, context=None):
 
87
        '''This method will check the retention value will be maximum 5%   
 
88
            '''
 
89
        if context is None: context = {}
 
90
        
 
91
        invoice_brw = self.browse(cr, uid,ids)
 
92
        
 
93
        ret = invoice_brw[0].wh_src_rate
 
94
    
 
95
        if ret and ret > 5:
 
96
            return False
 
97
            
 
98
        return True
 
99
    
69
100
    _columns = {
70
101
        'wh_src': fields.boolean('Social Responsibility Commitment Withheld'),
71
102
        'wh_src_rate': fields.float('SRC Wh rate', digits_compute= dp.get_precision('Withhold'), readonly=True, states={'draft':[('readonly',False)]}, help="Social Responsibility Commitment Withholding Rate"),
75
106
        'wh_src': False,
76
107
    }
77
108
 
 
109
    _constraints = [
 
110
        (_check_retention, _("Error ! Maximum retention is 5%"), []),
 
111
    ]
 
112
 
78
113
    def _get_move_lines(self, cr, uid, ids, to_wh, period_id, 
79
114
                            pay_journal_id, writeoff_acc_id, 
80
115
                            writeoff_period_id, writeoff_journal_id, date, 
84
119
                            pay_journal_id, writeoff_acc_id, 
85
120
                            writeoff_period_id, writeoff_journal_id, date, 
86
121
                            name, context=context)
87
 
        if context.get('src_wh',False):
 
122
        if context.get('wh_src',False):
88
123
            invoice = self.browse(cr, uid, ids[0])
89
124
            
90
125
            types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1}