[IMP]pms: improvement invoicing data checks

This commit is contained in:
Darío Lodeiros
2022-02-26 11:05:53 +01:00
parent 3cd44df820
commit b285f6d0eb
6 changed files with 70 additions and 17 deletions

View File

@@ -4,7 +4,7 @@ import itertools as it
import json
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError
class AccountMove(models.Model):
@@ -265,6 +265,8 @@ class AccountMove(models.Model):
"""
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)
self._autoreconcile_folio_payments()
return res
@@ -282,3 +284,35 @@ class AccountMove(models.Model):
lambda p: p.id in [item.id for item in combi]
)
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

View File

@@ -1789,14 +1789,18 @@ class PmsFolio(models.Model):
self.ensure_one()
pms_property = self.pms_property_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_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._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_invoice"

View File

@@ -182,6 +182,12 @@ class PmsProperty(models.Model):
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(
"checkin",
"checkout",

View File

@@ -555,15 +555,13 @@ class ResPartner(models.Model):
key_fields.extend(["document_number"])
return key_fields
def _enought_invoice_data(self):
def _check_enought_invoice_data(self):
self.ensure_one()
if (
self.document_number_to_invoice
and not self.country_id
and not self.state_id
and not self.city
and not self.zip
and not self.street
and self.country_id
and self.city
and self.street
):
return True
return False

View File

@@ -92,14 +92,6 @@
name="margin_days_autoinvoice"
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
name="journal_normal_invoice_id"
attrs="{'required': [('default_invoicing_policy', '!=', 'manual')]}"
@@ -108,6 +100,15 @@
('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>
</page>
<page string="Email Configuration">

View File

@@ -27,3 +27,13 @@ class ResPartner(models.Model):
if not record.state_id:
record.ine_code = False
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