[IMP]pms: sudo message_post in folio and reverse_moves with origin ref

This commit is contained in:
Darío Lodeiros
2024-03-16 17:44:37 +01:00
parent 2e2bd930be
commit 591ef71e98
4 changed files with 37 additions and 22 deletions

View File

@@ -4,7 +4,7 @@ from collections import defaultdict
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
from odoo import _, api, fields, models
class AccountPayment(models.Model):
@@ -113,7 +113,15 @@ class AccountPayment(models.Model):
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()

View File

@@ -1954,17 +1954,6 @@ class PmsFolio(models.Model):
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"
):
@@ -2212,7 +2201,7 @@ class PmsFolio(models.Model):
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,
@@ -2299,7 +2288,7 @@ class PmsFolio(models.Model):
)
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,

View File

@@ -708,7 +708,7 @@ class PmsProperty(models.Model):
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"
)
@@ -744,9 +744,15 @@ class PmsProperty(models.Model):
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=_(
"""
@@ -830,7 +836,7 @@ class PmsProperty(models.Model):
"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
@@ -852,11 +858,17 @@ class PmsProperty(models.Model):
).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):

View File

@@ -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" />
@@ -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" />
@@ -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">