mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]pms: folio refund method
This commit is contained in:
@@ -1747,6 +1747,71 @@ class PmsFolio(models.Model):
|
||||
)
|
||||
return True
|
||||
|
||||
def do_refund(
|
||||
self,
|
||||
journal,
|
||||
receivable_account,
|
||||
user,
|
||||
amount,
|
||||
folio,
|
||||
reservations=False,
|
||||
services=False,
|
||||
partner=False,
|
||||
date=False,
|
||||
pay_type=False,
|
||||
):
|
||||
"""
|
||||
create folio refund
|
||||
type: set cash to use statement or bank to use account.payment,
|
||||
by default, use the journal type
|
||||
"""
|
||||
if not pay_type:
|
||||
pay_type = journal.type
|
||||
if pay_type == "cash":
|
||||
line = self._get_statement_line_vals(
|
||||
journal=journal,
|
||||
receivable_account=receivable_account,
|
||||
user=user,
|
||||
amount=amount if amount < 0 else -amount,
|
||||
folios=folio,
|
||||
reservations=reservations,
|
||||
services=services,
|
||||
partner=partner,
|
||||
date=date,
|
||||
)
|
||||
self.env["account.bank.statement.line"].sudo().create(line)
|
||||
else:
|
||||
vals = {
|
||||
"journal_id": journal.id,
|
||||
"partner_id": partner.id,
|
||||
"amount": amount if amount > 0 else -amount,
|
||||
"date": fields.Date.today(),
|
||||
"ref": folio.name,
|
||||
"folio_ids": [(6, 0, [folio.id])],
|
||||
"payment_type": "outbound",
|
||||
"partner_type": "customer",
|
||||
"state": "draft",
|
||||
}
|
||||
pay = self.env["account.payment"].create(vals)
|
||||
pay.action_post()
|
||||
|
||||
folio.message_post(
|
||||
body=_(
|
||||
"""Refund: <b>%s</b> by <b>%s</b>""",
|
||||
amount,
|
||||
journal.display_name,
|
||||
)
|
||||
)
|
||||
for reservation in folio.reservation_ids:
|
||||
reservation.message_post(
|
||||
body=_(
|
||||
"""Refund: <b>%s</b> by <b>%s</b>""",
|
||||
amount,
|
||||
journal.display_name,
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
def open_wizard_several_partners(self):
|
||||
ctx = dict(
|
||||
folio_id=self.id,
|
||||
|
||||
Reference in New Issue
Block a user