Project

General

Profile

« Previous | Next » 

Revision 99a62b84

Added by Mikaël Ates almost 10 years ago

[facturation/b2] Fix b2 type1 dest org, change how b2 files are created (fixes #5802).

  • The b2 type 1 destination organism is the real destination, not the
    policyholder health center destination organism.
  • b2() does not assert when the b2 file exists and has the regenerate switch
    to indicate if the file must be kept or regenerated. The swith can be set
    for the buildall() method. Then caling buildall will now recreate missing
    files by default.

View differences:

calebasse/facturation/b2.py
181 181

  
182 182
    return invoice_lines
183 183

  
184
def b2(seq_id, hc, batches):
184
def b2(seq_id, hc, batches, regenerate=False):
185 185
    to = hc.b2_000()
186 186
    total = sum(b.total for b in batches)
187 187
    first_batch = min(b.number for b in batches)
......
204 204
    prefix = '%s-%s-%s-%s-%s.' % (seq_id, NUMERO_EMETTEUR, to, first_batch, file_id)
205 205

  
206 206
    b2_filename = os.path.join(output_dir, prefix + 'b2')
207
    assert not os.path.isfile(b2_filename), 'B2 file "%s" already exists' % b2_filename
207
    if os.path.isfile(b2_filename) and not regenerate:
208
        return None
208 209

  
209 210
    output_file = tempfile.NamedTemporaryFile(suffix='.b2tmp',
210 211
            prefix=prefix, dir=output_dir, delete=False)
......
222 223

  
223 224
    for batch in batches:
224 225
        start_1 = '1' + NUMERO_EMETTEUR + filler(6) + \
225
                batch.health_center.dest_organism[0:3] + \
226
                hc.dest_organism[0:3] + \
226 227
                ('%0.3d' % batch.number) + CATEGORIE + STATUT + MODE_TARIF + \
227 228
                NOM + 'B2' + b2date(utcnow) + ' ' + NORME[0:2] + \
228 229
                ' ' + '062007' + 'U' + filler(2+3+1+34)
......
231 232

  
232 233
        infos['batches'].append({
233 234
            'batch': batch.number,
235
            'dest': '%s' % hc.dest_organism[0:3],
234 236
            'hc': u'%s' % batch.health_center,
235 237
            'total': float(batch.total),
236 238
            'number_of_invoices': batch.number_of_invoices,
......
289 291

  
290 292
    return b2_filename
291 293

  
292
def buildall(seq_id):
294
def buildall(seq_id, regenerate=False):
293 295
    try:
294 296
        invoicing = Invoicing.objects.filter(seq_id=seq_id)[0]
295 297
    except IndexError:
296
        raise RuntimeError('Facture introuvable')
298
        raise RuntimeError('Facturation introuvable')
297 299
    batches = build_batches(invoicing)
298 300
    for hc in batches:
299 301
        for b in batches[hc]:
300
            b2_filename = b2(invoicing.seq_id, hc, [b])
302
            b2_filename = b2(invoicing.seq_id, hc, [b],
303
                    regenerate=regenerate)
304
            if b2_filename:
305
                print "%s created" % b2_filename
301 306

  
302 307

  
303 308
def sendmail_raw(mail):

Also available in: Unified diff