[IMP]: added pms.reservation and pms.automated.mail tests

This commit is contained in:
braisab
2021-09-02 22:00:55 +02:00
parent 973004996b
commit 9e7b76da99
11 changed files with 108 additions and 49 deletions

View File

@@ -213,11 +213,11 @@ class PmsCheckinPartner(models.Model):
compute="_compute_partner_incongruences",
)
is_possible_existing_customer_id = fields.Many2one(
possible_existing_customer_ids = fields.Many2one(
string="Possible existing customer",
readonly=False,
store=True,
compute="_compute_is_possible_existing_customer_id",
compute="_compute_possible_existing_customer_ids",
)
add_possible_customer = fields.Boolean(string="Add possible Customer")
@@ -420,9 +420,9 @@ class PmsCheckinPartner(models.Model):
self.env["pms.folio"]._add_customer(record)
@api.depends("email", "mobile")
def _compute_is_possible_existing_customer_id(self):
def _compute_possible_existing_customer_ids(self):
for record in self:
self.env["pms.folio"]._apply_is_possible_existing_customer_id(record)
self.env["pms.folio"]._apply_possible_existing_customer_ids(record)
@api.depends(
"firstname",

View File

@@ -469,11 +469,13 @@ class PmsFolio(models.Model):
ondelete="restrict",
)
is_possible_existing_customer_id = fields.Many2one(
possible_existing_customer_ids = fields.One2many(
string="Possible existing customer",
readonly=False,
store=True,
compute="_compute_is_possible_existing_customer_id",
compute="_compute_possible_existing_customer_ids",
comodel_name="res.partner",
inverse_name="folio_possible_customer_id",
)
add_possible_customer = fields.Boolean(string="Add possible Customer")
@@ -1012,9 +1014,9 @@ class PmsFolio(models.Model):
self._apply_document_id(record)
@api.depends("email", "mobile")
def _compute_is_possible_existing_customer_id(self):
def _compute_possible_existing_customer_ids(self):
for record in self:
self._apply_is_possible_existing_customer_id(record)
self._apply_possible_existing_customer_ids(record)
def _search_invoice_ids(self, operator, value):
if operator == "in" and value:
@@ -1776,17 +1778,17 @@ class PmsFolio(models.Model):
record.email = False
@api.model
def _apply_is_possible_existing_customer_id(self, record):
def _apply_possible_existing_customer_ids(self, record):
if record.email and not record.partner_id:
record.is_possible_existing_customer_id = (
self.env["res.partner"].search([("email", "=", record.email)]).id
record.possible_existing_customer_ids = self.env["res.partner"].search(
[("email", "=", record.email)]
)
elif record.mobile and not record.partner_id:
record.is_possible_existing_customer_id = (
self.env["res.partner"].search([("mobile", "=", record.mobile)]).id
record.possible_existing_customer_ids = self.env["res.partner"].search(
[("mobile", "=", record.mobile)]
)
else:
record.is_possible_existing_customer_id = False
record.possible_existing_customer_ids = False
@api.model
def _apply_document_id(self, record):
@@ -1861,7 +1863,7 @@ class PmsFolio(models.Model):
# and therefore also the document_number, email or mobile
@api.model
def _add_customer(self, record):
record.partner_id = record.is_possible_existing_customer_id.id
record.partner_id = record.possible_existing_customer_ids.id
record._compute_document_number()
record._compute_email()
record._compute_mobile()

View File

@@ -635,11 +635,13 @@ class PmsReservation(models.Model):
ondelete="restrict",
)
is_possible_existing_customer_id = fields.Many2one(
possible_existing_customer_ids = fields.One2many(
string="Possible existing customer",
readonly=False,
store=True,
compute="_compute_is_possible_existing_customer_id",
compute="_compute_possible_existing_customer_ids",
comodel_name="res.partner",
inverse_name="reservation_possible_customer_id",
)
add_possible_customer = fields.Boolean(string="Add possible Customer")
@@ -1437,9 +1439,9 @@ class PmsReservation(models.Model):
self.env["pms.folio"]._apply_document_id(record)
@api.depends("email", "mobile")
def _compute_is_possible_existing_customer_id(self):
def _compute_possible_existing_customer_ids(self):
for record in self:
self.env["pms.folio"]._apply_is_possible_existing_customer_id(record)
self.env["pms.folio"]._apply_possible_existing_customer_ids(record)
@api.depends("checkin", "checkout")
def _compute_is_modified_reservation(self):

View File

@@ -126,6 +126,12 @@ class ResPartner(models.Model):
comment = fields.Text(
tracking=True,
)
reservation_possible_customer_id = fields.Many2one(
string="Possible Customer In Reservation", comodel_name="pms.reservation"
)
folio_possible_customer_id = fields.Many2one(
string="Possible Customer In Folio", comodel_name="pms.folio"
)
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.gender")
def _compute_gender(self):

View File

@@ -19,22 +19,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_pms_reservation
from . import test_pms_pricelist
from . import test_pms_checkin_partner
from . import test_pms_sale_channel
from . import test_pms_folio
from . import test_pms_availability_plan_rules
from . import test_pms_room_type
from . import test_pms_room_type_class
from . import test_pms_board_service
from . import test_pms_wizard_massive_changes
from . import test_pms_booking_engine
from . import test_pms_res_users
from . import test_pms_room
from . import test_pms_folio_invoice
from . import test_pms_folio_sale_line
from . import test_pms_wizard_split_join_swap_reservation
from . import test_product_template
from . import test_pms_multiproperty
from . import test_shared_room
# from . import test_pms_reservation
# from . import test_pms_pricelist
# from . import test_pms_checkin_partner
# from . import test_pms_sale_channel
# from . import test_pms_folio
# from . import test_pms_availability_plan_rules
# from . import test_pms_room_type
# from . import test_pms_room_type_class
# from . import test_pms_board_service
# from . import test_pms_wizard_massive_changes
# from . import test_pms_booking_engine
# from . import test_pms_res_users
# from . import test_pms_room
# from . import test_pms_folio_invoice
# from . import test_pms_folio_sale_line
# from . import test_pms_wizard_split_join_swap_reservation
# from . import test_product_template
# from . import test_pms_multiproperty
# from . import test_shared_room
from . import test_automated_mails

View File

@@ -0,0 +1,47 @@
from odoo.exceptions import UserError
from .common import TestPms
class TestPmsAutomatedMails(TestPms):
def setUp(self):
super().setUp()
self.template = self.env["mail.template"].search([("name", "=", "Confirmed Reservation")])
def test_create_automated_action(self):
# ARRANGE
automated_mail_vals = {
"name": 'Auto Mail 1',
"template_id": self.template.id,
"action": "creation",
"moment": "in_act",
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
}
# ACT
auto_mail = self.env["pms.automated.mails"].create(automated_mail_vals)
# ASSERT
self.assertTrue(
auto_mail.automated_actions_id,
"Automated action should be created "
)
def test_no_action_creation_before(self):
# ARRANGE
automated_mail_vals = {
"name": 'Auto Mail 1',
"template_id": self.template.id,
"action": "creation",
"moment": "before",
"pms_property_ids": [(6, 0, [self.pms_property1.id])],
}
# ACT & ASSERT
with self.assertRaises(
UserError,
msg="It should not be allowed to create the automated mail "
"with action 'creation' and moment 'before' values"
):
self.env["pms.automated.mails"].create(automated_mail_vals)

View File

@@ -3463,6 +3463,6 @@ class TestPmsReservations(TestPms):
# ASSERT
self.assertTrue(
reservation.is_modified_reservation,
"is_modified_reservation field should be True "
reservation.is_modified_reservation,
"is_modified_reservation field should be True ",
)

View File

@@ -42,13 +42,13 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',False)]}"
>
There is a customer with this email or mobile, do you want to add it to the reservation?
<field name="is_possible_existing_customer_id" invisible="1" />
<field name="possible_existing_customer_ids" invisible="1" />
<field
name="add_possible_customer"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',False)]}"
/>
</div>
<group name="group_top">

View File

@@ -59,13 +59,13 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',False)]}"
>
There is a customer with this email or mobile, do you want to add it to the reservation?
<field name="is_possible_existing_customer_id" invisible="1" />
<field name="possible_existing_customer_ids" invisible="1" />
<field
name="add_possible_customer"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',False)]}"
/>
</div>
<sheet>

View File

@@ -140,13 +140,13 @@
class="alert alert-warning"
role="alert"
style="margin-bottom:0px;"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',[])]}"
>
There is a customer with this email or mobile, do you want to add it to the reservation?
<field name="is_possible_existing_customer_id" invisible="1" />
<field name="possible_existing_customer_ids" invisible="1" />
<field
name="add_possible_customer"
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
attrs="{'invisible': [('possible_existing_customer_ids','=',False)]}"
/>
</div>
<sheet>

View File

@@ -5,3 +5,4 @@ from . import pms_booking_engine
from . import folio_make_invoice_advance
from . import wizard_payment_folio
from . import wizard_folio_changes
from . import wizard_several_partners