Revision 3d7a840a
Added by Thomas Noël almost 12 years ago
calebasse/facturation/models.py | ||
---|---|---|
266 | 266 |
len_acts_paused = 0 |
267 | 267 |
len_patient_with_lost_acts_missing_policy = 0 |
268 | 268 |
len_acts_losts_missing_policy = 0 |
269 |
batches = {} |
|
270 |
last_batch = {} |
|
269 | 271 |
for patient in patients: |
270 | 272 |
dic = {} |
271 | 273 |
if patient in invoices.keys(): |
... | ... | |
306 | 308 |
ppa=ppa, |
307 | 309 |
amount=amount, |
308 | 310 |
**invoice_kwargs) |
309 |
in_o.batch = Invoice.objects.new_batch_number( |
|
310 |
health_center=in_o.health_center, |
|
311 |
invoicing=self) |
|
312 | 311 |
in_o.save() |
313 | 312 |
for act, hc in acts: |
314 | 313 |
act.is_billed = True |
315 | 314 |
act.healthcare = hc |
316 | 315 |
act.save() |
317 | 316 |
in_o.acts.add(act) |
317 |
|
|
318 |
# calcule le numero de lot pour cette facture |
|
319 |
hc = in_o.health_center |
|
320 |
hc_dest = hc.hc_invoice or hc |
|
321 |
dest = hc_dest.large_regime.code + ' ' + hc_dest.dest_organism |
|
322 |
if dest not in batches: |
|
323 |
batches[dest] = {} |
|
324 |
if hc not in batches[dest]: |
|
325 |
nb1 = Invoice.objects.new_batch_number(health_center=hc_dest, invoicing=self) |
|
326 |
nb2 = Invoice.objects.new_batch_number(health_center=hc, invoicing=self) |
|
327 |
nb = max(nb1, nb2, last_batch.get(dest,0) + 1) |
|
328 |
last_batch[dest] = nb |
|
329 |
batches[dest][hc] = [{ 'batch': nb, 'size': 2, 'invoices': [], }] |
|
330 |
# pas plus de 950 lignes par lot (le fichier B2 final ne doit |
|
331 |
# pas depasser 999 lignes au total) : |
|
332 |
b = batches[dest][hc].pop() |
|
333 |
b2_size = in_o.acts.count() + 2 |
|
334 |
if (b['size'] + b2_size) > 950: |
|
335 |
batches[dest][hc].append(b) |
|
336 |
nb = last_batch.get(dest, 0) + 1 |
|
337 |
last_batch[dest] = nb |
|
338 |
b = {'batch': nb, 'size': 2, 'invoices': []} |
|
339 |
b['invoices'].append(in_o) |
|
340 |
b['size'] += b2_size |
|
341 |
batches[dest][hc].append(b) |
|
342 |
|
|
343 |
in_o.batch = b['batch'] |
|
344 |
in_o.save() |
|
345 |
|
|
318 | 346 |
pass |
319 | 347 |
if patient in acts_losts.keys(): |
320 | 348 |
# TODO: More details about healthcare |
... | ... | |
698 | 726 |
max_bn = agg['batch__max'] |
699 | 727 |
if max_bn is None: |
700 | 728 |
max_bn = PREVIOUS_MAX_BATCH_NUMBERS.get(health_center.b2_000(), 0) |
729 |
else: |
|
730 |
max_bn = max(max_bn, PREVIOUS_MAX_BATCH_NUMBERS.get(health_center.b2_000(), 0)) |
|
701 | 731 |
return max_bn + 1 |
702 | 732 |
|
703 | 733 |
|
Also available in: Unified diff
new invoice.batch logic (fix #2525)
warning: execute this to init healthcenters hc_invoice
(redirections like in transmissions.csv from Faure)
----
from calebasse.ressources.models import HealthCenter
def redirect(from_, to):
hc_from=HealthCenter.objects.get(pk=from_)
hc_to=HealthCenter.objects.get(pk=to)
print hc_from.b2_000(), hc_from,
print "\t>", hc_to.b2_000(), hc_to
hc_from.hc_invoice=hc_to
hc_from.save()
redirect(454, 163)
redirect(944, 940)
redirect(980, 940)
redirect(928, 940)
redirect(979, 940)
redirect(988, 940)
redirect(1512, 1511)
-----