~openerp-venezuela/openerp-venezuela-localization/trunk

« back to all changes in this revision

Viewing changes to l10n_ve_withholding_islr/model/islr_wh_doc.py

[MERGE] OVL is getting Documented

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
class islr_wh_doc(osv.osv):
38
38
 
39
39
    def _get_type(self, cr, uid, context=None):
40
 
        '''
41
 
        returns type of invoice or returns in_invoice
42
 
        '''
 
40
        """ Return type of invoice or returns in_invoice
 
41
        """
43
42
        if context is None:
44
43
            context = {}
45
44
        type = context.get('type', 'in_invoice')
46
45
        return type
47
46
 
48
47
    def _get_journal(self, cr, uid, context=None):
49
 
        '''
50
 
        returns a islr journal depending on the type of bill
51
 
        '''
 
48
        """ Return a islr journal depending on the type of bill
 
49
        """
52
50
        if context is None:
53
51
            context = {}
54
52
        journal_obj = self.pool.get('account.journal')
64
62
            return False
65
63
 
66
64
    def _get_currency(self, cr, uid, context):
67
 
        '''
68
 
        returns the currency of the current company
69
 
        '''
 
65
        """ Return the currency of the current company
 
66
        """
70
67
        user = self.pool.get('res.users').browse(cr, uid, [uid])[0]
71
68
        if user.company_id:
72
69
            return user.company_id.currency_id.id
74
71
            return self.pool.get('res.currency').search(cr, uid, [('rate', '=', 1.0)])[0]
75
72
 
76
73
    def _get_amount_total(self, cr, uid, ids, name, args, context=None):
77
 
        '''
78
 
        returns the cumulative amount of each line
79
 
        '''
 
74
        """ Return the cumulative amount of each line
 
75
        """
80
76
        res = {}
81
77
        for rete in self.browse(cr, uid, ids, context):
82
78
            res[rete.id] = 0.0
138
134
    }
139
135
 
140
136
    def check_income_wh(self, cr, uid, ids, context=None):
141
 
        '''
142
 
        checks invoices to be retained and have
 
137
        """ Check invoices to be retained and have
143
138
        their fair share of taxes.
144
 
        '''
 
139
        """
145
140
        context = context or {}
146
141
        ids = isinstance(ids, (int, long)) and [ids] or ids
147
142
        obj = self.browse(cr, uid, ids[0], context=context)
167
162
        return True
168
163
 
169
164
    def check_auto_wh(self, cr, uid, ids, context=None):
170
 
        '''
171
 
        tells us if the process already
172
 
        checked and everything was fine.
173
 
        '''
 
165
        """ Tell us if the process already checked and everything was fine.
 
166
        """
174
167
        context = context or {}
175
168
        ids = isinstance(ids, (int, long)) and [ids] or ids
176
169
        obj = self.browse(cr, uid, ids[0], context=context)
177
170
        return obj.automatic_income_wh or False
178
171
 
179
172
    def check_auto_wh_by_type(self, cr, uid, ids, context=None):
180
 
        '''
181
 
        tells us if the process already
182
 
        checked and everything was fine in case of a
183
 
        in_invoice or in_refund
184
 
        '''
 
173
        """ Tell us if the process already checked and everything was 
 
174
        fine in case of a in_invoice or in_refund
 
175
        """
185
176
        context = context or {}
186
177
        ids = isinstance(ids, (int, long)) and [ids] or ids
187
178
        brw = self.browse(cr, uid, ids[0], context=context)
190
181
        return brw.automatic_income_wh or False
191
182
 
192
183
    def compute_amount_wh(self, cr, uid, ids, context=None):
193
 
        '''
194
 
        calculates the total withholding each invoice
 
184
        """ Calculate the total withholding each invoice
195
185
        associated with this document
196
 
        '''
 
186
        """
197
187
        context = context or {}
198
188
        ids = isinstance(ids, (int, long)) and [ids] or ids
199
189
        iwdi_obj = self.pool.get('islr.wh.doc.invoices')
217
207
        return False
218
208
 
219
209
    def action_done(self, cr, uid, ids, context=None):
220
 
        '''
221
 
        calls the functions in charge of
222
 
        preparing the document to pass the state done
