mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: improvement compute invoice sequence lines
This commit is contained in:
@@ -94,11 +94,10 @@ class FolioSaleLine(models.Model):
|
||||
)
|
||||
invoice_status = fields.Selection(
|
||||
string="Invoice Status",
|
||||
help="Invoice Status; it can be: upselling, invoiced, to invoice, no",
|
||||
help="Invoice Status; it can be: invoiced, to invoice, no",
|
||||
readonly=True,
|
||||
store=True,
|
||||
selection=[
|
||||
("upselling", "Upselling Opportunity"),
|
||||
("invoiced", "Fully Invoiced"),
|
||||
("to_invoice", "To Invoice"),
|
||||
("no", "Nothing to Invoice"),
|
||||
@@ -312,6 +311,13 @@ class FolioSaleLine(models.Model):
|
||||
default=False,
|
||||
)
|
||||
|
||||
section_id = fields.Many2one(
|
||||
string="Section",
|
||||
help="The section of the folio sale line",
|
||||
comodel_name="folio.sale.line",
|
||||
compute="_compute_section_id",
|
||||
)
|
||||
|
||||
service_order = fields.Integer(
|
||||
string="Service Id",
|
||||
help="Field to order by service id",
|
||||
@@ -379,6 +385,18 @@ class FolioSaleLine(models.Model):
|
||||
else 0
|
||||
)
|
||||
|
||||
def _compute_section_id(self):
|
||||
for record in self:
|
||||
if record.display_type == "line_section":
|
||||
record.section_id = record.id
|
||||
elif record.reservation_id:
|
||||
record.section_id = record.folio_id.sale_line_ids.filtered(
|
||||
lambda r: r.reservation_id == record.reservation_id
|
||||
and r.display_type == "line_section"
|
||||
)
|
||||
else:
|
||||
record.section_id = False
|
||||
|
||||
@api.depends("service_order")
|
||||
def _compute_date_order(self):
|
||||
for record in self:
|
||||
|
||||
@@ -474,13 +474,14 @@ class PmsFolio(models.Model):
|
||||
)
|
||||
invoice_status = fields.Selection(
|
||||
string="Invoice Status",
|
||||
help="Invoice Status; it can be: upselling, invoiced, to invoice, no",
|
||||
help="Invoice Status; it can be: invoiced, to invoice, to confirm, no",
|
||||
readonly=True,
|
||||
default="no",
|
||||
store=True,
|
||||
selection=[
|
||||
("invoiced", "Fully Invoiced"),
|
||||
("to_invoice", "To Invoice"),
|
||||
("to_confirm", "To Confirm"),
|
||||
("no", "Nothing to Invoice"),
|
||||
],
|
||||
compute="_compute_get_invoice_status",
|
||||
@@ -644,7 +645,8 @@ class PmsFolio(models.Model):
|
||||
for line in group["lines"]:
|
||||
if line.display_type == "line_section":
|
||||
current_section_vals = line._prepare_invoice_line(
|
||||
sequence=invoice_item_sequence + 1
|
||||
sequence=invoice_item_sequence
|
||||
+ folio.sale_line_ids.ids.index(line.id)
|
||||
)
|
||||
continue
|
||||
if line.display_type != "line_note" and float_is_zero(
|
||||
@@ -660,19 +662,17 @@ class PmsFolio(models.Model):
|
||||
down_payments += line
|
||||
continue
|
||||
if current_section_vals:
|
||||
invoice_item_sequence += 1
|
||||
invoice_lines_vals.append(current_section_vals)
|
||||
current_section_vals = None
|
||||
invoice_item_sequence += 1
|
||||
prepared_line = line._prepare_invoice_line(
|
||||
sequence=invoice_item_sequence,
|
||||
sequence=invoice_item_sequence
|
||||
+ folio.sale_line_ids.ids.index(line.id),
|
||||
qty=lines_to_invoice[line.id],
|
||||
)
|
||||
invoice_lines_vals.append(prepared_line)
|
||||
|
||||
# If down payments are present in SO, group them under common section
|
||||
if down_payments:
|
||||
invoice_item_sequence += 1
|
||||
down_payments_section = folio._prepare_down_payment_section_line(
|
||||
sequence=invoice_item_sequence
|
||||
)
|
||||
@@ -681,6 +681,7 @@ class PmsFolio(models.Model):
|
||||
invoice_item_sequence += 1
|
||||
invoice_down_payment_vals = down_payment._prepare_invoice_line(
|
||||
sequence=invoice_item_sequence
|
||||
+ folio.sale_line_ids.ids.index(down_payment.id)
|
||||
)
|
||||
invoice_lines_vals.append(invoice_down_payment_vals)
|
||||
|
||||
@@ -693,6 +694,7 @@ class PmsFolio(models.Model):
|
||||
]
|
||||
|
||||
invoice_vals_list.append(invoice_vals)
|
||||
invoice_item_sequence += 1000
|
||||
return invoice_vals_list
|
||||
|
||||
def _get_groups_invoice_lines(self, lines_to_invoice, partner_invoice_id=False):
|
||||
@@ -1080,21 +1082,18 @@ class PmsFolio(models.Model):
|
||||
line_invoice_status = [
|
||||
d[1] for d in line_invoice_status_all if d[0] == order.id
|
||||
]
|
||||
if order.state in ("draft") or order.force_nothing_to_invoice:
|
||||
if order.force_nothing_to_invoice:
|
||||
order.invoice_status = "no"
|
||||
elif any(
|
||||
invoice_status == "to_invoice" for invoice_status in line_invoice_status
|
||||
):
|
||||
order.invoice_status = "to_invoice"
|
||||
elif any(inv.state == "draft" for inv in order.move_ids):
|
||||
order.invoice_status = "to_confirm"
|
||||
elif line_invoice_status and all(
|
||||
invoice_status == "invoiced" for invoice_status in line_invoice_status
|
||||
):
|
||||
order.invoice_status = "invoiced"
|
||||
elif line_invoice_status and all(
|
||||
invoice_status in ("invoiced", "upselling")
|
||||
for invoice_status in line_invoice_status
|
||||
):
|
||||
order.invoice_status = "upselling"
|
||||
else:
|
||||
order.invoice_status = "no"
|
||||
|
||||
|
||||
@@ -561,7 +561,6 @@ class PmsReservation(models.Model):
|
||||
store=True,
|
||||
readonly=True,
|
||||
selection=[
|
||||
("upselling", "Upselling Opportunity"),
|
||||
("invoiced", "Fully Invoiced"),
|
||||
("to_invoice", "To Invoice"),
|
||||
("no", "Nothing to Invoice"),
|
||||
|
||||
Reference in New Issue
Block a user