From ca2874bb3f10ff5376c23cee55a190dd33eca4a2 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Wed, 11 Nov 2020 10:03:50 +0100 Subject: [PATCH] [IMP] Test_pms_sale_channel --- pms/models/pms_folio.py | 4 +-- pms/models/pms_reservation.py | 44 ++++++++++++------------------ pms/models/pms_sales_channel.py | 16 ----------- pms/tests/__init__.py | 1 + pms/tests/test_pms_sale_channel.py | 32 ++++++++++++++++++++++ 5 files changed, 52 insertions(+), 45 deletions(-) delete mode 100644 pms/models/pms_sales_channel.py create mode 100644 pms/tests/test_pms_sale_channel.py diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index d48de2ba4..71088d067 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -166,7 +166,7 @@ class PmsFolio(models.Model): channel_type = fields.Selection( [ ("direct", "Direct"), - ("agency", "Agency"), + ("indirect", "Indirect"), ], string="Sales Channel", compute="_compute_channel_type", @@ -312,7 +312,7 @@ class PmsFolio(models.Model): def _compute_channel_type(self): for folio in self: if folio.agency_id: - folio.channel_type = "agency" + folio.channel_type = "indirect" else: folio.channel_type = "direct" diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index e29fd69b3..e909aa8b0 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -148,6 +148,7 @@ class PmsReservation(models.Model): readonly=False, ) agency_id = fields.Many2one(related="folio_id.agency_id") + partner_invoice_id = fields.Many2one( "res.partner", string="Invoice Address", @@ -343,20 +344,13 @@ class PmsReservation(models.Model): reselling = fields.Boolean("Is Reselling", default=False) nights = fields.Integer("Nights", compute="_compute_nights", store=True) channel_type = fields.Selection( - selection=[ - ("direct", "Direct"), - ("agency", "Agency"), + [ + ("direct","Direct"), + ("indirect","Indirect") ], - string="Sales Channel", - default="direct", - ) - subchannel_direct = fields.Selection( - selection=[ - ("door", "Door"), - ("mail", "Mail"), - ("phone", "Phone"), - ], - string="Direct Channel", + string="Channel type", + required = True, + store=True ) origin = fields.Char("Origin", compute="_compute_origin", store=True) detail_origin = fields.Char( @@ -1014,6 +1008,16 @@ class PmsReservation(models.Model): # self._compute_tax_ids() TODO: refact + @api.constrains("channel_type") + def check_channel_type(self): + for record in self: + if (record.channel_type == "indirect" and record.partner_id.is_agency != True): + raise ValidationError( + _( + "Indirect Sale Channel must have an agency associated!" + ) + ) + # Action methods def open_folio(self): @@ -1288,20 +1292,6 @@ class PmsReservation(models.Model): record.checkin_partner_count = 0 record.checkin_partner_pending_count = 0 - @api.depends("channel_type", "subchannel_direct") - def _compute_origin(self): - for reservation in self: - if reservation.channel_type == "direct": - reservation.origin = reservation.subchannel_direct - elif reservation.channel_type == "agency": - reservation.origin = reservation.agency_id.name - - @api.depends("origin") - def _compute_detail_origin(self): - for reservation in self: - if reservation.channel_type in ["direct", "agency"]: - reservation.detail_origin = reservation.sudo().create_uid.name - def _search_checkin_partner_pending(self, operator, value): self.ensure_one() recs = self.search([]).filtered(lambda x: x.checkin_partner_pending_count > 0) diff --git a/pms/models/pms_sales_channel.py b/pms/models/pms_sales_channel.py deleted file mode 100644 index 0c4a1aef9..000000000 --- a/pms/models/pms_sales_channel.py +++ /dev/null @@ -1,16 +0,0 @@ -from odoo import models, fields -class PmsSalesChannel(models.Model): - _name="pms.room.sales.channel" - _description="Sales Channel" - _order="sequence, channel_type, name" - - name=fields.Char("Sale Channel Name", required=True) - channel_type=field.Selection( - selection=[ - ("direct","Direct"), - ("indirect","Indirect"), - ], - string="Type" - ) - is_offline=fields.Boolean("Is Offline") - is_online=fields.Boolean("Is Online") diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 99f80c5c0..8fd1589ba 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -22,3 +22,4 @@ from . import test_pms_reservation from . import test_pms_pricelist from . import test_pms_checkin_partner +from . import test_pms_sale_channel diff --git a/pms/tests/test_pms_sale_channel.py b/pms/tests/test_pms_sale_channel.py new file mode 100644 index 000000000..f58ac8c88 --- /dev/null +++ b/pms/tests/test_pms_sale_channel.py @@ -0,0 +1,32 @@ +from .common import TestHotel +from freezegun import freeze_time +from odoo.exceptions import ValidationError +import datetime +from odoo import fields + +@freeze_time("2010-01-01") +class TestPmsSaleChannel(TestHotel): + def test_reservation_indirect_channel(self): + #ARRANGE + PmsReservation = self.env["pms.reservation"] + not_agency = self.env["res.partner"].create( + { + "name":"partner1", + "is_agency":False + } + ) + + #ACT & ASSERT + with self.assertRaises(ValidationError), self.cr.savepoint(): + PmsReservation.create( + { + "checkin": datetime.datetime.now(), + "checkout":datetime.datetime.now() + datetime.timedelta(days=3), + "channel_type":"indirect", + "partner_id":not_agency.id + } + ) + + + +