[IMP] pms-l10n-es: generate traveller report

Co-authored-by: braisab <braisterbutalino@gmail.com>
This commit is contained in:
miguelpadin
2021-04-29 17:46:37 +02:00
parent ed609bf533
commit 224efeddb2
13 changed files with 240 additions and 9 deletions

View File

@@ -1 +1,2 @@
from . import models from . import models
from . import wizards

View File

@@ -15,10 +15,16 @@
"partner_second_lastname", "partner_second_lastname",
"partner_contact_gender", "partner_contact_gender",
"partner_contact_birthdate", "partner_contact_birthdate",
"partner_contact_nationality",
], ],
"data": [ "data": [
"data/cron_jobs.xml",
"data/pms_sequence.xml",
"security/ir.model.access.csv",
"views/pms_checkin_partner_views.xml", "views/pms_checkin_partner_views.xml",
"views/pms_property_views.xml",
"views/res_partner_views.xml", "views/res_partner_views.xml",
"wizards/traveller_report.xml",
], ],
"installable": True, "installable": True,
} }

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="0">
<record model="ir.cron" id="autosend_traveller_report">
<field name="name">Automatic Send Traveller Report</field>
<field name="active" eval="True" />
<field name="interval_number">1</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="state">code</field>
<field name="model_id" ref="model_traveller_report_wizard" />
<field
name="nextcall"
eval="datetime.now(pytz.timezone('UTC')).strftime('%Y-%m-%d 03:00:00')"
/>
<field name="code">model.generate_file()</field>
</record>
</data>
</odoo>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="1">
<record model="ir.sequence" id="seq_pms_traveller_report">
<field name="name">PMS L10N Traveller Report</field>
<field name="code">traveller.report.wizard</field>
<field name="padding">3</field>
<field name="number_next">1</field>
<field name="number_increment">1</field>
</record>
</data>
</odoo>

View File

@@ -1,2 +1,3 @@
from . import res_partner from . import res_partner
from . import pms_checkin_partner from . import pms_checkin_partner
from . import pms_property

View File

