mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[RFC]pms: simplified invoice by journal type and out_invoice move type
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
"report/pms_folio.xml",
|
||||
"report/pms_folio_templates.xml",
|
||||
"report/traveller_report_action.xml",
|
||||
"report/invoice.xml",
|
||||
# "templates/pms_email_template.xml",
|
||||
"data/menus.xml",
|
||||
"wizards/wizard_payment_folio.xml",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from odoo import fields, models
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
|
||||
class AccountJournal(models.Model):
|
||||
@@ -20,3 +20,51 @@ class AccountJournal(models.Model):
|
||||
string="For manual payments",
|
||||
help="Use to pay for reservations",
|
||||
)
|
||||
is_simplified_invoice = fields.Boolean(
|
||||
string="Simplified invoice",
|
||||
help="Use to simplified invoice",
|
||||
compute="_compute_is_simplified_invoice",
|
||||
readonly=False,
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.depends("pms_property_ids", "pms_property_ids.journal_simplified_invoice_id")
|
||||
def _compute_is_simplified_invoice(self):
|
||||
self.is_simplified_invoice = False
|
||||
for journal in self:
|
||||
if journal.id in journal.pms_property_ids.mapped(
|
||||
"journal_simplified_invoice_id.id"
|
||||
):
|
||||
journal.is_simplified_invoice = True
|
||||
|
||||
@api.constrains("is_simplified_invoice")
|
||||
def _check_pms_properties_simplified_invoice(self):
|
||||
for journal in self:
|
||||
if (
|
||||
journal.is_simplified_invoice
|
||||
and journal.id
|
||||
in journal.pms_property_ids.mapped("journal_normal_invoice_id.id")
|
||||
):
|
||||
raise models.ValidationError(
|
||||
_(
|
||||
"The journal %s is used for normal invoices in the properties: %s"
|
||||
% (
|
||||
journal.name,
|
||||
", ".join(journal.pms_property_ids.mapped("name")),
|
||||
)
|
||||
)
|
||||
)
|
||||
if (
|
||||
not journal.is_simplified_invoice
|
||||
and journal.id
|
||||
in journal.pms_property_ids.mapped("journal_simplified_invoice_id.id")
|
||||
):
|
||||
raise models.ValidationError(
|
||||
_(
|
||||
"The journal %s is used for simplified invoices in the properties: %s"
|
||||
% (
|
||||
journal.name,
|
||||
", ".join(journal.pms_property_ids.mapped("name")),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -32,6 +32,11 @@ class AccountMove(models.Model):
|
||||
# check_pms_properties=True,
|
||||
)
|
||||
# journal_id = fields.Many2one(check_pms_properties=True)
|
||||
is_simplified_invoice = fields.Boolean(
|
||||
help="Technical field to know if the invoice is simplified",
|
||||
related="journal_id.is_simplified_invoice",
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.onchange("pms_property_id")
|
||||
def _onchange_pms_property_id(self):
|
||||
@@ -292,7 +297,7 @@ class AccountMove(models.Model):
|
||||
Check invoice and receipts legal status
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.move_type == "out_invoice" and (
|
||||
if not self.journal_id.is_simplified_invoice and (
|
||||
not self.partner_id or not self.partner_id._check_enought_invoice_data()
|
||||
):
|
||||
raise UserError(
|
||||
@@ -301,18 +306,18 @@ class AccountMove(models.Model):
|
||||
" partner has the complete information required."
|
||||
)
|
||||
)
|
||||
if self.move_type == "out_receipt":
|
||||
self._check_receipt_restrictions()
|
||||
if self.journal_id.is_simplified_invoice:
|
||||
self._check_simplified_restrictions()
|
||||
return True
|
||||
|
||||
def _check_receipt_restrictions(self):
|
||||
def _check_simplified_restrictions(self):
|
||||
self.ensure_one()
|
||||
if (
|
||||
self.pms_property_id
|
||||
and self.amount_total > self.pms_property_id.max_amount_simplified_invoice
|
||||
):
|
||||
mens = _(
|
||||
"The total amount of the receipt is higher than the "
|
||||
"The total amount of the simplified invoice is higher than the "
|
||||
"maximum amount allowed for simplified invoices."
|
||||
)
|
||||
self.folio_ids.message_post(body=mens)
|
||||
|
||||
@@ -1703,12 +1703,6 @@ class PmsFolio(models.Model):
|
||||
.with_context(default_move_type="out_invoice", auto_name=True)
|
||||
.create(invoice_vals)
|
||||
)
|
||||
else:
|
||||
move = (
|
||||
self.env["account.move"]
|
||||
.with_context(default_move_type="out_receipt", auto_name=True)
|
||||
.create(invoice_vals)
|
||||
)
|
||||
moves += move
|
||||
return moves
|
||||
|
||||
@@ -1773,7 +1767,7 @@ class PmsFolio(models.Model):
|
||||
|
||||
invoice_vals = {
|
||||
"ref": self.client_order_ref or "",
|
||||
"move_type": self._get_default_move_type(partner_invoice_id),
|
||||
"move_type": "out_invoice",
|
||||
"narration": self.note,
|
||||
"currency_id": self.pricelist_id.currency_id.id,
|
||||
# 'campaign_id': self.campaign_id.id,
|
||||
@@ -1803,15 +1797,6 @@ class PmsFolio(models.Model):
|
||||
return pms_property.journal_simplified_invoice_id
|
||||
return pms_property.journal_normal_invoice_id
|
||||
|
||||
def _get_default_move_type(self, partner_invoice_id):
|
||||
self.ensure_one()
|
||||
partner = self.env["res.partner"].browse(partner_invoice_id)
|
||||
if not partner._check_enought_invoice_data() and self._context.get(
|
||||
"autoinvoice"
|
||||
):
|
||||
return "out_receipt"
|
||||
return "out_invoice"
|
||||
|
||||
def do_payment(
|
||||
self,
|
||||
journal,
|
||||
|
||||
@@ -176,7 +176,10 @@ class PmsProperty(models.Model):
|
||||
journal_normal_invoice_id = fields.Many2one(
|
||||
string="Normal Invoice Journal",
|
||||
comodel_name="account.journal",
|
||||
domain=[("type", "=", "sale")],
|
||||
domain=[
|
||||
("type", "=", "sale"),
|
||||
("is_simplified_invoice", "=", False),
|
||||
],
|
||||
help="Journal used to create the normal invoice",
|
||||
check_company=True,
|
||||
check_pms_properties=True,
|
||||
@@ -616,3 +619,12 @@ class PmsProperty(models.Model):
|
||||
if invoices:
|
||||
invoices.action_post()
|
||||
return True
|
||||
|
||||
@api.constrains("journal_normal_invoice_id")
|
||||
def _check_journal_normal_invoice(self):
|
||||
for pms_property in self.filtered("journal_normal_invoice_id"):
|
||||
if pms_property.journal_normal_invoice_id.is_simplified_invoice:
|
||||
raise ValidationError(
|
||||
_("Journal %s is not allowed to be used for normal invoices")
|
||||
% pms_property.journal_normal_invoice_id.name
|
||||
)
|
||||
|
||||
31
pms/report/invoice.xml
Normal file
31
pms/report/invoice.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
|
||||
<xpath expr="//div[@class='page']//h2" position="replace">
|
||||
<h2>
|
||||
<span
|
||||
t-if="o.move_type == 'out_invoice' and o.is_simplified_invoice and o.state == 'posted'"
|
||||
>Simplified Invoice</span>
|
||||
<span
|
||||
t-if="o.move_type == 'out_invoice' and o.is_simplified_invoice and o.state == 'draft'"
|
||||
>Draft Simplified Invoice</span>
|
||||
<span
|
||||
t-if="o.move_type == 'out_invoice' and o.is_simplified_invoice and o.state == 'cancel'"
|
||||
>Cancelled Simplified Invoice</span>
|
||||
<span
|
||||
t-if="o.move_type == 'out_invoice' and not o.is_simplified_invoice and o.state == 'posted'"
|
||||
>Invoice</span>
|
||||
<span
|
||||
t-if="o.move_type == 'out_invoice' and not o.is_simplified_invoice and o.state == 'draft'"
|
||||
>Draft Invoice</span>
|
||||
<span
|
||||
t-if="o.move_type == 'out_invoice' and not o.is_simplified_invoice and o.state == 'cancel'"
|
||||
>Cancelled Invoice</span>
|
||||
<span t-if="o.move_type == 'out_refund'">Credit Note</span>
|
||||
<span t-if="o.move_type == 'in_refund'">Vendor Credit Note</span>
|
||||
<span t-if="o.move_type == 'in_invoice'">Vendor Bill</span>
|
||||
<span t-if="o.name != '/'" t-field="o.name" />
|
||||
</h2>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user