mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: draft invoice use invoice_date_due
This commit is contained in:
@@ -426,7 +426,7 @@ class FolioSaleLine(models.Model):
|
||||
)
|
||||
def _compute_autoinvoice_date(self):
|
||||
self.autoinvoice_date = False
|
||||
for record in self.filtered(lambda r: r.invoice_status == "to_invoice"):
|
||||
for record in self:
|
||||
record.autoinvoice_date = record._get_to_invoice_date()
|
||||
|
||||
def _get_to_invoice_date(self):
|
||||
@@ -438,6 +438,8 @@ class FolioSaleLine(models.Model):
|
||||
last_checkout = self.service_id.reservation_id.checkout
|
||||
else:
|
||||
last_checkout = self.folio_id.last_checkout
|
||||
if not last_checkout:
|
||||
return False
|
||||
invoicing_policy = (
|
||||
self.pms_property_id.default_invoicing_policy
|
||||
if not partner or partner.invoicing_policy == "property"
|
||||
@@ -459,11 +461,11 @@ class FolioSaleLine(models.Model):
|
||||
else partner.invoicing_month_day
|
||||
)
|
||||
if last_checkout.day <= month_day:
|
||||
self.autoinvoice_date = last_checkout.replace(day=month_day)
|
||||
return last_checkout.replace(day=month_day)
|
||||
else:
|
||||
self.autoinvoice_date = (
|
||||
last_checkout + relativedelta.relativedelta(months=1)
|
||||
).replace(day=month_day)
|
||||
return (last_checkout + relativedelta.relativedelta(months=1)).replace(
|
||||
day=month_day
|
||||
)
|
||||
|
||||
@api.depends("date_order")
|
||||
def _compute_reservation_order(self):
|
||||
|
||||
@@ -1927,8 +1927,13 @@ class PmsFolio(models.Model):
|
||||
month_day,
|
||||
)
|
||||
if invoice_date:
|
||||
key_field = (
|
||||
"invoice_date"
|
||||
if invoice_date == fields.Date.today()
|
||||
else "invoice_date_due"
|
||||
)
|
||||
for vals in invoice_vals_list:
|
||||
vals["invoice_date"] = invoice_date
|
||||
vals[key_field] = invoice_date
|
||||
|
||||
# 3) Create invoices.
|
||||
|
||||
|
||||
@@ -18,10 +18,9 @@ from odoo.addons.base.models.res_partner import _tz_get
|
||||
|
||||
|
||||
def get_default_logo():
|
||||
with open(modules.get_module_resource('pms',
|
||||
'static/img',
|
||||
'property_logo.png'),
|
||||
'rb') as f:
|
||||
with open(
|
||||
modules.get_module_resource("pms", "static/img", "property_logo.png"), "rb"
|
||||
) as f:
|
||||
return base64.b64encode(f.read())
|
||||
|
||||
|
||||
@@ -683,7 +682,11 @@ class PmsProperty(models.Model):
|
||||
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"))
|
||||
folio.message_post(
|
||||
body=_(
|
||||
"Not invoiced due to pending amounts and cancelled reservations"
|
||||
)
|
||||
)
|
||||
for folio in folios_to_invoice:
|
||||
try:
|
||||
invoice = folio.with_context(autoinvoice=True)._create_invoices(
|
||||
@@ -696,7 +699,7 @@ class PmsProperty(models.Model):
|
||||
draft_invoices_to_post = self.env["account.move"].search(
|
||||
[
|
||||
("state", "=", "draft"),
|
||||
("invoice_date", "=", date_reference),
|
||||
("invoice_date_due", "=", date_reference),
|
||||
("folio_ids", "!=", False),
|
||||
]
|
||||
)
|
||||
@@ -704,9 +707,7 @@ class PmsProperty(models.Model):
|
||||
try:
|
||||
invoice.action_post()
|
||||
except Exception as e:
|
||||
invoice.message_post(
|
||||
body=_("Error in autoinvoicing invoice: " + str(e))
|
||||
)
|
||||
invoice.message_post(body=_("Error in autovalidate invoice: " + str(e)))
|
||||
return True
|
||||
|
||||
@api.constrains("journal_normal_invoice_id")
|
||||
|
||||
Reference in New Issue
Block a user