223
 
        '''
 
210
        """ Call the functions in charge of preparing the document 
 
211
        to pass the state done
 
212
        """
224
213
        context = context or {}
225
214
        ids = isinstance(ids, (int, long)) and [ids] or ids
226
215
        self.action_number(cr, uid, ids, context=context)
234
223
        return True
235
224
 
236
225
    def action_cancel_process(self, cr, uid, ids, context=None):
237
 
        '''
238
 
        deletes all withholding lines and reverses
239
 
        the process of islr
240
 
        '''
 
226
        """ Delete all withholding lines and reverses the process of islr
 
227
        """
241
228
        if not context:
242
229
            context = {}
243
230
        line_obj = self.pool.get('islr.wh.doc.line')
274
261
        return True
275
262
 
276
263
    def retencion_seq_get(self, cr, uid, context=None):
277
 
        '''
278
 
        determinates the next sequence for
279
 
        islr withhold and returns.
280
 
        '''
 
264
        """ Determinate the next sequence for islr withhold and returns.
 
265
        """
281
266
        pool_seq = self.pool.get('ir.sequence')
282
267
        cr.execute(
283
268
            "select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where code='islr.wh.doc' and active=True")
290
275
        return False
291
276
 
292
277
    def onchange_partner_id(self, cr, uid, ids, type, partner_id, context=None):
293
 
        '''
294
 
        unlink all taxes whean change the partner in the
295
 
        document
296
 
        '''
 
278
        """ Unlink all taxes whean change the partner in the document.
 
279
        @param type: invoice type
 
280
        @param partner_id: partner id was changed
 
281
        """
297
282
        context = context or {}
298
283
        acc_id = False
299
284
        inv_ids = []
350
335
            'invoice_ids': res_wh_lines}}
351
336
 
352
337
    def create(self, cr, uid, vals, context=None, check=True):
353
 
        '''
354
 
        When you create a new document, this function
355
 
        is responsible for generating the sequence
356
 
        code for the field
357
 
        '''
 
338
        """ When you create a new document, this function is responsible 
 
339
        for generating the sequence code for the field
 
340
        """
358
341
        if not context:
359
342
            context = {}
360
343
        code = self.pool.get('ir.sequence').get(cr, uid, 'islr.wh.doc')
362
345
        return super(islr_wh_doc, self).create(cr, uid, vals, context)
363
346
 
364
347
    def action_confirm(self, cr, uid, ids, context=None):
365
 
        '''
366
 
        is responsible for checking if the provider
367
 
        allows retention is automatically verified and checked
368
 
        '''
 
348
        """ This checking if the provider allows retention is 
 
349
        automatically verified and checked
 
350
        """
369
351
        context = context or {}
370
352
        ids = isinstance(ids, (int, long)) and [ids] or ids
371
353
        check_auto_wh = self.browse(cr, uid, ids[0],
374
356
                                            'automatic_income_wh': check_auto_wh}, context=context)
375
357
 
376
358
    def action_number(self, cr, uid, ids, context=None):
377
 
        '''
378
 
        Is responsible for generating a number for
379
 
        the document if it does not have one
380
 
        '''
 
359
        """ Is responsible for generating a number for the document 
 
360
        if it does not have one
 
361
        """
381
362
        context = context or {}
382
363
        obj_ret = self.browse(cr, uid, ids)[0]
383
364
        cr.execute('SELECT id, number '
393
374
        return True
394
375
 
395
376
    def action_cancel(self, cr, uid, ids, context={}):
396
 
        '''
397
 
        The operation is canceled and not allows automatic retention
398
 
        '''
 
377
        """ The operation is canceled and not allows automatic retention
 
378
        """
399
379
        #~ if self.browse(cr,uid,ids)[0].type=='in_invoice':
400
380
            #~ return True
401
381
        self.pool.get('islr.wh.doc').write(
406
386
        return True
407
387
 
408
388
    def cancel_move(self, cr, uid, ids, *args):
409
 
        '''
410
 
        Retention cancel documents
411
 
        '''
 
389
        """ Retention cancel documents
 
390
        """
412
391
        context = {}
413
392
        ret_brw = self.browse(cr, uid, ids)
414
393
        account_move_obj = self.pool.get('account.move')
426
405
        return True
427
406
 
428
407
    def action_cancel_draft(self, cr, uid, ids, *args):
429
 
        '''
430
 
        Back to draft status
