mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: improvement downpayment invoice manage
This commit is contained in:
@@ -199,4 +199,11 @@ class AccountPayment(models.Model):
|
||||
for (account, _dummy), line_ids in group.items():
|
||||
if account.reconcile or account.internal_type == "liquidity":
|
||||
self.env["account.move.line"].browse(line_ids).reconcile()
|
||||
# Set folio sale lines default_invoice_to to partner downpayment invoice
|
||||
for folio in payment.folio_ids:
|
||||
for sale_line in folio.sale_line_ids.filtered(
|
||||
lambda l: not l.default_invoice_to
|
||||
):
|
||||
sale_line.default_invoice_to = move.partner_id.id
|
||||
|
||||
return move
|
||||
|
||||
@@ -1862,7 +1862,11 @@ class PmsFolio(models.Model):
|
||||
if not lines_to_invoice:
|
||||
self = self.with_context(lines_auto_add=True)
|
||||
lines_to_invoice = dict()
|
||||
for line in self.sale_line_ids:
|
||||
for line in self.sale_line_ids.filtered(
|
||||
lambda l: l.qty_to_invoice > 0
|
||||
or (l.qty_to_invoice < 0 and final)
|
||||
or l.display_type == "line_note"
|
||||
):
|
||||
if not self._context.get("autoinvoice"):
|
||||
lines_to_invoice[line.id] = (
|
||||
0 if line.display_type else line.qty_to_invoice
|
||||
@@ -1904,7 +1908,7 @@ class PmsFolio(models.Model):
|
||||
)
|
||||
invoice_date = max(
|
||||
self.env["pms.reservation"]
|
||||
.search([("sale_line_ids", "in", list(lines_to_invoice.keys()))])
|
||||
.search([("sale_line_ids", "in", lines_to_invoice.keys())])
|
||||
.mapped("checkout")
|
||||
) + datetime.timedelta(days=margin_days_autoinvoice)
|
||||
if invoice_date < datetime.date.today():
|
||||
|
||||
@@ -671,6 +671,7 @@ class PmsProperty(models.Model):
|
||||
[
|
||||
("sale_line_ids.autoinvoice_date", "=", date_reference),
|
||||
("invoice_status", "=", "to_invoice"),
|
||||
("amount_total", ">", 0),
|
||||
]
|
||||
)
|
||||
paid_folios = folios.filtered(lambda f: f.pending_amount <= 0)
|
||||
@@ -696,10 +697,23 @@ class PmsProperty(models.Model):
|
||||
lambda l: not l.autoinvoice_date
|
||||
):
|
||||
line._compute_autoinvoice_date()
|
||||
invoice = folio.with_context(autoinvoice=True)._create_invoices(
|
||||
grouped=True,
|
||||
# REVIEW: Reverse downpayment invoices if the downpayment is not included
|
||||
# in the service invoice (qty_to_invoice < 0)
|
||||
downpayment_invoices = (
|
||||
folio.sale_line_ids.filtered(
|
||||
lambda l: l.is_downpayment and l.qty_to_invoice < 0
|
||||
)
|
||||
.mapped("invoice_lines")
|
||||
.mapped("move_id")
|
||||
.filtered(lambda i: i.is_simplified_invoice)
|
||||
)
|
||||
if invoice:
|
||||
if downpayment_invoices:
|
||||
downpayment_invoices._reverse_moves(cancel=True)
|
||||
invoices = folio.with_context(autoinvoice=True)._create_invoices(
|
||||
grouped=True,
|
||||
final=True,
|
||||
)
|
||||
for invoice in invoices:
|
||||
if (
|
||||
invoice.amount_total
|
||||
> invoice.pms_property_id.max_amount_simplified_invoice
|
||||
|
||||
Reference in New Issue
Block a user