Some Bills are being created and loosing their Bookings. That probably happens when a Bill create for one or more Bookings are being submitted twice.
This causes a NFE to be created twice and can't be cancelled. The NFe data is also being lost, since there is a validation on Bill model that checks if Bookings are present, but since the references actually sit at Bookings side, a Bill can loose it's Bookings without being saved, thus validations won't run.
We need to add a validation on Bookings or Bills (or even maybe a check in Bills controller) to avoid creating a new Bill for Bookings that already have a Bill.
We will also need to cleanup the database for orphaned Bills and to cancel it's NFes
Some Bills are being created and loosing their Bookings. That probably happens when a Bill create for one or more Bookings are being submitted twice.
This causes a NFE to be created twice and can't be cancelled. The NFe data is also being lost, since there is a validation on Bill model that checks if Bookings are present, but since the references actually sit at Bookings side, a Bill can loose it's Bookings without being saved, thus validations won't run.
We need to add a validation on Bookings or Bills (or even maybe a check in Bills controller) to avoid creating a new Bill for Bookings that already have a Bill.
We will also need to cleanup the database for orphaned Bills and to cancel it's NFes