mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: change conditions folio invoice automatically
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user