[FIX] pms: check mandatory fields, ine_seats, add ine link and more

This commit is contained in:
miguelpadin
2021-07-28 19:20:07 +02:00
parent fd01aa07e6
commit 154d42ef90
4 changed files with 98 additions and 29 deletions

View File

@@ -33,7 +33,7 @@ class PmsProperty(models.Model):
string="Institution password",
help="Password provided by institution to send the data.",
)
ine_tourism = fields.Char(
ine_tourism_number = fields.Char(
"Tourism number",
help="Registration number in the Ministry of Tourism. Used for INE statistics.",
)
@@ -48,6 +48,9 @@ class PmsProperty(models.Model):
ine_eventual_staff = fields.Integer(
"Eventual Staff", default=0, help="Used for INE statistics."
)
ine_unpaid_staff = fields.Integer(
"Unpaid Staff", default=0, help="Used for INE statistics."
)
ine_category_id = fields.Many2one(
"pms.ine.tourism.type.category",
help="Hotel category in the Ministry of Tourism. Used for INE statistics.",

View File

@@ -42,7 +42,7 @@
</div>
<div class="col-6">
<group>
<field name="ine_tourism" />
<field name="ine_tourism_number" />
<field name="ine_category_id" />
</group>
</div>
@@ -51,6 +51,7 @@
<field name="ine_seats" />
<field name="ine_permanent_staff" />
<field name="ine_eventual_staff" />
<field name="ine_unpaid_staff" />
</group>
</div>
</div>

View File

@@ -143,21 +143,6 @@ class WizardIne(models.TransientModel):
all_rooms - double_rooms_double_use
) - double_rooms_single_use
seats_excluding_extra_beds = (
sum(other_rooms.mapped("capacity"))
+ sum(double_rooms_double_use.mapped("capacity"))
+ sum(double_rooms_single_use.mapped("capacity"))
)
if seats_excluding_extra_beds > pms_property_id.ine_seats:
raise ValidationError(
_(
"The number of seats, excluding extra beds (%s)"
% str(seats_excluding_extra_beds)
+ " exceeds the number of seats established in the property (%s)"
% str(pms_property_id.ine_seats)
)
)
# no room movements -> no dict entrys
if not (
extra_beds == 0
@@ -413,13 +398,71 @@ class WizardIne(models.TransientModel):
return cif_nif[2:].strip()
return cif_nif.strip()
@api.model
def check_ine_mandatory_fields(self, pms_property_id):
if not pms_property_id.name:
raise ValidationError(_("The property name is not established."))
if not pms_property_id.company_id.vat:
raise ValidationError(_("The company VAT is not established."))
if not pms_property_id.company_id.name:
raise ValidationError(_("The company name is not established."))
if not pms_property_id.name:
raise ValidationError(_("The property name is not established."))
if not pms_property_id.ine_tourism_number:
raise ValidationError(_("The property tourism number is not established."))
if not pms_property_id.ine_tourism_number:
raise ValidationError(_("The property tourism number is not established."))
if not pms_property_id.street:
raise ValidationError(_("The property street is not established."))
if not pms_property_id.zip:
raise ValidationError(_("The property zip is not established."))
if not pms_property_id.city:
raise ValidationError(_("The property city is not established."))
if not pms_property_id.partner_id.state_id:
raise ValidationError(_("The property state is not established."))
if not pms_property_id.phone:
raise ValidationError(_("The property phone is not established."))
if not pms_property_id.ine_category_id:
raise ValidationError(_("The property category is not established."))
def ine_generate_xml(self):
self.check_ine_mandatory_fields(self.pms_property_id)
if self.start_date.month != self.end_date.month:
raise ValidationError(_("The date range must belong to the same month."))
if not self.pms_property_id.company_id.vat:
raise ValidationError(_("The VAT is not established."))
if not self.pms_property_id.phone:
raise ValidationError(_("The phone is not established."))
number_of_rooms = sum(
self.env["pms.room"]
.search(
[
("in_ine", "=", True),
("pms_property_id", "=", self.pms_property_id.id),
]
)
.mapped("capacity")
)
if number_of_rooms > self.pms_property_id.ine_seats:
raise ValidationError(
_(
"The number of seats, excluding extra beds (%s)"
% str(number_of_rooms)
+ " exceeds the number of seats established in the property (%s)"
% str(self.pms_property_id.ine_seats)
)
)
# INE XML
survey_tag = ET.Element("ENCUESTA")
@@ -444,7 +487,7 @@ class WizardIne(models.TransientModel):
)
ET.SubElement(
header_tag, "NUMERO_REGISTRO"
).text = self.pms_property_id.ine_tourism
).text = self.pms_property_id.ine_tourism_number
ET.SubElement(header_tag, "DIRECCION").text = self.pms_property_id.street
ET.SubElement(header_tag, "CODIGO_POSTAL").text = self.pms_property_id.zip
ET.SubElement(header_tag, "LOCALIDAD").text = self.pms_property_id.city
@@ -603,7 +646,9 @@ class WizardIne(models.TransientModel):
ET.SubElement(prices_tag, "PCTN_HABITACIONES_OCUPADAS_OTROS").text = "0"
staff_tag = ET.SubElement(survey_tag, "PERSONAL_OCUPADO")
ET.SubElement(staff_tag, "PERSONAL_NO_REMUNERADO").text = "0"
ET.SubElement(staff_tag, "PERSONAL_NO_REMUNERADO").text = str(
self.pms_property_id.ine_unpaid_staff
)
ET.SubElement(staff_tag, "PERSONAL_REMUNERADO_FIJO").text = str(
self.pms_property_id.ine_permanent_staff
)

View File

@@ -53,12 +53,32 @@
</group>
</div>
</div>
<button
name="ine_generate_xml"
class="btn btn-primary btn-sm"
type="object"
string="Generate INE XML"
/>
<div class="row">
<div class="col-6">
<button
name="ine_generate_xml"
class="btn btn-primary btn-sm"
type="object"
string="Generate INE XML"
/>
</div>
<div
class="col-6"
attrs="{'invisible': [('txt_filename','=', False)]}"
>
<b>
<a
href="https://arce.ine.es/ARCE/jsp/encuestaXml.jsp"
target="_blank"
>
Send survey to Spanish National Institute of Statistics (INE)
<i class="fa fa-signal" />
</a>
</b>
</div>
</div>
<footer />
</form>
</field>