mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: improvement invoicing data checks
This commit is contained in:
@@ -4,7 +4,7 @@ import itertools as it
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
|
|
||||||
|
|
||||||
class AccountMove(models.Model):
|
class AccountMove(models.Model):
|
||||||
@@ -265,6 +265,8 @@ class AccountMove(models.Model):
|
|||||||
"""
|
"""
|
||||||
Overwrite the original method to add the folio_ids to the invoice
|
Overwrite the original method to add the folio_ids to the invoice
|
||||||
"""
|
"""
|
||||||
|
for record in self:
|
||||||
|
record._check_pms_valid_invoice(record)
|
||||||
res = super(AccountMove, self)._post(soft)
|
res = super(AccountMove, self)._post(soft)
|
||||||
self._autoreconcile_folio_payments()
|
self._autoreconcile_folio_payments()
|
||||||
return res
|
return res
|
||||||
@@ -282,3 +284,35 @@ class AccountMove(models.Model):
|
|||||||
lambda p: p.id in [item.id for item in combi]
|
lambda p: p.id in [item.id for item in combi]
|
||||||
)
|
)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def _check_pms_valid_invoice(self, move):
|
||||||
|
"""
|
||||||
|
Check invoice and receipts legal status
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
if self.move_type == "out_invoice" and (
|
||||||
|
not self.partner_id or not self.partner_id._check_enought_invoice_data()
|
||||||
|
):
|
||||||
|
raise UserError(
|
||||||
|
_(
|
||||||
|
"You cannot validate this invoice. Please check the "
|
||||||
|
" partner has the complete information required."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if self.move_type == "out_receipt":
|
||||||
|
self._check_receipt_restrictions()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _check_receipt_restrictions(self):
|
||||||
|
self.ensure_one()
|
||||||
|
if (
|
||||||
|
self.pms_property_id
|
||||||
|
and self.total_amount > self.pms_property_id.max_amount_simplified_invoice
|
||||||
|
):
|
||||||
|
mens = _(
|
||||||
|
"The total amount of the receipt is higher than the "
|
||||||
|
"maximum amount allowed for simplified invoices."
|
||||||
|
)
|
||||||
|
self.folio_ids.message_post(body=mens)
|
||||||
|
raise ValidationError(mens)
|
||||||
|
return True
|
||||||
|
|||||||
@@ -1797,14 +1797,18 @@ class PmsFolio(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
pms_property = self.pms_property_id
|
pms_property = self.pms_property_id
|
||||||
partner = self.env["res.partner"].browse(partner_invoice_id)
|
partner = self.env["res.partner"].browse(partner_invoice_id)
|
||||||
if not partner._enought_invoice_data() and self._context.get("autoinvoice"):
|
if not partner._check_enought_invoice_data() and self._context.get(
|
||||||
|
"autoinvoice"
|
||||||
|
):
|
||||||
return pms_property.journal_simplified_invoice_id
|
return pms_property.journal_simplified_invoice_id
|
||||||
return pms_property.journal_normal_invoice_id
|
return pms_property.journal_normal_invoice_id
|
||||||
|
|
||||||
def _get_default_move_type(self, partner_invoice_id):
|
def _get_default_move_type(self, partner_invoice_id):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
partner = self.env["res.partner"].browse(partner_invoice_id)
|
partner = self.env["res.partner"].browse(partner_invoice_id)
|
||||||
if not partner._enought_invoice_data() and self._context.get("autoinvoice"):
|
if not partner._check_enought_invoice_data() and self._context.get(
|
||||||
|
"autoinvoice"
|
||||||
|
):
|
||||||
return "out_receipt"
|
return "out_receipt"
|
||||||
return "out_invoice"
|
return "out_invoice"
|
||||||
|
|
||||||
|
|||||||
@@ -182,6 +182,12 @@ class PmsProperty(models.Model):
|
|||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
max_amount_simplified_invoice = fields.Float(
|
||||||
|
string="Max Amount Simplified Invoice",
|
||||||
|
help="Maximum amount to create the simplified invoice",
|
||||||
|
default=400.0,
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends_context(
|
@api.depends_context(
|
||||||
"checkin",
|
"checkin",
|
||||||
"checkout",
|
"checkout",
|
||||||
|
|||||||
@@ -555,15 +555,13 @@ class ResPartner(models.Model):
|
|||||||
key_fields.extend(["document_number"])
|
key_fields.extend(["document_number"])
|
||||||
return key_fields
|
return key_fields
|
||||||
|
|
||||||
def _enought_invoice_data(self):
|
def _check_enought_invoice_data(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if (
|
if (
|
||||||
self.document_number_to_invoice
|
self.document_number_to_invoice
|
||||||
and not self.country_id
|
and self.country_id
|
||||||
and not self.state_id
|
and self.city
|
||||||
and not self.city
|
and self.street
|
||||||
and not self.zip
|
|
||||||
and not self.street
|
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -92,14 +92,6 @@
|
|||||||
name="margin_days_autoinvoice"
|
name="margin_days_autoinvoice"
|
||||||
attrs="{'invisible': [('default_invoicing_policy', '=', 'manual')]}"
|
attrs="{'invisible': [('default_invoicing_policy', '=', 'manual')]}"
|
||||||
/>
|
/>
|
||||||
<field
|
|
||||||
name="journal_simplified_invoice_id"
|
|
||||||
attrs="{'required': [('default_invoicing_policy', '!=', 'manual')]}"
|
|
||||||
domain="[
|
|
||||||
('type', '=', 'sale'),
|
|
||||||
('company_id','=',company_id),
|
|
||||||
]"
|
|
||||||
/>
|
|
||||||
<field
|
<field
|
||||||
name="journal_normal_invoice_id"
|
name="journal_normal_invoice_id"
|
||||||
attrs="{'required': [('default_invoicing_policy', '!=', 'manual')]}"
|
attrs="{'required': [('default_invoicing_policy', '!=', 'manual')]}"
|
||||||
@@ -108,6 +100,15 @@
|
|||||||
('company_id','=',company_id),
|
('company_id','=',company_id),
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
|
<field
|
||||||
|
name="journal_simplified_invoice_id"
|
||||||
|
attrs="{'required': [('default_invoicing_policy', '!=', 'manual')]}"
|
||||||
|
domain="[
|
||||||
|
('type', '=', 'sale'),
|
||||||
|
('company_id','=',company_id),
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
<field name="max_amount_simplified_invoice" />
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
<page string="Email Configuration">
|
<page string="Email Configuration">
|
||||||
|
|||||||
@@ -27,3 +27,13 @@ class ResPartner(models.Model):
|
|||||||
if not record.state_id:
|
if not record.state_id:
|
||||||
record.ine_code = False
|
record.ine_code = False
|
||||||
record.ine_code = record.state_id.ine_code
|
record.ine_code = record.state_id.ine_code
|
||||||
|
|
||||||
|
def _check_enought_invoice_data(self):
|
||||||
|
self.ensure_one()
|
||||||
|
res = super(ResPartner, self)._check_enought_invoice_data()
|
||||||
|
if not res:
|
||||||
|
return res
|
||||||
|
if self.country_id.code == "ES":
|
||||||
|
if not self.state_id and not self.zip:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user