mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Test_pms_sale_channel
This commit is contained in:
committed by
Darío Lodeiros
parent
c3c5ff059c
commit
ca2874bb3f
@@ -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"
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
@@ -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
|
||||
|
||||
32
pms/tests/test_pms_sale_channel.py
Normal file
32
pms/tests/test_pms_sale_channel.py
Normal file
@@ -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
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user