mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms.folio add sale channel constraint
This commit is contained in:
@@ -443,6 +443,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!"
|
||||
)
|
||||
)
|
||||
|
||||
# TODO: Add return_ids to depends
|
||||
@api.depends("amount_total", "payment_ids", "reservation_type", "state")
|
||||
|
||||
@@ -298,13 +298,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(
|
||||
@@ -736,16 +732,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):
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user