Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]14.0 remove default invoice to from folio sale lines #281

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions pms/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,4 @@ def _create_downpayment_invoice(self, payment, partner_id):
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
29 changes: 3 additions & 26 deletions pms/models/folio_sale_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,6 @@ class FolioSaleLine(models.Model):
store=True,
compute="_compute_date_order",
)
default_invoice_to = fields.Many2one(
string="Invoice to",
help="""Indicates the contact to which this line will be
billed by default, if it is not established,
a guest or the generic contact will be used instead""",
comodel_name="res.partner",
ondelete="restrict",
index=True,
)
autoinvoice_date = fields.Date(
string="Autoinvoice Date",
compute="_compute_autoinvoice_date",
Expand Down Expand Up @@ -424,7 +415,6 @@ def _compute_date_order(self):
record.date_order = 0

@api.depends(
"default_invoice_to",
"invoice_status",
"folio_id.last_checkout",
"reservation_id.checkout",
Expand All @@ -436,7 +426,6 @@ def _compute_autoinvoice_date(self):

def _get_to_invoice_date(self):
self.ensure_one()
partner = self.default_invoice_to
if self.reservation_id:
last_checkout = self.reservation_id.checkout
elif self.service_id and self.service_id.reservation_id:
Expand All @@ -445,26 +434,14 @@ def _get_to_invoice_date(self):
last_checkout = self.folio_id.last_checkout
if not last_checkout:
return False
invoicing_policy = (
self.folio_id.pms_property_id.default_invoicing_policy
if not partner or partner.invoicing_policy == "property"
else partner.invoicing_policy
)
invoicing_policy = self.folio_id.pms_property_id.default_invoicing_policy
if invoicing_policy == "manual":
return False
if invoicing_policy == "checkout":
margin_days = (
self.folio_id.pms_property_id.margin_days_autoinvoice
if not partner or partner.invoicing_policy == "property"
else partner.margin_days_autoinvoice
)
margin_days = self.folio_id.pms_property_id.margin_days_autoinvoice
return last_checkout + timedelta(days=margin_days)
if invoicing_policy == "month_day":
month_day = (
self.folio_id.pms_property_id.invoicing_month_day
if not partner or partner.invoicing_policy == "property"
else partner.invoicing_month_day
)
month_day = self.folio_id.pms_property_id.invoicing_month_day
if last_checkout.day <= month_day:
return last_checkout.replace(day=month_day)
else:
Expand Down
51 changes: 10 additions & 41 deletions pms/models/pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,6 @@ def get_invoice_vals_list(
for down_payment in down_payments:
# If the down payment is not for the current partner, skip it
# it will be managed manually or by the automatic invoice cron
if down_payment.default_invoice_to.id != group["partner_id"]:
continue
invoice_item_sequence += 1
invoice_down_payment_vals = down_payment._prepare_invoice_line(
sequence=invoice_item_sequence
Expand Down Expand Up @@ -722,25 +720,12 @@ def _get_groups_invoice_lines(self, lines_to_invoice, partner_invoice_id=False):
}
)
else:
partners = lines_to_invoice.mapped("default_invoice_to")
for partner in partners:
groups_invoice_lines.append(
{
"partner_id": partner.id,
"lines": lines_to_invoice.filtered(
lambda l: l.default_invoice_to == partner
),
}
)
if any(not line.default_invoice_to for line in lines_to_invoice):
groups_invoice_lines.append(
{
"partner_id": self.env.ref("pms.various_pms_partner").id,
"lines": lines_to_invoice.filtered(
lambda l: not l.default_invoice_to
),
}
)
groups_invoice_lines.append(
{
"partner_id": self.env.ref("pms.various_pms_partner").id,
"lines": lines_to_invoice,
}
)
return groups_invoice_lines

def _get_tax_amount_by_group(self):
Expand Down Expand Up @@ -802,7 +787,6 @@ def _compute_number_of_services(self):
"reservation_ids",
"service_ids",
"service_ids.reservation_id",
"service_ids.default_invoice_to",
"service_ids.service_line_ids.price_day_total",
"service_ids.service_line_ids.discount",
"service_ids.service_line_ids.cancel_discount",
Expand All @@ -812,7 +796,6 @@ def _compute_number_of_services(self):
"reservation_ids.reservation_line_ids.price",
"reservation_ids.reservation_line_ids.discount",
"reservation_ids.reservation_line_ids.cancel_discount",
"reservation_ids.reservation_line_ids.default_invoice_to",
"reservation_ids.tax_ids",
"reservation_ids.state",
)
Expand Down Expand Up @@ -2433,8 +2416,8 @@ def _get_reservation_sale_lines(self, folio, reservation, sequence):
("reservation_id", "=", reservation.id),
("cancel_discount", "<", 100),
],
["price", "discount", "cancel_discount", "default_invoice_to"],
["price", "discount", "cancel_discount", "default_invoice_to"],
["price", "discount", "cancel_discount"],
["price", "discount", "cancel_discount"],
lazy=False,
)
current_sale_line_ids = reservation.sale_line_ids.filtered(
Expand All @@ -2449,16 +2432,12 @@ def _get_reservation_sale_lines(self, folio, reservation, sequence):
final_discount = self.concat_discounts(
item["discount"], item["cancel_discount"]
)
partner_invoice = lines_to.mapped("default_invoice_to")
if current_sale_line_ids and index <= (len(current_sale_line_ids) - 1):
current = {
"price_unit": item["price"],
"discount": final_discount,
"reservation_line_ids": [(6, 0, lines_to.ids)],
"sequence": sequence,
"default_invoice_to": partner_invoice[0].id
if partner_invoice
else current_sale_line_ids[index].default_invoice_to,
}
sale_reservation_vals.append(
(1, current_sale_line_ids[index].id, current)
Expand All @@ -2473,9 +2452,6 @@ def _get_reservation_sale_lines(self, folio, reservation, sequence):
"tax_ids": [(6, 0, reservation.tax_ids.ids)],
"reservation_line_ids": [(6, 0, lines_to.ids)],
"sequence": sequence,
"default_invoice_to": partner_invoice[0].id
if partner_invoice
else False,
}
sale_reservation_vals.append((0, 0, new))
folio_sale_lines_to_remove = []
Expand All @@ -2498,8 +2474,8 @@ def _get_service_sale_lines(self, folio, reservation, sequence):
("service_id", "=", service.id),
("cancel_discount", "<", 100),
],
["price_unit", "discount", "cancel_discount", "default_invoice_to"],
["price_unit", "discount", "cancel_discount", "default_invoice_to"],
["price_unit", "discount", "cancel_discount"],
["price_unit", "discount", "cancel_discount"],
lazy=False,
)
current_sale_service_ids = reservation.sale_line_ids.filtered(
Expand All @@ -2513,7 +2489,6 @@ def _get_service_sale_lines(self, folio, reservation, sequence):
final_discount = self.concat_discounts(
item["discount"], item["cancel_discount"]
)
partner_invoice = lines_to.mapped("default_invoice_to")
if current_sale_service_ids and index <= (
len(current_sale_service_ids) - 1
):
Expand All @@ -2522,9 +2497,6 @@ def _get_service_sale_lines(self, folio, reservation, sequence):
"discount": final_discount,
"service_line_ids": [(6, 0, lines_to.ids)],
"sequence": sequence,
"default_invoice_to": partner_invoice[0].id
if partner_invoice
else current_sale_service_ids[index].default_invoice_to,
}
sale_service_vals.append(
(1, current_sale_service_ids[index].id, current)
Expand All @@ -2540,9 +2512,6 @@ def _get_service_sale_lines(self, folio, reservation, sequence):
"product_id": service.product_id.id,
"tax_ids": [(6, 0, service.tax_ids.ids)],
"sequence": sequence,
"default_invoice_to": partner_invoice[0].id
if partner_invoice
else False,
}
sale_service_vals.append((0, 0, new))
sequence = sequence + 1
Expand Down
6 changes: 1 addition & 5 deletions pms/models/pms_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,7 @@ def autoinvoice_folio(self, folio):
)
folio.sudo().message_post(body=mens)
raise ValidationError(mens)
for downpayment in downpayments.filtered(
lambda d: d.default_invoice_to == invoice.partner_id
):
# If the downpayment invoice partner is the same that the
# folio partner, we include the downpayment in the normal invoice
for downpayment in downpayments:
invoice_down_payment_vals = downpayment._prepare_invoice_line(
sequence=max(invoice.invoice_line_ids.mapped("sequence"))
+ 1,
Expand Down
25 changes: 0 additions & 25 deletions pms/models/pms_reservation_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@ class PmsReservationLine(models.Model):
index=True,
check_pms_properties=True,
)
default_invoice_to = fields.Many2one(
string="Invoice to",
help="""Indicates the contact to which this line will be
billed by default, if it is not established,
a guest or the generic contact will be used instead""",
readonly=False,
store=True,
compute="_compute_default_invoice_to",
comodel_name="res.partner",
index=True,
ondelete="restrict",
)

