Skip to content

Commit

Permalink
Release 1.9-rc1 (OCA#46)
Browse files Browse the repository at this point in the history
* Release

* [IMP] Pricing multi rate (OCA#47)

* Pricing multi rate

* improve pricing compute

* Fix: Cleaning fee on multiquote and unit price (OCA#49)

* fix send order (singleton issue on write) (OCA#50)

* fix send order (singleton issue on write)

* fix state validation

* Fix guest info on guesty (push/update) (OCA#51)

* ADD CI/CO Date on SO (PDF & Portal) (OCA#53)

* Branch Consolidation

* ADD CI/CO date and time on SO preview (Portal) (OCA#52)

* changes to complement the qweb view

* fix add hour on ci/co

Co-authored-by: Brandon Molina <[email protected]>

* Feature/sale pdf format (OCA#48)

* report pdf custom with checkint-out info

* new format for changes

* fix format

* fix: add hour in CI/CO

Co-authored-by: Brandon Molina <[email protected]>

Co-authored-by: Brandon Molina <[email protected]>

* Fix: remove logs

Co-authored-by: Brandon Molina <[email protected]>
  • Loading branch information
JorgeJuarezCasai and BrandonMolinaCasai authored Mar 17, 2022
1 parent f63c008 commit 9aa7862
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 103 deletions.
2 changes: 2 additions & 0 deletions connector_guesty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"views/pms_guesty_calendar_wizard.xml",
"views/res_partner.xml",
"views/sale_order_views.xml",
"views/sale_order_report_custom.xml",
"views/sales_order_portal_template_custom.xml",
"wizard/pms_property_days_quotation_expiration_views.xml",
"wizard/crm_lead_new_reservation.xml",
"security/ir.model.access.csv",
Expand Down
1 change: 1 addition & 0 deletions connector_guesty/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pms_property_reservation,
pms_guesty_calendar,
pms_configurator,
product,
res_company,
res_config_settings,
res_partner_guesty,
Expand Down
7 changes: 6 additions & 1 deletion connector_guesty/models/backend_guesty.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ def guesty_search_create_customer(self, partner):
guesty_partner = self.env["res.partner.guesty"].search(
[("partner_id", "=", partner.id)], limit=1
)

first_name, last_name = partner.split_name()

if not guesty_partner:
# create on guesty
body = {
"firstName": first_name,
"lastName": last_name,
"fullName": partner.name,
"email": partner.email,
"phone": partner.phone,
}
success, res = self.call_post_request(url_path="guests", body=body)

Expand All @@ -151,6 +155,7 @@ def guesty_search_create_customer(self, partner):

return customer
else:
guesty_partner.guesty_push_update()
return guesty_partner

def guesty_search_pull_customer(self, guesty_id):
Expand Down
78 changes: 78 additions & 0 deletions connector_guesty/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (C) 2021 Casai (https://www.casai.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import datetime
import logging

from odoo import models

_log = logging.getLogger(__name__)


class ProductProduct(models.Model):
_inherit = "product.product"

def price_compute(self, price_type):
result = super().price_compute(price_type)
for product in self:
if product.reservation_ok and self.env.company.guesty_backend_id:
property_id = self.env.context.get("property_id")
reservation_start = self.env.context.get("reservation_start")
reservation_stop = self.env.context.get("reservation_stop")
reservation_date = self.env.context.get("reservation_date")
if (
property_id
and reservation_start
and reservation_stop
and reservation_date
):
price = product.compute_reservation_price(
property_id,
reservation_start,
reservation_stop,
reservation_date,
)
if price:
result[product.id] = price
return result

def compute_reservation_price(self, property_id, start, stop, reservation_date):
real_stop_date = stop - datetime.timedelta(days=1)
success, result = self.env.company.guesty_backend_id.call_get_request(
url_path="availability-pricing/api/calendar/listings/{}".format(
property_id.guesty_id
),
params={
"startDate": start.strftime("%Y-%m-%d"),
"endDate": real_stop_date.strftime("%Y-%m-%d"),
},
paginate=False,
)
if not success:
return None

dates_list = result["data"]["days"]
if len(dates_list) == 0:
return None

prices = [calendar.get("price", 0.0) for calendar in dates_list]
avg_price = sum(prices) / len(prices)

currency_name = dates_list[0]["currency"]
currency_id = (
self.env["res.currency"]
.sudo()
.search([("name", "=", currency_name)], limit=1)
)

if not currency_id:
currency_id = self.sudo().env.ref("base.USD", raise_if_not_found=False)

# noinspection PyProtectedMember
price_currency = currency_id._convert(
avg_price,
self.currency_id,
self.env.company,
reservation_date,
)

return price_currency
17 changes: 16 additions & 1 deletion connector_guesty/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# Copyright (C) 2021 Casai (https://www.casai.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import _, fields, models
from odoo.exceptions import ValidationError


class ResPartner(models.Model):
_inherit = "res.partner"

guesty_ids = fields.One2many("res.partner.guesty", "partner_id")

def split_name(self):
name_values = self.name.split(" ")
if len(name_values) == 0:
raise ValidationError(_("No name defined"))

if len(name_values) == 1:
return name_values[0], None

if len(name_values) == 2:
return name_values[0], name_values[1]

if len(name_values) >= 3:
return name_values[0], " ".join(name_values[1:-1])
26 changes: 26 additions & 0 deletions connector_guesty/models/res_partner_guesty.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# Copyright (C) 2021 Casai (https://www.casai.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

from odoo import fields, models

_log = logging.getLogger(__name__)


class ResPartnerGuesty(models.Model):
_name = "res.partner.guesty"
_description = "Guesty Partner"

partner_id = fields.Many2one("res.partner", required=True, ondelete="cascade")
guesty_id = fields.Char(required=True)

def guesty_push_update(self):
first_name, last_name = self.partner_id.split_name()

body = {
"firstName": first_name,
"lastName": last_name,
"fullName": self.partner_id.name,
}

if self.partner_id.phone:
body["phone"] = self.partner_id.phone

if self.partner_id.email:
body["email"] = self.partner_id.email

success, res = self.env.company.guesty_backend_id.call_put_request(
url_path="guests/{}".format(self.guesty_id), body=body
)

if success:
return res
10 changes: 6 additions & 4 deletions connector_guesty/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def write(self, values):
and len(_fields) > 0
):
for sale in self:
if self.state == "draft":
if sale.state == "draft":
continue

reservation = self.env["pms.reservation"].search(
reservation_ids = self.env["pms.reservation"].search(
[("sale_order_id", "=", sale.id)]
)

if reservation and reservation.guesty_id:
reservation.guesty_push_reservation_update()
if reservation_ids:
for reservation in reservation_ids:
if reservation.guesty_id:
reservation.guesty_push_reservation_update()
return res

def action_cancel(self):
Expand Down
56 changes: 9 additions & 47 deletions connector_guesty/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright (C) 2021 Casai (https://www.casai.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import datetime
import logging

from odoo import fields, models
Expand All @@ -20,50 +19,13 @@ def write(self, values):
return super().write(values)

def _get_display_price(self, product):
if (
self.company_id.guesty_backend_id
and self.reservation_ok
and self.start
and self.stop
):
# todo: Fix Calendar
real_stop = self.stop - datetime.timedelta(days=1)
success, result = self.sudo().company_id.guesty_backend_id.call_get_request(
url_path="availability-pricing/api/calendar/listings/{}".format(
self.sudo().property_id.guesty_id
),
paginate=False,
params={
"startDate": self.start.strftime("%Y-%m-%d"),
"endDate": real_stop.strftime("%Y-%m-%d"),
},
return super()._get_display_price(
product.with_context(
{
"property_id": self.sudo().property_id,
"reservation_start": self.start,
"reservation_stop": self.stop,
"reservation_date": self.order_id.date_order,
}
)

# todo: Fix Calendar
if success:
calendar_data = result.get("data", {}).get("days", [])
prices = [calendar.get("price") for calendar in calendar_data]
avg_price = sum(prices) / len(prices)

currency_name = calendar_data[0]["currency"]
currency_id = (
self.env["res.currency"]
.sudo()
.search([("name", "=", currency_name)], limit=1)
)

if not currency_id:
currency_id = self.sudo().env.ref(
"base.USD", raise_if_not_found=False
)

# noinspection PyProtectedMember
price_currency = currency_id._convert(
avg_price,
self.currency_id,
self.order_id.company_id,
self.order_id.date_order,
)
return price_currency
# noinspection PyProtectedMember
return super()._get_display_price(product)
)
38 changes: 38 additions & 0 deletions connector_guesty/views/sale_order_report_custom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<odoo>
<template
id="sale_order_report_custom"
inherit_id="sale.report_saleorder_document"
name="sale.order.report.custom"
>
<xpath expr="//div[@id='informations']" position="after">
<div class="o_check_out_info">
<br />
<strong>Reservation details</strong>
<table class="table table-sm o_second_table">
<thead style="display: table-row-group">
<tr>
<th name="th_check_in" class="text-left">Check in</th>
<th name="th_check_out" class="text-left">Check out</th>
</tr>
</thead>
<tbody class="check_info_tbody">
<tr>
<td name="td_check_in">
<span
t-field="doc.check_in"
t-options='{"widget": "datetime", "format": "MMM dd, Y HH:mm"}'
/>
</td>
<td name="td_check_out" class="text-left">
<span
t-field="doc.check_out"
t-options='{"widget": "datetime", "format": "MMM dd, Y HH:mm"}'
/>
</td>
</tr>
</tbody>
</table>
</div>
</xpath>
</template>
</odoo>
26 changes: 26 additions & 0 deletions connector_guesty/views/sales_order_portal_template_custom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<odoo>
<template
id="sale_order_portal_template_custom"
inherit_id="sale.sale_order_portal_content"
name="sale.order.portal.template.custom"
>
<xpath expr="//div[@class='row']" position="after">
<div>
<br />
<strong class="d-block mb-1">Reservation details</strong>
<span>Check in:</span>
<b
t-field="sale_order.check_in"
t-options='{"widget": "datetime", "format": "MMM dd, Y HH:mm"}'
/>
<br />
<span>Check out:</span>
<b
t-field="sale_order.check_out"
t-options='{"widget": "datetime", "format": "MMM dd, Y HH:mm"}'
/>
<hr />
</div>
</xpath>
</template>
</odoo>
Loading

0 comments on commit 9aa7862

Please sign in to comment.