431
 
        '''
 
408
        """ Back to draft status
 
409
        """
432
410
        self.write(cr, uid, ids, {'state': 'draft'})
433
411
        return True
434
412
 
435
413
    def action_move_create(self, cr, uid, ids, context=None):
436
 
        '''
437
 
        build account moves related to withholding invoice
438
 
        '''
 
414
        """ Build account moves related to withholding invoice
 
415
        """
439
416
        wh_doc_obj = self.pool.get('islr.wh.doc.line')
440
417
        context = context or {}
441
418
        ids = isinstance(ids, (int, long)) and [ids] or ids
503
480
        return True
504
481
 
505
482
    def wh_and_reconcile(self, cr, uid, ids, invoice_id, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''):
506
 
 
 
483
        """ retain, reconcile and create corresponding journal items
 
484
        @param invoice_id: invoice to retain and reconcile
 
485
        @param pay_amount: amount payable on the invoice
 
486
        @param pay_account_id: payment account
 
487
        @param period_id: period for the journal items
 
488
        @param pay_journal_id: payment journal
 
489
        @param writeoff_acc_id: account for reconciliation
 
490
        @param writeoff_period_id: period for reconciliation
 
491
        @param writeoff_journal_id: journal for reconciliation
 
492
        @param name: withholding voucher name
 
493
        """
507
494
        inv_obj = self.pool.get('account.invoice')
508
495
        ret = self.browse(cr, uid, ids)[0]
509
496
        if context is None:
592
579
    }
593
580
 
594
581
    def copy(self, cr, uid, id, default=None, context=None):
 
582
        """ Initialized id by duplicating
 
583
        """
595
584
        if default is None:
596
585
            default = {}
597
586
        default = default.copy()
607
596
    _description = 'Document and Invoice Withheld Income'
608
597
 
609
598
    def _amount_all(self, cr, uid, ids, fieldname, args, context=None):
610
 
        '''
611
 
 
612
 
        '''
 
599
        """ Return all amount relating to the invoices lines
 
600
        """
613
601
        res = {}
614
602
        for ret_line in self.browse(cr, uid, ids, context):
615
603
            res[ret_line.id] = {
640
628
    _rec_rame = 'invoice_id'
641
629
 
642
630
    def _get_concepts(self, cr, uid, ids, context=None):
643
 
        '''
644
 
        Gets a list of withholdable concepts (concept_id) from the invoice lines
645
 
        '''
 
631
        """ Get a list of withholdable concepts (concept_id) from the invoice lines
 
632
        """
646
633
        context = context or {}
647
634
        ids = isinstance(ids, (int, long)) and [ids] or ids
648
635
        inv_obj = self.pool.get('account.invoice')
654
641
        return list(concept_set)
655
642
 
656
643
    def _withholdable_invoices(self, cr, uid, ids, context=None):
657
 
        '''Given a list of invoices return only those
658
 
        where there are withholdable concepts'''
 
644
        """ Given a list of invoices return only those
 
645
        where there are withholdable concepts
 
646
        """
659
647
        context = context or {}
660
648
        ids = isinstance(ids, (int, long)) and [ids] or ids
661
649
        res_ids = []
666
654
        return res_ids
667
655
 
668
656
    def _get_wh(self, cr, uid, ids, concept_id, context=None):
669
 
        '''
670
 
        Returns a dictionary containing all the values of the retention of an invoice line.
671
 
        '''
 
657
        """ Return a dictionary containing all the values of the retention of an invoice line.
 
658
        @param concept_id: Withholding reason
 
659
        """
672
660
        # TODO: Change the signature of this method
673
661
        # This record already has the concept_id built-in
674
662
        context = context or {}
735
723
        return True
736
724
 
737
725
    def load_taxes(self, cr, uid, ids, context=None):
738
 
        '''
739
 
        load taxes to the current invoice,
 
726
        """ Load taxes to the current invoice,
740
727
        and if already loaded, it recalculates and load.
741
 
        '''
 
728
        """
742
729
        context = context or {}
743
730
        ids = isinstance(ids, (int, long)) and [ids] or ids
744
731
        ixwl_obj = self.pool.get('islr.xml.wh.line')
824
811
        return True
825
812
 
826
813
    def _get_partners(self, cr, uid, invoice):
827
 
        '''
828
 
        Se obtiene: el id del vendedor, el id del comprador de la factura y el campo booleano que determina si el comprador es agente de retencion.
829
 
        '''
 