is_reselling = fields.Boolean(
string="Reselling",
Expand Down Expand Up @@ -521,19 +509,6 @@ def create(self, vals_list):
)
return records

@api.depends("sale_channel_id", "reservation_id.agency_id")
def _compute_default_invoice_to(self):
for record in self:
agency = record.reservation_id.agency_id
if (
agency
and agency.invoice_to_agency == "always"
and agency.sale_channel_id == record.sale_channel_id
):
record.default_invoice_to = agency
elif not record.default_invoice_to:
record.default_invoice_to = False

def write(self, vals):
if not self.env.context.get("force_write_blocked") and (
(
Expand Down
26 changes: 1 addition & 25 deletions pms/models/pms_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,7 @@ class PmsService(models.Model):
""",
default=False,
)
default_invoice_to = fields.Many2one(
string="Invoice to",
help="""Indicates the contact to which this line will be
billed by default, if it is not established,
a guest or the generic contact will be used instead""",
readonly=False,
store=True,
index=True,
compute="_compute_default_invoice_to",
comodel_name="res.partner",
ondelete="restrict",
)

is_cancel_penalty = fields.Boolean(
string="Is Cancel Penalty",
help="Indicates if the service is a cancel penalty",
Expand Down Expand Up @@ -465,19 +454,6 @@ def _inverse_discount(self):
line.discount = record.discount
line.cancel_discount = 0

@api.depends("sale_channel_origin_id", "folio_id.agency_id")
def _compute_default_invoice_to(self):
for record in self:
agency = record.folio_id.agency_id
if (
agency
and agency.invoice_to_agency == "always"
and agency.sale_channel_id == record.sale_channel_origin_id
):
record.default_invoice_to = agency
elif not record.default_invoice_to:
record.default_invoice_to = False

def _compute_is_cancel_penalty(self):
for record in self:
if record.product_id == record.company_id.cancel_penalty_product_id:
Expand Down
11 changes: 0 additions & 11 deletions pms/models/pms_service_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,6 @@ class PmsServiceLine(models.Model):
readonly=False,
store=True,
)
default_invoice_to = fields.Many2one(
string="Invoice to",
help="""Indicates the contact to which this line will be
billed by default, if it is not established,
a guest or the generic contact will be used instead""",
comodel_name="res.partner",
store=True,
index=True,
related="service_id.default_invoice_to",
ondelete="restrict",
)

@api.depends("day_qty", "discount", "price_unit", "tax_ids")
def _compute_day_amount_service(self):
Expand Down
Loading
Loading