mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
@@ -697,14 +697,29 @@ class PmsFolio(models.Model):
|
||||
if not folio.user_id:
|
||||
folio.user_id = (folio.partner_id.user_id.id or self.env.uid,)
|
||||
|
||||
@api.depends("partner_id")
|
||||
@api.depends(
|
||||
"partner_id",
|
||||
"reservation_ids",
|
||||
"reservation_ids.partner_id",
|
||||
"reservation_ids.checkin_partner_ids",
|
||||
"reservation_ids.checkin_partner_ids.partner_id",
|
||||
)
|
||||
def _compute_partner_invoice_ids(self):
|
||||
for folio in self.filtered("partner_id"):
|
||||
folio.partner_invoice_ids = False
|
||||
addr = folio.partner_id.address_get(["invoice"])
|
||||
if not addr["invoice"] in folio.partner_invoice_ids.ids:
|
||||
folio.partner_invoice_ids = [(4, addr["invoice"])]
|
||||
# Avoid CacheMissing
|
||||
for folio in self:
|
||||
if folio.partner_id:
|
||||
addr = folio.partner_id.address_get(["invoice"])
|
||||
if not addr["invoice"] in folio.partner_invoice_ids.ids:
|
||||
folio.partner_invoice_ids = [(4, addr["invoice"])]
|
||||
for reservation in folio.reservation_ids:
|
||||
if reservation.partner_id:
|
||||
addr = reservation.partner_id.address_get(["invoice"])
|
||||
if not addr["invoice"] in folio.partner_invoice_ids.ids:
|
||||
folio.partner_invoice_ids = [(4, addr["invoice"])]
|
||||
for checkin in reservation.checkin_partner_ids:
|
||||
if checkin.partner_id:
|
||||
addr = checkin.partner_id.address_get(["invoice"])
|
||||
if not addr["invoice"] in folio.partner_invoice_ids.ids:
|
||||
folio.partner_invoice_ids = [(4, addr["invoice"])]
|
||||
self.filtered(lambda f: not f.partner_invoice_ids).partner_invoice_ids = False
|
||||
|
||||
@api.depends("partner_id")
|
||||
@@ -1428,6 +1443,11 @@ class PmsFolio(models.Model):
|
||||
% (self.company_id.name, self.company_id.id)
|
||||
)
|
||||
|
||||
if not partner_invoice_id:
|
||||
partner_invoice_id = (
|
||||
self.partner_invoice_ids[0].id if self.partner_invoice_ids else False
|
||||
)
|
||||
|
||||
invoice_vals = {
|
||||
"ref": self.client_order_ref or "",
|
||||
"move_type": "out_invoice",
|
||||
@@ -1437,9 +1457,7 @@ class PmsFolio(models.Model):
|
||||
# 'medium_id': self.medium_id.id,
|
||||
# 'source_id': self.source_id.id,
|
||||
"invoice_user_id": self.user_id and self.user_id.id,
|
||||
"partner_id": partner_invoice_id
|
||||
if partner_invoice_id
|
||||
else self.partner_invoice_ids[0],
|
||||
"partner_id": partner_invoice_id,
|
||||
"partner_bank_id": self.company_id.partner_id.bank_ids[:1].id,
|
||||
"journal_id": journal.id, # company comes from the journal
|
||||
"invoice_origin": self.name,
|
||||
|
||||
@@ -867,3 +867,90 @@ class TestPmsFolio(TestPms):
|
||||
msg="A partner can be added to the folio",
|
||||
):
|
||||
several_partners_wizard.add_partner()
|
||||
|
||||
def test_add_partner_invoice_contact(self):
|
||||
"""
|
||||
Check that when adding a customer at check-in, reservation or folio,
|
||||
it is added as a possible billing address
|
||||
---------------
|
||||
Three res.partner are created with name, email and mobile. A folio is created.
|
||||
We add the partners to the folio, reservation, and checkin, and check that the
|
||||
three partners are on partner_invoice in folio.
|
||||
"""
|
||||
# ARRANGE
|
||||
partner1 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Serafín Rivas",
|
||||
"email": "serafin@example.com",
|
||||
"mobile": "60595595",
|
||||
}
|
||||
)
|
||||
partner2 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Simon",
|
||||
"mobile": "654667733",
|
||||
"email": "simon@example.com",
|
||||
}
|
||||
)
|
||||
partner3 = self.env["res.partner"].create(
|
||||
{
|
||||
"name": "Sofia",
|
||||
"mobile": "688667733",
|
||||
"email": "sofia@example.com",
|
||||
}
|
||||
)
|
||||
|
||||
# FIRST ACTION
|
||||
folio1 = self.env["pms.folio"].create(
|
||||
{
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"partner_name": partner1.name,
|
||||
"email": partner1.email,
|
||||
}
|
||||
)
|
||||
reservation1 = self.env["pms.reservation"].create(
|
||||
{
|
||||
"checkin": datetime.datetime.now(),
|
||||
"checkout": datetime.datetime.now() + datetime.timedelta(days=1),
|
||||
"adults": 2,
|
||||
"room_type_id": self.room_type_double.id,
|
||||
"folio_id": folio1.id,
|
||||
}
|
||||
)
|
||||
|
||||
# FIRST ASSERT
|
||||
self.assertEqual(
|
||||
len(folio1.partner_invoice_ids),
|
||||
0,
|
||||
"A partner was added as a billing contact for no reason",
|
||||
)
|
||||
|
||||
# SECOND ACTION
|
||||
folio1.partner_id = partner1.id
|
||||
|
||||
# SECOND ASSERT
|
||||
self.assertEqual(
|
||||
folio1.partner_invoice_ids.ids,
|
||||
[partner1.id],
|
||||
"A folio partner was not added as a billing contact",
|
||||
)
|
||||
|
||||
# SECOND ACTION
|
||||
reservation1.partner_id = partner2.id
|
||||
|
||||
# SECOND ASSERT
|
||||
self.assertIn(
|
||||
partner2.id,
|
||||
folio1.partner_invoice_ids.ids,
|
||||
"A reservation partner was not added as a billing contact",
|
||||
)
|
||||
|
||||
# THIRD ACTION
|
||||
reservation1.checkin_partner_ids[0].partner_id = partner3.id
|
||||
|
||||
# THIRD ASSERT
|
||||
self.assertIn(
|
||||
partner3.id,
|
||||
folio1.partner_invoice_ids.ids,
|
||||
"A checkin partner was not added as a billing contact",
|
||||
)
|
||||
|
||||
@@ -178,7 +178,9 @@
|
||||
class="row pb-2 pt-3 #{'card-header bg-white' if report_type == 'html' else ''}"
|
||||
>
|
||||
<div class="col-xs-6">
|
||||
<t t-if="folio.partner_invoice_ids[0] != folio.partner_id">
|
||||
<t
|
||||
t-if="folio.partner_invoice_ids and folio.partner_invoice_ids[0] != folio.partner_id"
|
||||
>
|
||||
<div
|
||||
t-field="folio.partner_invoice_ids"
|
||||
t-options='{"widget": "contact", "fields": ["address", "name", "phone"], "no_marker": True, "phone_icons": True}'
|
||||
@@ -186,15 +188,22 @@
|
||||
</t>
|
||||
</div>
|
||||
<div class="col-xs-5 col-xs-offset-1">
|
||||
<div
|
||||
t-field="folio.partner_id"
|
||||
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}'
|
||||
/>
|
||||
<p t-if="folio.partner_id.vat">
|
||||
<t t-esc="folio.company_id.country_id.vat_label or 'TIN'" />
|
||||
:
|
||||
<span t-field="folio.partner_id.vat" />
|
||||
</p>
|
||||
<t t-if="folio.partner_id">
|
||||
<div
|
||||
t-field="folio.partner_id"
|
||||
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}'
|
||||
/>
|
||||
<p t-if="folio.partner_id.vat">
|
||||
<t
|
||||
t-esc="folio.company_id.country_id.vat_label or 'TIN'"
|
||||
/>
|
||||
:
|
||||
<span t-field="folio.partner_id.vat" />
|
||||
</p>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<div t-field="folio.partner_name" />
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
@@ -230,10 +239,10 @@
|
||||
t-options='{"widget": "date"}'
|
||||
/>
|
||||
</div>
|
||||
<div t-if="folio.user_id.name" class="mb-3 col-6">
|
||||
<!-- <div t-if="folio.user_id.name" class="mb-3 col-6">
|
||||
<strong>Salesperson:</strong>
|
||||
<p class="m-0" t-field="folio.user_id" />
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- Is there a discount on at least one line? -->
|
||||
|
||||
@@ -268,7 +268,6 @@
|
||||
attrs="{'invisible':[('state','not in',('cancel'))]}"
|
||||
/>
|
||||
<field name="internal_comment" />
|
||||
<field name="user_id" />
|
||||
</group>
|
||||
<group
|
||||
colspan="2"
|
||||
|
||||
@@ -127,7 +127,10 @@ class FolioAdvancePaymentInv(models.TransientModel):
|
||||
"active_id", False
|
||||
):
|
||||
folio = self.env["pms.folio"].browse(self._context.get("active_id", []))
|
||||
return folio.partner_invoice_ids[0]
|
||||
if folio.partner_invoice_ids:
|
||||
return folio.partner_invoice_ids[0]
|
||||
else:
|
||||
return False
|
||||
|
||||
def _get_advance_details(self, order):
|
||||
context = {"lang": order.partner_id.lang}
|
||||
|
||||
Reference in New Issue
Block a user