Revision e2e4192d
Added by Mikaël Ates almost 12 years ago
calebasse/facturation/models.py | ||
---|---|---|
386 | 386 |
try: |
387 | 387 |
patient = PatientRecord.objects.get(id=invoice.patient_id) |
388 | 388 |
except: |
389 |
patient = PatientRecord(last_name=patient_last_name, first_name=patient_first_name)
|
|
389 |
patient = PatientRecord(last_name=invoice.patient_last_name, first_name=invoice.patient_first_name)
|
|
390 | 390 |
patients[invoice.patient_id] = patient |
391 | 391 |
len_patients = len_patients + 1 |
392 | 392 |
patients_stats[patient] = {} |
... | ... | |
439 | 439 |
len_patient_hors_pause = len_patient_hors_pause + 1 |
440 | 440 |
len_acts_hors_pause = len_acts_hors_pause + len(acts) |
441 | 441 |
if commit: |
442 |
policy_holder = patient.policyholder |
|
443 |
try: |
|
444 |
address = unicode(policy_holder.addresses.filter(place_of_life=True)[0]) |
|
445 |
except: |
|
446 |
try: |
|
447 |
address = unicode(policy_holder.addresses.all()[0]) |
|
448 |
except: |
|
449 |
address = u'' |
|
450 |
invoice_kwargs = dict( |
|
451 |
patient_id=patient.id, |
|
452 |
patient_last_name=patient.last_name, |
|
453 |
patient_first_name=patient.first_name, |
|
454 |
patient_social_security_id=patient.social_security_id or '', |
|
455 |
patient_birthdate=patient.birthdate, |
|
456 |
patient_twinning_rank=patient.twinning_rank, |
|
457 |
patient_healthcenter=patient.health_center, |
|
458 |
patient_other_health_center=patient.other_health_center or '', |
|
459 |
patient_entry_date=patient.entry_date, |
|
460 |
patient_exit_date=patient.exit_date, |
|
461 |
policy_holder_id=policy_holder.id, |
|
462 |
policy_holder_last_name=policy_holder.last_name, |
|
463 |
policy_holder_first_name=policy_holder.first_name, |
|
464 |
policy_holder_social_security_id=policy_holder.social_security_id or '', |
|
465 |
policy_holder_other_health_center=policy_holder.other_health_center or '', |
|
466 |
policy_holder_healthcenter=policy_holder.health_center, |
|
467 |
policy_holder_address=address) |
|
468 |
if policy_holder.management_code: |
|
469 |
management_code = policy_holder.management_code |
|
470 |
invoice_kwargs['policy_holder_management_code'] = management_code.code |
|
471 |
invoice_kwargs['policy_holder_management_code_name'] = management_code.name |
|
472 |
invoice = Invoice( |
|
473 |
invoicing=self, |
|
474 |
ppa=0, amount=0, |
|
475 |
**invoice_kwargs) |
|
476 |
invoice.save() |
|
442 | 477 |
for act in acts: |
443 |
self.acts.add(act) |
|
478 |
act.is_billed = True |
|
479 |
act.save() |
|
480 |
invoice.acts.add(act) |
|
444 | 481 |
if patient in acts_pause.keys(): |
445 | 482 |
dic['acts_paused'] = acts_pause[patient] |
446 | 483 |
len_patient_acts_paused = len_patient_acts_paused + 1 |
... | ... | |
460 | 497 |
len_acts_paused = 0 |
461 | 498 |
days_not_locked = [] |
462 | 499 |
patients_missing_policy = [] |
463 |
for act in self.acts.all(): |
|
464 |
if act.patient in patients_stats.keys(): |
|
465 |
patients_stats[act.patient]['accepted'].append(act) |
|
466 |
len_acts_hors_pause = len_acts_hors_pause + 1 |
|
467 |
else: |
|
468 |
len_patient_hors_pause = len_patient_hors_pause + 1 |
|
469 |
len_acts_hors_pause = len_acts_hors_pause + 1 |
|
470 |
patients_stats[act.patient] = {} |
|
471 |
patients_stats[act.patient]['accepted'] = [act] |
|
500 |
invoices = self.invoice_set.all() |
|
501 |
for invoice in invoices: |
|
502 |
len_patient_hors_pause = len_patient_hors_pause + 1 |
|
503 |
len_acts_hors_pause = len_acts_hors_pause + len(invoice.acts.all()) |
|
504 |
patient = None |
|
505 |
try: |
|
506 |
patient = PatientRecord.objects.get(id=invoice.patient_id) |
|
507 |
except: |
|
508 |
patient = PatientRecord(last_name=invoice.patient_last_name, first_name=invoice.patient_first_name) |
|
509 |
patients_stats[patient] = {} |
|
510 |
patients_stats[patient]['accepted'] = invoice.acts.all() |
|
472 | 511 |
patients_stats = sorted(patients_stats.items(), key=lambda patient: (patient[0].last_name, patient[0].first_name)) |
473 | 512 |
return (len_patient_pause, len_patient_hors_pause, |
474 | 513 |
len_acts_pause, len_acts_hors_pause, patients_stats, |
... | ... | |
497 | 536 |
patients_missing_notif = [] |
498 | 537 |
for patient in patients: |
499 | 538 |
dic = {} |
539 |
acts_to_commit = [] |
|
500 | 540 |
if patient in acts_accepted.keys(): |
501 | 541 |
acts = acts_accepted[patient] |
542 |
acts_to_commit.extend(acts) |
|
502 | 543 |
dic['accepted'] = acts |
503 | 544 |
if patient.pause: |
504 | 545 |
len_patient_pause = len_patient_pause + 1 |
... | ... | |
506 | 547 |
else: |
507 | 548 |
len_patient_hors_pause = len_patient_hors_pause + 1 |
508 | 549 |
len_acts_hors_pause = len_acts_hors_pause + len(acts) |
509 |
if commit: |
|
510 |
for act in acts: |
|
511 |
self.acts.add(act) |
|
512 | 550 |
if patient in acts_missing_valid_notification.keys(): |
513 | 551 |
patients_missing_notif.append(patient) |
514 | 552 |
acts = acts_missing_valid_notification[patient] |
553 |
acts_to_commit.extend(acts) |
|
515 | 554 |
dic['missings'] = acts |
516 | 555 |
len_patient_missing_notif = len_patient_missing_notif + 1 |
517 | 556 |
len_acts_missing_notif = len_acts_missing_notif + len(acts) |
518 |
if not 'accepted' in dic:
|
|
519 |
if patient.pause:
|
|
557 |
if patient.pause:
|
|
558 |
if not 'accepted' in dic:
|
|
520 | 559 |
len_patient_pause = len_patient_pause + 1 |
521 |
len_acts_pause = len_acts_pause + len(acts) |
|
522 |
else: |
|
560 |
len_acts_pause = len_acts_pause + len(acts) |
|
561 |
else: |
|
562 |
if not 'accepted' in dic: |
|
523 | 563 |
len_patient_hors_pause = len_patient_hors_pause + 1 |
524 |
len_acts_hors_pause = len_acts_hors_pause + len(acts) |
|
525 |
if commit: |
|
526 |
for act in acts: |
|
527 |
self.acts.add(act) |
|
564 |
len_acts_hors_pause = len_acts_hors_pause + len(acts) |
|
565 |
if commit and acts_to_commit: |
|
566 |
policy_holder = patient.policyholder |
|
567 |
try: |
|
568 |
address = unicode(policy_holder.addresses.filter(place_of_life=True)[0]) |
|
569 |
except: |
|
570 |
try: |
|
571 |
address = unicode(policy_holder.addresses.all()[0]) |
|
572 |
except: |
|
573 |
address = u'' |
|
574 |
invoice_kwargs = dict( |
|
575 |
patient_id=patient.id, |
|
576 |
patient_last_name=patient.last_name, |
|
577 |
patient_first_name=patient.first_name, |
|
578 |
patient_social_security_id=patient.social_security_id or '', |
|
579 |
patient_birthdate=patient.birthdate, |
|
580 |
patient_twinning_rank=patient.twinning_rank, |
|
581 |
patient_healthcenter=patient.health_center, |
|
582 |
patient_other_health_center=patient.other_health_center or '', |
|
583 |
patient_entry_date=patient.entry_date, |
|
584 |
patient_exit_date=patient.exit_date, |
|
585 |
policy_holder_id=policy_holder.id, |
|
586 |
policy_holder_last_name=policy_holder.last_name, |
|
587 |
policy_holder_first_name=policy_holder.first_name, |
|
588 |
policy_holder_social_security_id=policy_holder.social_security_id or '', |
|
589 |
policy_holder_other_health_center=policy_holder.other_health_center or '', |
|
590 |
policy_holder_healthcenter=policy_holder.health_center, |
|
591 |
policy_holder_address=address) |
|
592 |
if policy_holder.management_code: |
|
593 |
management_code = policy_holder.management_code |
|
594 |
invoice_kwargs['policy_holder_management_code'] = management_code.code |
|
595 |
invoice_kwargs['policy_holder_management_code_name'] = management_code.name |
|
596 |
invoice = Invoice( |
|
597 |
invoicing=self, |
|
598 |
ppa=0, amount=0, |
|
599 |
**invoice_kwargs) |
|
600 |
invoice.save() |
|
601 |
for act in acts_to_commit: |
|
602 |
act.is_billed = True |
|
603 |
act.save() |
|
604 |
invoice.acts.add(act) |
|
528 | 605 |
if patient in acts_pause.keys(): |
529 | 606 |
dic['acts_paused'] = acts_pause[patient] |
530 | 607 |
len_patient_acts_paused = len_patient_acts_paused + 1 |
531 | 608 |
len_acts_paused = len_acts_paused + len(acts_pause[patient]) |
532 | 609 |
patients_stats.append((patient, dic)) |
533 | 610 |
patients_stats = sorted(patients_stats, key=lambda patient: (patient[0].last_name, patient[0].first_name)) |
534 |
len_acts_hors_pause = len_acts_hors_pause + len_acts_missing_notif |
|
535 | 611 |
if commit: |
536 | 612 |
self.status = Invoicing.STATUS.validated |
537 | 613 |
self.save() |
... | ... | |
548 | 624 |
days_not_locked = [] |
549 | 625 |
patients_missing_policy = [] |
550 | 626 |
patients_missing_notif = [] |
551 |
for act in self.acts.all(): |
|
552 |
if act.patient in patients_stats.keys(): |
|
553 |
patients_stats[act.patient]['accepted'].append(act) |
|
554 |
len_acts_hors_pause = len_acts_hors_pause + 1 |
|
555 |
else: |
|
556 |
len_patient_hors_pause = len_patient_hors_pause + 1 |
|
557 |
len_acts_hors_pause = len_acts_hors_pause + 1 |
|
558 |
patients_stats[act.patient] = {} |
|
559 |
patients_stats[act.patient]['accepted'] = [act] |
|
627 |
invoices = self.invoice_set.all() |
|
628 |
for invoice in invoices: |
|
629 |
len_patient_hors_pause = len_patient_hors_pause + 1 |
|
630 |
len_acts_hors_pause = len_acts_hors_pause + len(invoice.acts.all()) |
|
631 |
patient = None |
|
632 |
try: |
|
633 |
patient = PatientRecord.objects.get(id=invoice.patient_id) |
|
634 |
except: |
|
635 |
patient = PatientRecord(last_name=invoice.patient_last_name, first_name=invoice.patient_first_name) |
|
636 |
patients_stats[patient] = {} |
|
637 |
patients_stats[patient]['accepted'] = invoice.acts.all() |
|
560 | 638 |
patients_stats = sorted(patients_stats.items(), key=lambda patient: (patient[0].last_name, patient[0].first_name)) |
561 | 639 |
return (len_patient_pause, len_patient_hors_pause, |
562 | 640 |
len_acts_pause, len_acts_hors_pause, |
... | ... | |
791 | 869 |
default='', blank=True) |
792 | 870 |
policy_holder_address = models.CharField(max_length=128, |
793 | 871 |
verbose_name=u'Adresse de l\'assuré', default='', blank=True) |
872 |
policy_holder_management_code = models.CharField(max_length=10, |
|
873 |
verbose_name=u'Code de gestion', default='', blank=True) |
|
874 |
policy_holder_management_code_name = models.CharField(max_length=256, |
|
875 |
verbose_name=u'Libellé du code de gestion', default='', blank=True) |
|
794 | 876 |
|
795 | 877 |
created = models.DateTimeField(u'Création', auto_now_add=True) |
796 | 878 |
invoicing = models.ForeignKey('facturation.Invoicing', |
Also available in: Unified diff
facturation: add new fields to Invoice and build invoicing for not CMPP services.