[IMP] pms.folio add sale channel constraint

This commit is contained in:
Sara Lago
2020-11-11 11:49:11 +01:00
committed by Darío Lodeiros
parent ca2874bb3f
commit d5de68e120
3 changed files with 37 additions and 17 deletions

View File

@@ -442,6 +442,17 @@ class PmsFolio(models.Model):
"amount_total": amount_untaxed + amount_tax,
}
)
# Check channel type
@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
or record.channel_type == "direct" and record.partner_id.is_agency == True):
raise ValidationError(
_(
"Indirect Sale Channel must have an agency associated!"
)
)
@api.depends("reservation_ids", "reservation_ids.state")
def _compute_reservations_pending_arrival(self):

View File

@@ -344,13 +344,9 @@ class PmsReservation(models.Model):
reselling = fields.Boolean("Is Reselling", default=False)
nights = fields.Integer("Nights", compute="_compute_nights", store=True)
channel_type = fields.Selection(
[
("direct","Direct"),
("indirect","Indirect")
],
string="Channel type",
related="folio_id.channel_type",
required = True,
store=True
readonly = True,
)
origin = fields.Char("Origin", compute="_compute_origin", store=True)
detail_origin = fields.Char(
@@ -1008,16 +1004,6 @@ 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):

View File

@@ -23,10 +23,33 @@ class TestPmsSaleChannel(TestHotel):
"checkin": datetime.datetime.now(),
"checkout":datetime.datetime.now() + datetime.timedelta(days=3),
"channel_type":"indirect",
"partner_id":not_agency.id
"partner_id":not_agency.id,
}
)
def test_reservation_direct_channel(self):
PmsReservation = self.env["pms.reservation"]
agency = self.env["res.partner"].create(
{
"name":"partner2",
"is_agency":True,
}
)
#ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint():
PmsReservation.create(
{
"checkin": datetime.datetime.now() +datetime.timedelta(days=5),
"checkout":datetime.datetime.now() + datetime.timedelta(days=8),
"channel_type":"direct",
"partner_id":agency.id,
}
)