[IMP]pms: change conditions folio invoice automatically

This commit is contained in:
Darío Lodeiros
2022-06-29 09:42:31 +02:00
parent 0239a2237d
commit f9ef793fe7
2 changed files with 11 additions and 6 deletions

View File

@@ -585,7 +585,7 @@ class PmsProperty(models.Model):
@api.model @api.model
def autoinvoicing(self): def autoinvoicing(self):
""" """
This method is used to autoinvoicing the folios This method is used to invoicing automatically the folios
""" """
folios = self.env["pms.folio"].search( folios = self.env["pms.folio"].search(
[ [
@@ -595,10 +595,14 @@ class PmsProperty(models.Model):
) )
paid_folios = folios.filtered(lambda f: f.pending_amount <= 0) paid_folios = folios.filtered(lambda f: f.pending_amount <= 0)
unpaid_folios = folios.filtered(lambda f: f.pending_amount > 0) unpaid_folios = folios.filtered(lambda f: f.pending_amount > 0)
folios_to_invoice = paid_folios
for folio in unpaid_folios: for folio in unpaid_folios:
# TODO: Autoinvoice unpaid agency folios? # REVIEW: Change this by state flow folio control
folio.message_post(body=_("Not invoiced due to pending amounts")) if any([res.state != "cancel" for res in folio.reservation_ids]):
for folio in paid_folios: folios_to_invoice += folio
else:
folio.message_post(body=_("Not invoiced due to pending amounts"))
for folio in folios_to_invoice:
try: try:
invoice = folio.with_context(autoinvoice=True)._create_invoices( invoice = folio.with_context(autoinvoice=True)._create_invoices(
grouped=True, grouped=True,

View File

@@ -814,14 +814,14 @@ class TestPmsFolioInvoice(TestPms):
"Billed services and overnights invoicing wrong compute", "Billed services and overnights invoicing wrong compute",
) )
def test_not_autoinvoice_unpaid_folio_partner_policy(self): def test_not_autoinvoice_unpaid_cancel_folio_partner_policy(self):
""" """
Test create and invoice the cron by partner preconfig automation Test create and invoice the cron by partner preconfig automation
-------------------------------------- --------------------------------------
Set partner invoicing_policy to checkout, create a reservation Set partner invoicing_policy to checkout, create a reservation
with room, board service and normal service, run autoinvoicing with room, board service and normal service, run autoinvoicing
method and check that not invoice was created becouse method and check that not invoice was created becouse
the folio is not paid the folio is cancel and not paid
""" """
# ARRANGE # ARRANGE
self.partner_id.invoicing_policy = "checkout" self.partner_id.invoicing_policy = "checkout"
@@ -881,6 +881,7 @@ class TestPmsFolioInvoice(TestPms):
"reservation_id": self.reservation1.id, "reservation_id": self.reservation1.id,
} }
) )
self.reservation1.action_cancel()
self.property.autoinvoicing() self.property.autoinvoicing()
# ASSERT # ASSERT