@@ -62,12 +62,13 @@ class PmsCheckinPartner(models.Model):
store=True, store=True,
readonly=False, readonly=False,
) )
nationality_id = fields.Many2one(
@api.depends("partner_id", "partner_id.lastname") string="Nationality ID",
def _compute_lastname(self): compute="_compute_nationality",
for record in self: comodel_name="res.country",
if not record.lastname: store=True,
record.lastname = record.partner_id.lastname readonly=False,
)
@api.depends("partner_id", "partner_id.firstname") @api.depends("partner_id", "partner_id.firstname")
def _compute_firstname(self): def _compute_firstname(self):
@@ -75,6 +76,12 @@ class PmsCheckinPartner(models.Model):
if not record.firstname: if not record.firstname:
record.firstname = record.partner_id.firstname record.firstname = record.partner_id.firstname
@api.depends("partner_id", "partner_id.lastname")
def _compute_lastname(self):
for record in self:
if not record.lastname:
record.lastname = record.partner_id.lastname
@api.depends("partner_id", "partner_id.lastname2") @api.depends("partner_id", "partner_id.lastname2")
def _compute_lastname2(self): def _compute_lastname2(self):
for record in self: for record in self:
@@ -113,6 +120,12 @@ class PmsCheckinPartner(models.Model):
if not record.gender: if not record.gender:
record.gender = record.partner_id.gender record.gender = record.partner_id.gender
@api.depends("partner_id", "partner_id.lastname")
def _compute_nationality(self):
for record in self:
if not record.nationality_id:
record.nationality_id = record.partner_id.nationality_id
@api.model @api.model
def _checkin_mandatory_fields(self, depends=False): def _checkin_mandatory_fields(self, depends=False):
mandatory_fields = super(PmsCheckinPartner, self)._checkin_mandatory_fields( mandatory_fields = super(PmsCheckinPartner, self)._checkin_mandatory_fields(

View File

@@ -0,0 +1,18 @@
from odoo import _, fields, models
class PmsProperty(models.Model):
_inherit = "pms.property"
police_type = fields.Selection(
[
("guardia_civil", "Guardia Civil"),
("policia_nacional","Policía Nacional"),
("ertxaintxa", "Ertxaintxa"),
("mossos", "Mossos_d'esquadra")
],
string="Police Type",
default="guardia_civil")
police_number = fields.Char("Police Number", size=10)
police_user = fields.Char("Police User")
police_pass = fields.Char("Police Password")

View File

@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
user_access_traveller_report_wizard,user_access_traveller_report_wizard,model_traveller_report_wizard,pms.group_pms_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 user_access_traveller_report_wizard user_access_traveller_report_wizard model_traveller_report_wizard pms.group_pms_user 1 1 1 1

View File

@@ -7,12 +7,14 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<data> <data>
<xpath expr="//field[@name='partner_id']" position="after"> <xpath expr="//field[@name='partner_id']" position="after">
<field name="lastname" />
<field name="lastname2" /> <field name="lastname2" />
<field name="gender" /> <field name="gender" />
<field name="birthdate_date" /> <field name="birthdate_date" />
<field name="document_type" /> <field name="document_type" />
<field name="document_number" /> <field name="document_number" />
<field name="document_expedition_date" /> <field name="document_expedition_date" />
<field name="nationality_id" />
</xpath> </xpath>
</data> </data>
</field> </field>
@@ -32,6 +34,7 @@
<field name="document_type" /> <field name="document_type" />
<field name="document_number" /> <field name="document_number" />
<field name="document_expedition_date" /> <field name="document_expedition_date" />
<field name="nationality_id" />
</xpath> </xpath>
</data> </data>
</field> </field>
@@ -51,6 +54,7 @@
<field name="document_type" /> <field name="document_type" />
<field name="document_number" /> <field name="document_number" />
<field name="document_expedition_date" /> <field name="document_expedition_date" />
<field name="nationality_id" />
</xpath> </xpath>
</data> </data>
</field> </field>
@@ -70,11 +74,11 @@
<field name="document_type" /> <field name="document_type" />
<field name="document_number" /> <field name="document_number" />
<field name="document_expedition_date" /> <field name="document_expedition_date" />
<field name="nationality_id" />
</xpath> </xpath>
</data> </data>
</field> </field>
</record> </record>
<record id="pms_checkin_partner_view_search" model="ir.ui.view"> <record id="pms_checkin_partner_view_search" model="ir.ui.view">
<field name="name">Checkin partner view tree Spain</field> <field name="name">Checkin partner view tree Spain</field>
<field name="model">pms.checkin.partner</field> <field name="model">pms.checkin.partner</field>
@@ -93,6 +97,4 @@
</data> </data>
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Hotel Settings -->
<record id="view_property_form_pms_l10n_es" model="ir.ui.view">
<field name="name">Property Form l10n_es</field>
<field name="model">pms.property</field>
<field name="inherit_id" ref="pms.pms_property_views_form" />
<field name="arch" type="xml">
<xpath expr="//page[@name='property_settings']" position="inside">
<group name="property_data" string="Property data">
<field name="police_type"/>
<field name="police_number"/>
<field name="police_user"/>
<field name="police_pass"/>
</group>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1 @@
from . import traveller_report

View File

@@ -0,0 +1,86 @@
import base64
import datetime
from datetime import date
from odoo import _, api, fields, models
import requests
class TravellerReport(models.TransientModel):
_name = "traveller.report.wizard"
_description = "Traveller Report"
txt_filename = fields.Char()
txt_binary = fields.Binary()
txt_message = fields.Char()
def generate_file(self):
date_start = str(date.today()) + " 0:00:00"
date_end = str(date.today()) + " 23:59:59"
lines = self.env["pms.checkin.partner"].search(
[
("state", "=", "onboard"),
("arrival", ">=", date_start),
("arrival", "<=", date_end),
]
)
if not lines:
return
pms_property = self.env["pms.property"].search(
[("id", "=", self.env.user.get_active_property_ids()[0])]
)
if pms_property.police_number and pms_property.name:
content = "1|" + pms_property.police_number.upper() + "|" + pms_property.name.upper()
content += "|"
content += datetime.datetime.now().strftime("%Y%m%d|%H%M")
content += "|" + str(len(lines))
for line in lines:
if line.document_type == "D":
content += "\n2|" + line.document_number.upper() + "||"
else:
content += "\n2||" + line.document_number.upper() + "|"
content += line.document_type + "|"
content += line.document_expedition_date.strftime("%Y%m%d") + "|"
content += line.lastname.upper() + "|"
if line.lastname2:
content += line.lastname2.upper()
content += "|" + line.firstname.upper() + "|"
if line.gender == "female":
content += "F|"
else:
content += "M|"
content += line.birthdate_date.strftime("%Y%m%d") + "|"
# REVIEW: nationality_id must be nationality
content += line.nationality_id.name.upper() + "|"
content += line.arrival.strftime("%Y%m%d") + "|"
sequence_num = self.env['ir.sequence'].next_by_code("traveller.report.wizard")
txt_binary = self.env["traveller.report.wizard"].create(
{
"txt_filename": pms_property.police_number + "." + sequence_num,
"txt_binary": base64.b64encode(str.encode(content)),
"txt_message": content,
}
)
return {
"name": _("Download File"),
"res_id": txt_binary.id,
"res_model": "traveller.report.wizard",
"target": "new",
"type": "ir.actions.act_window",
"view_id": self.env.ref("pms_l10n_es.traveller_report_wizard").id,
"view_mode": "form",
"view_type": "form",
}
def send_guardia_civil_report(self):
pms_property = self.env["pms.property"].search(
[("id", "=", self.env.user.get_active_property_ids()[0])]
)
user = pms_property.police_user
password = pms_property.police_pass
if user and password:
data = [self.txt_binary]
requests.post(
'https://usuario:password@hospederias.guardiacivil.es/hospederias/servlet/ControlRecepcionFichero',
auth=(user, password),
data=data
)

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" ?>
<odoo>
<record id="traveller_report_wizard" model="ir.ui.view">
<field name="name">Traveller Report</field>
<field name="model">traveller.report.wizard</field>
<field name="arch" type="xml">
<form>
<sheet>
<div>
<button
name="generate_file"
class="btn btn-primary btn-sm"
type="object"
string="Generate Police file"
/>
<field name="txt_filename" invisible="1" />
<field
name="txt_binary"
filename="txt_filename"
readonly="1"
style="margin-left: 20px;"
/>
</div>
<group colspan="1">
<div>
<p><field name="txt_message" readonly="1" /></p>
</div>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_traveller_report" model="ir.actions.act_window">
<field name="name">Traveller Report</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">traveller.report.wizard</field>
<field name="view_id" ref="traveller_report_wizard" />
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem
id="menu_traveller_report"
name="Police File Download"
sequence="30"
parent="pms.pms_configuration_menu"
action="action_traveller_report"
/>
</odoo>