From f9ef793fe72647e820591f0a3bc3d27034c371bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Wed, 29 Jun 2022 09:42:31 +0200 Subject: [PATCH] [IMP]pms: change conditions folio invoice automatically --- pms/models/pms_property.py | 12 ++++++++---- pms/tests/test_pms_folio_invoice.py | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index 1e72a055f..6904462b9 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -585,7 +585,7 @@ class PmsProperty(models.Model): @api.model 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( [ @@ -595,10 +595,14 @@ class PmsProperty(models.Model): ) paid_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: - # TODO: Autoinvoice unpaid agency folios? - folio.message_post(body=_("Not invoiced due to pending amounts")) - for folio in paid_folios: + # REVIEW: Change this by state flow folio control + if any([res.state != "cancel" for res in folio.reservation_ids]): + folios_to_invoice += folio + else: + folio.message_post(body=_("Not invoiced due to pending amounts")) + for folio in folios_to_invoice: try: invoice = folio.with_context(autoinvoice=True)._create_invoices( grouped=True, diff --git a/pms/tests/test_pms_folio_invoice.py b/pms/tests/test_pms_folio_invoice.py index 7826f8354..c5d509a7e 100644 --- a/pms/tests/test_pms_folio_invoice.py +++ b/pms/tests/test_pms_folio_invoice.py @@ -814,14 +814,14 @@ class TestPmsFolioInvoice(TestPms): "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 -------------------------------------- Set partner invoicing_policy to checkout, create a reservation with room, board service and normal service, run autoinvoicing method and check that not invoice was created becouse - the folio is not paid + the folio is cancel and not paid """ # ARRANGE self.partner_id.invoicing_policy = "checkout" @@ -881,6 +881,7 @@ class TestPmsFolioInvoice(TestPms): "reservation_id": self.reservation1.id, } ) + self.reservation1.action_cancel() self.property.autoinvoicing() # ASSERT