mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] pms: fix UI errors again
This commit is contained in:
@@ -19,8 +19,6 @@ class TravellerReport(models.TransientModel):
|
|||||||
txt_binary = fields.Binary(string="File Download")
|
txt_binary = fields.Binary(string="File Download")
|
||||||
txt_message = fields.Char(string="File Preview")
|
txt_message = fields.Char(string="File Preview")
|
||||||
|
|
||||||
can_be_sent = fields.Boolean(default=False)
|
|
||||||
|
|
||||||
def generate_file(self):
|
def generate_file(self):
|
||||||
|
|
||||||
# get the active property
|
# get the active property
|
||||||
@@ -31,11 +29,13 @@ class TravellerReport(models.TransientModel):
|
|||||||
# build content
|
# build content
|
||||||
content = self.generate_checkin_list(pms_property.id)
|
content = self.generate_checkin_list(pms_property.id)
|
||||||
|
|
||||||
if not content:
|
if not pms_property.institution_property_id:
|
||||||
content = _("There is no guest information to send")
|
raise ValidationError(
|
||||||
|
_("The guest information sending settins is not property updated.")
|
||||||
if content:
|
)
|
||||||
self.can_be_sent = True
|
elif not content:
|
||||||
|
raise ValidationError(_("There is no guest information to send."))
|
||||||
|
else:
|
||||||
# file creation
|
# file creation
|
||||||
txt_binary = self.env["traveller.report.wizard"].create(
|
txt_binary = self.env["traveller.report.wizard"].create(
|
||||||
{
|
{
|
||||||
@@ -144,79 +144,94 @@ class TravellerReport(models.TransientModel):
|
|||||||
[("id", "=", self.env.user.get_active_property_ids()[0])]
|
[("id", "=", self.env.user.get_active_property_ids()[0])]
|
||||||
)
|
)
|
||||||
|
|
||||||
headers = {
|
if not (
|
||||||
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 "
|
pms_property
|
||||||
"Build/MRA58N) AppleWebKit/537.36 (KHTML, like "
|
and pms_property.institution_property_id
|
||||||
"Gecko) Chrome/90.0.4430.93 Mobile Safari/537.36",
|
and pms_property.institution_user
|
||||||
}
|
and pms_property.institution_password
|
||||||
session = requests.session()
|
):
|
||||||
login_payload = {
|
raise ValidationError(
|
||||||
"usuario": pms_property.institution_user,
|
_("The guest information sending settins is not complete.")
|
||||||
"pswd": pms_property.institution_password,
|
)
|
||||||
}
|
|
||||||
|
|
||||||
# login
|
content = self.generate_checkin_list(pms_property.id)
|
||||||
response_login = session.post(
|
|
||||||
url + login_route,
|
|
||||||
headers=headers,
|
|
||||||
data=login_payload,
|
|
||||||
verify=get_module_resource("pms_l10n_es", "static", "cert.pem"),
|
|
||||||
)
|
|
||||||
|
|
||||||
# check if authentication was successful / unsuccessful or the
|
if content:
|
||||||
# resource cannot be accessed
|
headers = {
|
||||||
soup = bs(response_login.text, "html.parser")
|
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 "
|
||||||
errors_login = soup.select("#txterror > ul > li")
|
"Build/MRA58N) AppleWebKit/537.36 (KHTML, like "
|
||||||
if errors_login:
|
"Gecko) Chrome/90.0.4430.93 Mobile Safari/537.36",
|
||||||
raise ValidationError(errors_login[0].text)
|
}
|
||||||
else:
|
session = requests.session()
|
||||||
login_correct = soup.select(".cabecera2")
|
login_payload = {
|
||||||
if not login_correct:
|
"usuario": pms_property.institution_user,
|
||||||
session.close()
|
"pswd": pms_property.institution_password,
|
||||||
raise ValidationError(_("Connection could not be established"))
|
}
|
||||||
|
|
||||||
# build the file to send
|
# login
|
||||||
pwd = get_module_resource("pms_l10n_es", "wizards", "")
|
response_login = session.post(
|
||||||
checkin_list_file = open(pwd + pms_property.institution_user + ".999", "w+")
|
url + login_route,
|
||||||
checkin_list_file.write(self.generate_checkin_list(pms_property.id))
|
headers=headers,
|
||||||
checkin_list_file.close()
|
data=login_payload,
|
||||||
files = {"fichero": open(pwd + pms_property.institution_user + ".999", "rb")}
|
verify=get_module_resource("pms_l10n_es", "static", "cert.pem"),
|
||||||
|
)
|
||||||
|
|
||||||
# send file
|
# check if authentication was successful / unsuccessful or the
|
||||||
response_file_sent = session.post(
|
# resource cannot be accessed
|
||||||
url + upload_file_route,
|
soup = bs(response_login.text, "html.parser")
|
||||||
data={"autoSeq": "on"},
|
errors_login = soup.select("#txterror > ul > li")
|
||||||
files=files,
|
if errors_login:
|
||||||
verify=get_module_resource("pms_l10n_es", "static", "cert.pem"),
|
raise ValidationError(errors_login[0].text)
|
||||||
)
|
else:
|
||||||
# remove file locally
|
login_correct = soup.select(".cabecera2")
|
||||||
os.remove(pwd + pms_property.institution_user + ".999")
|
if not login_correct:
|
||||||
|
session.close()
|
||||||
|
raise ValidationError(_("Connection could not be established"))
|
||||||
|
|
||||||
# logout & close connection
|
# build the file to send
|
||||||
session.get(
|
pwd = get_module_resource("pms_l10n_es", "wizards", "")
|
||||||
url + logout_route,
|
checkin_list_file = open(pwd + pms_property.institution_user + ".999", "w+")
|
||||||
headers=headers,
|
checkin_list_file.write(content)
|
||||||
verify=get_module_resource("pms_l10n_es", "static", "cert.pem"),
|
checkin_list_file.close()
|
||||||
)
|
files = {
|
||||||
session.close()
|
"fichero": open(pwd + pms_property.institution_user + ".999", "rb")
|
||||||
|
}
|
||||||
|
|
||||||
# check if the file send has been correct
|
# send file
|
||||||
soup = bs(response_file_sent.text, "html.parser")
|
response_file_sent = session.post(
|
||||||
errors = soup.select("#errores > tbody > tr > td > a")
|
url + upload_file_route,
|
||||||
if errors:
|
data={"autoSeq": "on"},
|
||||||
raise ValidationError(errors[2].text)
|
files=files,
|
||||||
else:
|
verify=get_module_resource("pms_l10n_es", "static", "cert.pem"),
|
||||||
if called_from_user:
|
)
|
||||||
message = {
|
# remove file locally
|
||||||
"type": "ir.actions.client",
|
os.remove(pwd + pms_property.institution_user + ".999")
|
||||||
"tag": "display_notification",
|
|
||||||
"params": {
|
# logout & close connection
|
||||||
"title": _("Sent succesfully!"),
|
session.get(
|
||||||
"message": _("Successful file sending"),
|
url + logout_route,
|
||||||
"sticky": False,
|
headers=headers,
|
||||||
},
|
verify=get_module_resource("pms_l10n_es", "static", "cert.pem"),
|
||||||
}
|
)
|
||||||
return message
|
session.close()
|
||||||
|
|
||||||
|
# check if the file send has been correct
|
||||||
|
soup = bs(response_file_sent.text, "html.parser")
|
||||||
|
errors = soup.select("#errores > tbody > tr > td > a")
|
||||||
|
if errors:
|
||||||
|
raise ValidationError(errors[2].text)
|
||||||
|
else:
|
||||||
|
if called_from_user:
|
||||||
|
message = {
|
||||||
|
"type": "ir.actions.client",
|
||||||
|
"tag": "display_notification",
|
||||||
|
"params": {
|
||||||
|
"title": _("Sent succesfully!"),
|
||||||
|
"message": _("Successful file sending"),
|
||||||
|
"sticky": False,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return message
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def send_file_gc_async(self):
|
def send_file_gc_async(self):
|
||||||
|
|||||||
@@ -6,13 +6,12 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form>
|
<form>
|
||||||
<field name="txt_filename" invisible="1" />
|
<field name="txt_filename" invisible="1" />
|
||||||
<field name="can_be_sent" invisible="1" />
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<group attrs="{'invisible': [('txt_message','=',False)]}">
|
<group attrs="{'invisible': [('txt_message','=',False)]}">
|
||||||
<field name="txt_message" readonly="1" />
|
<field name="txt_message" readonly="1" />
|
||||||
</group>
|
</group>
|
||||||
<group attrs="{'invisible': [('can_be_sent','=',False)]}">
|
<group attrs="{'invisible': [('txt_message','=',False)]}">
|
||||||
<field
|
<field
|
||||||
name="txt_binary"
|
name="txt_binary"
|
||||||
filename="txt_filename"
|
filename="txt_filename"
|
||||||
@@ -37,7 +36,7 @@
|
|||||||
class="btn btn-primary btn-sm"
|
class="btn btn-primary btn-sm"
|
||||||
type="object"
|
type="object"
|
||||||
string="Send file"
|
string="Send file"
|
||||||
attrs="{'invisible': [('can_be_sent','=',False)]}"
|
attrs="{'invisible': [('txt_message','=',False)]}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user