Skip to content

Commit

Permalink
[IMP]pms: sudo message_post in folio and reverse_moves with origin ref
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Mar 16, 2024
1 parent 2e2bd93 commit 591ef71
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
12 changes: 10 additions & 2 deletions pms/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dateutil.relativedelta import relativedelta

from odoo import api, fields, models
from odoo import _, api, fields, models


class AccountPayment(models.Model):
Expand Down Expand Up @@ -113,7 +113,15 @@ def action_draft(self):
lambda inv: inv._is_downpayment()
)
if downpayment_invoices.state == "posted":
downpayment_invoices._reverse_moves(cancel=True)
default_values_list = [
{
"ref": _(f'Reversal of: {move.name + " - " + move.ref}'),
}
for move in downpayment_invoices
]
downpayment_invoices._reverse_moves(
default_values_list, cancel=True
)
else:
downpayment_invoices.unlink()
return super(AccountPayment, self).action_draft()
Expand Down
15 changes: 2 additions & 13 deletions pms/models/pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,17 +1954,6 @@ def _create_invoices(
month_day,
)
if invoice_date:
if (
self.company_id.period_lock_date
and invoice_date < self.company_id.period_lock_date
and not self.user_has_groups("account.group_account_manager")
):
raise UserError(
_(
"The period to create this invoice is locked. "
"Please contact your administrator to unlock it."
)
)
if invoice_date < datetime.date.today() and not self._context.get(
"autoinvoice"
):
Expand Down Expand Up @@ -2212,7 +2201,7 @@ def do_payment(
date=date,
)
self.env["account.bank.statement.line"].sudo().create(line)
folio.message_post(
folio.sudo().message_post(
body=_(
"""Payment: <b>%s</b> by <b>%s</b>""",
amount,
Expand Down Expand Up @@ -2299,7 +2288,7 @@ def do_refund(
)
self.env["account.bank.statement.line"].sudo().create(line)

folio.message_post(
folio.sudo().message_post(
body=_(
"""Refund: <b>%s</b> by <b>%s</b>""",
amount,
Expand Down
22 changes: 17 additions & 5 deletions pms/models/pms_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def autoinvoicing(self, offset=0, with_delay=False, autocommit=False):
if any([res.state != "cancel" for res in folio.reservation_ids]):
folios_to_invoice += folio
else:
folio.message_post(
folio.sudo().message_post(
body=_(
"Not invoiced due to pending amounts and cancelled reservations"
)
Expand Down Expand Up @@ -744,9 +744,15 @@ def autoinvoicing(self, offset=0, with_delay=False, autocommit=False):
downpayment_invoices = downpayments_invoices_to_reverse.mapped("move_id")
if downpayment_invoices:
for downpayment_invoice in downpayment_invoices:
default_values_list = [
{
"ref": _(f'Reversal of: {move.name + " - " + move.ref}'),
}
for move in downpayment_invoice
]
downpayment_invoice.with_context(
{"sii_refund_type": "I"}
)._reverse_moves(cancel=True)
)._reverse_moves(default_values_list, cancel=True)
downpayment_invoice.message_post(
body=_(
"""
Expand Down Expand Up @@ -830,7 +836,7 @@ def autoinvoice_folio(self, folio):
"maximum amount allowed for simplified invoices, and dont have "
"enought data in hosts to create a normal invoice."
)
folio.message_post(body=mens)
folio.sudo().message_post(body=mens)
raise ValidationError(mens)
for downpayment in downpayments.filtered(
lambda d: d.default_invoice_to == invoice.partner_id
Expand All @@ -852,11 +858,17 @@ def autoinvoice_folio(self, folio):
).invoice_lines.mapped("move_id")
).filtered(lambda i: i.is_simplified_invoice)
if downpayment_invoices:
default_values_list = [
{
"ref": _(f'Reversal of: {move.name + " - " + move.ref}'),
}
for move in downpayment_invoices
]
downpayment_invoices.with_context(
{"sii_refund_type": "I"}
)._reverse_moves(cancel=True)
)._reverse_moves(default_values_list, cancel=True)
except Exception as e:
folio.message_post(body=_("Error in autoinvoicing folio: " + str(e)))
folio.sudo().message_post(body=_("Error in autoinvoicing folio: " + str(e)))

@api.constrains("journal_normal_invoice_id")
def _check_journal_normal_invoice(self):
Expand Down
10 changes: 8 additions & 2 deletions pms/views/pms_reservation_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<form string="Reservation">
<header>
<field name="splitted" invisible="True" />
<field name="tax_ids" invisible="1" />
<field name="checkin_partner_count" invisible="1" />
<field name="to_assign" invisible="1" />
<field name="check_adults" invisible="1" />
Expand Down Expand Up @@ -586,7 +585,7 @@
<field
name="tax_ids"
widget="many2many_tags"
optional="hide"
optional="show"
/>
<field name="price_subtotal" optional="hide" />
<field name="price_tax" optional="hide" />
Expand Down Expand Up @@ -713,6 +712,13 @@
string="Invoicing"
attrs="{'invisible': [('reservation_type','in',('out','staff'))]}"
>
<group>
<field
name="tax_ids"
widget="many2many_tags"
options="{'no_create': True,'no_open': True}"
/>
</group>
</page>
<page name="others" string="Others">
<div class="row">
Expand Down

0 comments on commit 591ef71

Please sign in to comment.