814
        """ Se obtiene: el id del vendedor, el id del comprador de la 
 
815
        factura y el campo booleano que determina si el comprador es 
 
816
        agente de retencion.
 
817
        """
830
818
        if invoice.type == 'in_invoice' or invoice.type == 'in_refund':
831
819
            vendor = invoice.partner_id
832
820
            buyer = invoice.company_id.partner_id
837
825
        return (vendor, buyer, buyer.islr_withholding_agent)
838
826
 
839
827
    def _get_residence(self, cr, uid, vendor, buyer):
840
 
        '''
841
 
        Se determina si la direccion fiscal del comprador es la misma que la del vendedor, con el fin de luego obtener la tasa asociada.
842
 
        Retorna True si es una persona domiciliada o residente. Retorna False si es, no Residente o No Domicialiado.
843
 
        '''
 
828
        """ Se determina si la direccion fiscal del comprador es la misma 
 
829
        que la del vendedor, con el fin de luego obtener la tasa asociada.
 
830
        Retorna True si es una persona domiciliada o residente. Retorna 
 
831
        False si es, no Residente o No Domicialiado.
 
832
        """
844
833
        vendor_address = self._get_country_fiscal(cr, uid, vendor)
845
834
        buyer_address = self._get_country_fiscal(cr, uid, buyer)
846
835
        if vendor_address and buyer_address:
851
840
        return False
852
841
 
853
842
    def _get_nature(self, cr, uid, partner_id):
854
 
        '''
855
 
        Se obtiene la naturaleza del vendedor a partir del RIF, retorna True si es persona de tipo natural, y False si es juridica.
856
 
        '''
 
843
        """ Se obtiene la naturaleza del vendedor a partir del RIF, retorna 
 
844
        True si es persona de tipo natural, y False si es juridica.
 
845
        """
857
846
        if not partner_id.vat:
858
847
            raise osv.except_osv(_('Invalid action !'), _(
859
848
                "Impossible income withholding, because the partner '%s' has not vat associated!") % (partner_id.name))
865
854
                return False
866
855
 
867
856
    def _get_rate(self, cr, uid, concept_id, residence, nature, context):
868
 
        '''
869
 
        Se obtiene la tasa del concepto de retencion, siempre y cuando exista uno asociado a las especificaciones:
870
 
            La naturaleza del vendedor coincida con una tasa.
871
 
            La residencia del vendedor coindica con una tasa.
872
 
        '''
 
857
        """ Se obtiene la tasa del concepto de retencion, siempre y 
 
858
        cuando exista uno asociado a las especificaciones:
 
859
        La naturaleza del vendedor coincida con una tasa.
 
860
        La residencia del vendedor coindica con una tasa.
 
861
        """
873
862
        ut_obj = self.pool.get('l10n.ut')
874
863
        rate_brw_lst = self.pool.get(
875
864
            'islr.wh.concept').browse(cr, uid, concept_id).rate_ids
884
873
        return ()
885
874
 
886
875
    def _get_country_fiscal(self, cr, uid, partner_id, context=None):
887
 
        '''
888
 
        Get the country of the partner
889
 
        '''
 
876
        """ Get the country of the partner
 
877
        @param partner_id: partner id whom consult your country
 
878
        """
890
879
        # TODO: THIS METHOD SHOULD BE IMPROVED
891
880
        # DUE TO OPENER HAS CHANGED THE WAY PARTNER
892
881
        # ARE USED FOR ACCOUNT_MOVE
898
887
            return partner_id.country_id.id
899
888
 
900
889
    def _get_xml_lines(self, cr, uid, ail_brw, context=None):
 
890
        """ Extract information from the document to generate xml lines
 
891
        @param ail_brw: invoice of the document
 
892
        """
901
893
        context = context or {}
902
894
        vendor, buyer, wh_agent = self._get_partners(
903
895
            cr, uid, ail_brw.invoice_id)
958
950
    _description = 'Lines of Document Income Withholding'
959
951
 
960
952
    def _retention_rate(self, cr, uid, ids, name, args, context=None):
 
953
        """ Return the retention rate of each line
 
954
        """
961
955
        res = {}
962
956
        for ret_line in self.browse(cr, uid, ids, context=context):
963
957
            if ret_line.invoice_id: