mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: improvemente invoice to agency configuration
This commit is contained in:
@@ -535,6 +535,14 @@ class PmsFolio(models.Model):
|
||||
compute="_compute_autoinvoice_date",
|
||||
store=True,
|
||||
)
|
||||
invoice_to_agency = fields.Boolean(
|
||||
string="Invoice Agency",
|
||||
help="""Indicates if agency invoices partner
|
||||
(it only affects those nights/services sold through the agency)""",
|
||||
compute="_compute_invoice_to_agengy",
|
||||
store=True,
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
@@ -899,7 +907,7 @@ class PmsFolio(models.Model):
|
||||
for folio in self:
|
||||
if folio.reservation_type == "out":
|
||||
folio.partner_id = False
|
||||
elif folio.agency_id and folio.agency_id.invoice_to_agency:
|
||||
elif folio.agency_id and folio.invoice_to_agency:
|
||||
folio.partner_id = folio.agency_id.id
|
||||
elif folio.document_number and folio.document_type:
|
||||
self._create_partner(folio)
|
||||
@@ -1336,6 +1344,16 @@ class PmsFolio(models.Model):
|
||||
checkouts = record.reservation_ids.mapped("checkout")
|
||||
record.last_checkout = max(checkouts)
|
||||
|
||||
@api.depends("agency_id")
|
||||
def _compute_invoice_to_agengy(self):
|
||||
for record in self:
|
||||
if not record.agency_id or record.agency_id.invoice_to_agency == "never":
|
||||
record.invoice_to_agency = False
|
||||
elif record.agency_id.invoice_to_agency == "always":
|
||||
record.invoice_to_agency = True
|
||||
elif not record.invoice_to_agency:
|
||||
record.invoice_to_agency = False
|
||||
|
||||
def _search_invoice_ids(self, operator, value):
|
||||
if operator == "in" and value:
|
||||
self.env.cr.execute(
|
||||
@@ -2455,11 +2473,7 @@ class PmsFolio(models.Model):
|
||||
def _apply_partner_name(self, record):
|
||||
if record.partner_id:
|
||||
record.partner_name = record.partner_id.name
|
||||
elif (
|
||||
record.agency_id
|
||||
and not record.agency_id.invoice_to_agency
|
||||
and not record.partner_name
|
||||
):
|
||||
elif record.agency_id and not record.partner_name:
|
||||
# if the customer not is the agency but we dont know the customer's name,
|
||||
# set the name provisional
|
||||
record.partner_name = _("Reservation from ") + record.agency_id.name
|
||||
|
||||
@@ -870,7 +870,6 @@ class PmsReservation(models.Model):
|
||||
|
||||
@api.depends(
|
||||
"reservation_type",
|
||||
"agency_id",
|
||||
"folio_id",
|
||||
"folio_id.agency_id",
|
||||
"document_number",
|
||||
@@ -886,8 +885,6 @@ class PmsReservation(models.Model):
|
||||
reservation.partner_id = False
|
||||
elif reservation.folio_id and reservation.folio_id.partner_id:
|
||||
reservation.partner_id = reservation.folio_id.partner_id
|
||||
elif reservation.agency_id and reservation.agency_id.invoice_to_agency:
|
||||
reservation.partner_id = reservation.agency_id
|
||||
elif reservation.document_number and reservation.document_type:
|
||||
self.env["pms.folio"]._create_partner(reservation)
|
||||
elif not reservation.partner_id:
|
||||
|
||||
@@ -37,9 +37,16 @@ class ResPartner(models.Model):
|
||||
string="Apply Pricelist",
|
||||
help="Indicates if agency pricelist is applied to his reservations",
|
||||
)
|
||||
invoice_to_agency = fields.Boolean(
|
||||
invoice_to_agency = fields.Selection(
|
||||
string="Invoice Agency",
|
||||
help="Indicates if agency invoices partner",
|
||||
selection=[
|
||||
("never", "Never"),
|
||||
("manual", "Manual"),
|
||||
("always", "Always"),
|
||||
],
|
||||
default="never",
|
||||
required=True,
|
||||
)
|
||||
pms_property_ids = fields.Many2many(
|
||||
string="Properties",
|
||||
|
||||
@@ -71,7 +71,7 @@ class TestPmsFolio(TestPms):
|
||||
{
|
||||
"name": "partner1",
|
||||
"is_agency": True,
|
||||
"invoice_to_agency": True,
|
||||
"invoice_to_agency": "always",
|
||||
"default_commission": 15,
|
||||
"sale_channel_id": self.sale_channel1.id,
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class TestPmsReservations(TestPms):
|
||||
{
|
||||
"name": "partner1",
|
||||
"is_agency": True,
|
||||
"invoice_to_agency": True,
|
||||
"invoice_to_agency": "always",
|
||||
"default_commission": 15,
|
||||
"sale_channel_id": self.sale_channel1.id,
|
||||
}
|
||||
@@ -1775,7 +1775,7 @@ class TestPmsReservations(TestPms):
|
||||
"name": "partner1",
|
||||
"is_agency": True,
|
||||
"sale_channel_id": sale_channel1.id,
|
||||
"invoice_to_agency": True,
|
||||
"invoice_to_agency": "always",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ class BookingDuplicate(models.TransientModel):
|
||||
for record in self:
|
||||
if record.reference_folio_id.agency_id == record.agency_id:
|
||||
record.partner_id = record.reference_folio_id.partner_id
|
||||
elif record.agency_id and record.agency_id.invoice_to_agency:
|
||||
elif record.agency_id and record.agency_id.invoice_to_agency == "always":
|
||||
record.partner_id = record.agency_id.id
|
||||
elif not record.partner_id:
|
||||
record.partner_id = False
|
||||
@@ -179,7 +179,7 @@ class BookingDuplicate(models.TransientModel):
|
||||
record.partner_name = record.partner_id.name
|
||||
if (
|
||||
record.agency_id
|
||||
and not record.agency_id.invoice_to_agency
|
||||
and not record.agency_id.invoice_to_agency == "always"
|
||||
and not record.partner_name
|
||||
):
|
||||
record.partner_name = _("Reservation from ") + record.agency_id.name
|
||||
|
||||
@@ -150,7 +150,7 @@ class BookingEngine(models.TransientModel):
|
||||
@api.depends("agency_id")
|
||||
def _compute_partner_id(self):
|
||||
for record in self:
|
||||
if record.agency_id and record.agency_id.invoice_to_agency:
|
||||
if record.agency_id and record.agency_id.invoice_to_agency == "always":
|
||||
record.partner_id = record.agency_id.id
|
||||
elif not record.partner_id:
|
||||
record.partner_id = False
|
||||
@@ -162,7 +162,7 @@ class BookingEngine(models.TransientModel):
|
||||
record.partner_name = record.partner_id.name
|
||||
if (
|
||||
record.agency_id
|
||||
and not record.agency_id.invoice_to_agency
|
||||
and not record.agency_id.invoice_to_agency == "always"
|
||||
and not record.partner_name
|
||||
):
|
||||
record.partner_name = _("Reservation from ") + record.agency_id.name
|
||||
|
||||
Reference in New Issue
Block a user