[IMP]pms: improvemente invoice to agency configuration

This commit is contained in:
Darío Lodeiros
2022-06-27 08:20:48 +02:00
parent 5bb8872464
commit a531aa026a
7 changed files with 35 additions and 17 deletions

View File

@@ -535,6 +535,14 @@ class PmsFolio(models.Model):
compute="_compute_autoinvoice_date", compute="_compute_autoinvoice_date",
store=True, 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): def name_get(self):
result = [] result = []
@@ -899,7 +907,7 @@ class PmsFolio(models.Model):
for folio in self: for folio in self:
if folio.reservation_type == "out": if folio.reservation_type == "out":
folio.partner_id = False 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 folio.partner_id = folio.agency_id.id
elif folio.document_number and folio.document_type: elif folio.document_number and folio.document_type:
self._create_partner(folio) self._create_partner(folio)
@@ -1336,6 +1344,16 @@ class PmsFolio(models.Model):
checkouts = record.reservation_ids.mapped("checkout") checkouts = record.reservation_ids.mapped("checkout")
record.last_checkout = max(checkouts) 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): def _search_invoice_ids(self, operator, value):
if operator == "in" and value: if operator == "in" and value:
self.env.cr.execute( self.env.cr.execute(
@@ -2455,11 +2473,7 @@ class PmsFolio(models.Model):
def _apply_partner_name(self, record): def _apply_partner_name(self, record):
if record.partner_id: if record.partner_id:
record.partner_name = record.partner_id.name record.partner_name = record.partner_id.name
elif ( elif record.agency_id and not record.partner_name:
record.agency_id
and not record.agency_id.invoice_to_agency
and not record.partner_name
):
# if the customer not is the agency but we dont know the customer's name, # if the customer not is the agency but we dont know the customer's name,
# set the name provisional # set the name provisional
record.partner_name = _("Reservation from ") + record.agency_id.name record.partner_name = _("Reservation from ") + record.agency_id.name

View File

@@ -870,7 +870,6 @@ class PmsReservation(models.Model):
@api.depends( @api.depends(
"reservation_type", "reservation_type",
"agency_id",
"folio_id", "folio_id",
"folio_id.agency_id", "folio_id.agency_id",
"document_number", "document_number",
@@ -886,8 +885,6 @@ class PmsReservation(models.Model):
reservation.partner_id = False reservation.partner_id = False
elif reservation.folio_id and reservation.folio_id.partner_id: elif reservation.folio_id and reservation.folio_id.partner_id:
reservation.partner_id = 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: elif reservation.document_number and reservation.document_type:
self.env["pms.folio"]._create_partner(reservation) self.env["pms.folio"]._create_partner(reservation)
elif not reservation.partner_id: elif not reservation.partner_id:

View File

@@ -37,9 +37,16 @@ class ResPartner(models.Model):
string="Apply Pricelist", string="Apply Pricelist",
help="Indicates if agency pricelist is applied to his reservations", help="Indicates if agency pricelist is applied to his reservations",
) )
invoice_to_agency = fields.Boolean( invoice_to_agency = fields.Selection(
string="Invoice Agency", string="Invoice Agency",
help="Indicates if agency invoices partner", help="Indicates if agency invoices partner",
selection=[
("never", "Never"),
("manual", "Manual"),
("always", "Always"),
],
default="never",
required=True,
) )
pms_property_ids = fields.Many2many( pms_property_ids = fields.Many2many(
string="Properties", string="Properties",

View File

@@ -71,7 +71,7 @@ class TestPmsFolio(TestPms):
{ {
"name": "partner1", "name": "partner1",
"is_agency": True, "is_agency": True,
"invoice_to_agency": True, "invoice_to_agency": "always",
"default_commission": 15, "default_commission": 15,
"sale_channel_id": self.sale_channel1.id, "sale_channel_id": self.sale_channel1.id,
} }

View File

@@ -97,7 +97,7 @@ class TestPmsReservations(TestPms):
{ {
"name": "partner1", "name": "partner1",
"is_agency": True, "is_agency": True,
"invoice_to_agency": True, "invoice_to_agency": "always",
"default_commission": 15, "default_commission": 15,
"sale_channel_id": self.sale_channel1.id, "sale_channel_id": self.sale_channel1.id,
} }
@@ -1775,7 +1775,7 @@ class TestPmsReservations(TestPms):
"name": "partner1", "name": "partner1",
"is_agency": True, "is_agency": True,
"sale_channel_id": sale_channel1.id, "sale_channel_id": sale_channel1.id,
"invoice_to_agency": True, "invoice_to_agency": "always",
} }
) )

View File

@@ -159,7 +159,7 @@ class BookingDuplicate(models.TransientModel):
for record in self: for record in self:
if record.reference_folio_id.agency_id == record.agency_id: if record.reference_folio_id.agency_id == record.agency_id:
record.partner_id = record.reference_folio_id.partner_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 record.partner_id = record.agency_id.id
elif not record.partner_id: elif not record.partner_id:
record.partner_id = False record.partner_id = False
@@ -179,7 +179,7 @@ class BookingDuplicate(models.TransientModel):
record.partner_name = record.partner_id.name record.partner_name = record.partner_id.name
if ( if (
record.agency_id 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 and not record.partner_name
): ):
record.partner_name = _("Reservation from ") + record.agency_id.name record.partner_name = _("Reservation from ") + record.agency_id.name

View File

@@ -150,7 +150,7 @@ class BookingEngine(models.TransientModel):
@api.depends("agency_id") @api.depends("agency_id")
def _compute_partner_id(self): def _compute_partner_id(self):
for record in 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 record.partner_id = record.agency_id.id
elif not record.partner_id: elif not record.partner_id:
record.partner_id = False record.partner_id = False
@@ -162,7 +162,7 @@ class BookingEngine(models.TransientModel):
record.partner_name = record.partner_id.name record.partner_name = record.partner_id.name
if ( if (
record.agency_id 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 and not record.partner_name
): ):
record.partner_name = _("Reservation from ") + record.agency_id.name record.partner_name = _("Reservation from ") + record.agency_id.name