~camptocamp/openerp-swiss-localization/7.0-wip-invoice-ref-transaction-id

« back to all changes in this revision

Viewing changes to l10n_ch_payment_slip/invoice.py

  • Committer: Guewen Baconnier
  • Date: 2014-01-20 13:52:47 UTC
  • Revision ID: guewen.baconnier@camptocamp.com-20140120135247-i0s76sa6k1i8qigm
add a glue module between l10n_ch_payment_slip and base_transaction_id, do not write a BVR ref when an invoice/move line has a transaction id

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    }
35
35
 
36
36
    def get_bvr_ref(self, cursor, uid, move_line_id, context=None):
37
 
        """Retrieve ESR/BVR reference from move line in order to print it"""
 
37
        """Retrieve ESR/BVR reference from move line in order to print it
 
38
 
 
39
        Returns False when no BVR reference should be generated.  No
 
40
        reference is generated when a transaction reference already
 
41
        exists for the line (likely been generated by a payment service).
 
42
        """
38
43
        res = ''
39
44
        if isinstance(move_line_id, (tuple, list)):
40
45
            assert len(move_line_id) == 1, "Only 1 ID expected"
41
46
            move_line_id = move_line_id[0]
42
47
        move_line = self.browse(cursor, uid, move_line_id, context=context)
43
48
        ## We check if the type is bvr, if not we return false
44
 
        if move_line.invoice.partner_bank_id.state != 'bvr':
 
49
        if (move_line.invoice.partner_bank_id.state != 'bvr' or
 
50
                move_line.transaction_ref):
45
51
            return ''
46
52
        ##
47
53
        if move_line.invoice.partner_bank_id.bvr_adherent_num:
96
102
                                         store=True, readonly=True)
97
103
    }
98
104
 
 
105
    def _get_bvr_ref(self, cr, uid, invoice, context=None):
 
106
        """Retrieve ESR/BVR reference form invoice in order to print it
 
107
 
 
108
        Receive a browse record so it can be overloaded without rebrowsing
 
109
        the invoice.
 
110
        """
 
111
        res = ''
 
112
        ## We check if the type is bvr, if not we return false
 
113
        if invoice.partner_bank_id.state != 'bvr':
 
114
            return ''
 
115
        ##
 
116
        if invoice.partner_bank_id.bvr_adherent_num:
 
117
            res = invoice.partner_bank_id.bvr_adherent_num
 
118
        invoice_number = ''
 
119
        if invoice.number:
 
120
            invoice_number = self._compile_get_ref.sub('', invoice.number)
 
121
        return mod10r(res + invoice_number.rjust(26 - len(res), '0'))
 
122
 
99
123
    def get_bvr_ref(self, cursor, uid, inv_id, context=None):
100
 
        """Retrieve ESR/BVR reference form invoice in order to print it"""
101
 
        res = ''
102
 
        if isinstance(inv_id, list):
 
124
        """Retrieve ESR/BVR reference form invoice in order to print it
 
125
 
 
126
        Returns False when no BVR reference should be generated.  No
 
127
        reference is generated when the invoice is not a BVR invoice.
 
128
        """
 
129
        if isinstance(inv_id, (list, tuple)):
 
130
            assert len(inv_id) == 1, "1 ID expected, got %s" % inv_id
103
131
            inv_id = inv_id[0]
104
132
        inv = self.browse(cursor, uid, inv_id, context=context)
105
 
        ## We check if the type is bvr, if not we return false
106
 
        if inv.partner_bank_id.state != 'bvr':
107
 
            return ''
108
 
        ##
109
 
        if inv.partner_bank_id.bvr_adherent_num:
110
 
            res = inv.partner_bank_id.bvr_adherent_num
111
 
        invoice_number = ''
112
 
        if inv.number:
113
 
            invoice_number = self._compile_get_ref.sub('', inv.number)
114
 
        return mod10r(res + invoice_number.rjust(26 - len(res), '0'))
 
133
        return self._get_bvr_ref(cursor, uid, inv, context=context)
115
134
 
116
135
    def _space(self, nbr, nbrspc=5):
117
136
        """Spaces * 5.
144
163
            # We keep this branch for compatibility with single BVR report.
145
164
            # This should be cleaned when porting to V8
146
165
            if move_lines:
 
166
                # An existing transaction_ref as the priority if we
 
167
                # already have a transaction ref, it has been issued by
 
168
                # a payment service, so we don't need a BVR reference.
147
169
                if len(move_lines) == 1:
148
170
                    ref = inv.get_bvr_ref()
149
171
                    move_id = inv.move_id
150
 
                    if move_id:
 
172
                    if move_id and ref:
151
173
                        cr.execute('UPDATE account_move_line SET transaction_ref=%s'
152
174
                                   '  WHERE move_id=%s',
153
175
                                   (ref, move_id.id))