mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
@@ -19,3 +19,7 @@ class AccountJournal(models.Model):
|
|||||||
help="The company for Account Jouarnal",
|
help="The company for Account Jouarnal",
|
||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
)
|
)
|
||||||
|
allowed_pms_payments = fields.Boolean(
|
||||||
|
string="For manual payments",
|
||||||
|
help="Use to pay for reservations",
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,88 +1,104 @@
|
|||||||
# Copyright 2017 Dario Lodeiros
|
# Copyright 2017 Dario Lodeiros
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from odoo import _, fields, models
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class AccountPayment(models.Model):
|
class AccountPayment(models.Model):
|
||||||
_inherit = "account.payment"
|
_inherit = "account.payment"
|
||||||
|
|
||||||
# Fields declaration
|
# Fields declaration
|
||||||
folio_id = fields.Many2one(
|
folio_ids = fields.Many2many(
|
||||||
string="Folio Reference",
|
string="Folios",
|
||||||
help="Folio in account payment",
|
|
||||||
comodel_name="pms.folio",
|
comodel_name="pms.folio",
|
||||||
|
ondelete="cascade",
|
||||||
|
relation="account_payment_folio_rel",
|
||||||
|
column1="payment_id",
|
||||||
|
column2="folio_id",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _prepare_move_line_default_vals(self, write_off_line_vals=None):
|
||||||
|
line_vals_list = super(AccountPayment, self)._prepare_move_line_default_vals(
|
||||||
|
write_off_line_vals
|
||||||
|
)
|
||||||
|
if self.folio_ids:
|
||||||
|
for line in line_vals_list:
|
||||||
|
line.update(
|
||||||
|
{
|
||||||
|
"folio_ids": [(6, 0, self.folio_ids.ids)],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return line_vals_list
|
||||||
|
|
||||||
# Business methods
|
# Business methods
|
||||||
|
|
||||||
def modify(self):
|
# def modify(self):
|
||||||
self.cancel()
|
# self.cancel()
|
||||||
vals = {
|
# vals = {
|
||||||
"journal_id": self.journal_id,
|
# "journal_id": self.journal_id,
|
||||||
"partner_id": self.partner_id,
|
# "partner_id": self.partner_id,
|
||||||
"amount": self.amount,
|
# "amount": self.amount,
|
||||||
"payment_date": self.payment_date,
|
# "payment_date": self.payment_date,
|
||||||
"communication": self.communication,
|
# "communication": self.communication,
|
||||||
"state": "draft",
|
# "state": "draft",
|
||||||
}
|
# }
|
||||||
self.update(vals)
|
# self.update(vals)
|
||||||
self.with_context({"ignore_notification_post": True}).post()
|
# self.with_context({"ignore_notification_post": True}).post()
|
||||||
self._compute_folio_amount()
|
# self._compute_folio_amount()
|
||||||
if self.folio_id:
|
# if self.folio_id:
|
||||||
msg = _("Payment %s modified: \n") % (self.communication)
|
# msg = _("Payment %s modified: \n") % (self.communication)
|
||||||
if self.save_amount and self.save_amount != self.amount:
|
# if self.save_amount and self.save_amount != self.amount:
|
||||||
msg += _("Amount from %s to %s %s \n") % (
|
# msg += _("Amount from %s to %s %s \n") % (
|
||||||
self.save_amount,
|
# self.save_amount,
|
||||||
self.amount,
|
# self.amount,
|
||||||
self.currency_id.symbol,
|
# self.currency_id.symbol,
|
||||||
)
|
# )
|
||||||
if self.save_date and self.save_date != self.payment_date:
|
# if self.save_date and self.save_date != self.payment_date:
|
||||||
msg += _("Date from %s to %s \n") % (self.save_date, self.payment_date)
|
# msg += _("Date from %s to %s \n") % (self.save_date, self.payment_date)
|
||||||
if self.save_journal_id and self.save_journal_id != self.journal_id.id:
|
# if self.save_journal_id and self.save_journal_id != self.journal_id.id:
|
||||||
msg += _("Journal from %s to %s") % (
|
# msg += _("Journal from %s to %s") % (
|
||||||
self.env["account.journal"].browse(self.save_journal_id).name,
|
# self.env["account.journal"].browse(self.save_journal_id).name,
|
||||||
self.journal_id.name,
|
# self.journal_id.name,
|
||||||
)
|
# )
|
||||||
self.folio_id.message_post(subject=_("Payment"), body=msg)
|
# self.folio_id.message_post(subject=_("Payment"), body=msg)
|
||||||
|
|
||||||
def delete(self):
|
# def delete(self):
|
||||||
msg = False
|
# msg = False
|
||||||
if self.folio_id:
|
# if self.folio_id:
|
||||||
msg = _("Deleted payment: %s %s ") % (self.amount, self.currency_id.symbol)
|
# msg = _("Deleted payment: %s %s ") % (self.amount, self.currency_id.symbol)
|
||||||
self.cancel()
|
# self.cancel()
|
||||||
self.move_name = ""
|
# self.move_name = ""
|
||||||
self.unlink()
|
# self.unlink()
|
||||||
if msg:
|
# if msg:
|
||||||
self.folio_id.message_post(subject=_("Payment Deleted"), body=msg)
|
# self.folio_id.message_post(subject=_("Payment Deleted"), body=msg)
|
||||||
|
|
||||||
def post(self):
|
# def post(self):
|
||||||
rec = super(AccountPayment, self).post()
|
# rec = super(AccountPayment, self).post()
|
||||||
if rec and not self._context.get("ignore_notification_post", False):
|
# if rec and not self._context.get("ignore_notification_post", False):
|
||||||
for pay in self:
|
# for pay in self:
|
||||||
if pay.folio_id:
|
# if pay.folio_id:
|
||||||
msg = _(
|
# msg = _(
|
||||||
"Payment of %s %s registered from %s \
|
# "Payment of %s %s registered from %s \
|
||||||
using %s payment method"
|
# using %s payment method"
|
||||||
) % (
|
# ) % (
|
||||||
pay.amount,
|
# pay.amount,
|
||||||
pay.currency_id.symbol,
|
# pay.currency_id.symbol,
|
||||||
pay.communication,
|
# pay.communication,
|
||||||
pay.journal_id.name,
|
# pay.journal_id.name,
|
||||||
)
|
# )
|
||||||
pay.folio_id.message_post(subject=_("Payment"), body=msg)
|
# pay.folio_id.message_post(subject=_("Payment"), body=msg)
|
||||||
|
|
||||||
def modify_payment(self):
|
# def modify_payment(self):
|
||||||
self.ensure_one()
|
# self.ensure_one()
|
||||||
view_form_id = self.env.ref("pms.account_payment_view_form_folio").id
|
# view_form_id = self.env.ref("pms.account_payment_view_form_folio").id
|
||||||
# moves = self.mapped('move_ids.id')
|
# # moves = self.mapped('move_ids.id')
|
||||||
return {
|
# return {
|
||||||
"name": _("Payment"),
|
# "name": _("Payment"),
|
||||||
"view_type": "form",
|
# "view_type": "form",
|
||||||
"views": [(view_form_id, "form")],
|
# "views": [(view_form_id, "form")],
|
||||||
"view_mode": "tree,form",
|
# "view_mode": "tree,form",
|
||||||
"res_model": "account.payment",
|
# "res_model": "account.payment",
|
||||||
"target": "new",
|
# "target": "new",
|
||||||
"init_mode": "edit",
|
# "init_mode": "edit",
|
||||||
"type": "ir.actions.act_window",
|
# "type": "ir.actions.act_window",
|
||||||
"res_id": self.id,
|
# "res_id": self.id,
|
||||||
}
|
# }
|
||||||
|
|||||||
22
pms/models/payment_transaction.py
Normal file
22
pms/models/payment_transaction.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentTransaction(models.Model):
|
||||||
|
_name = "payment.transaction"
|
||||||
|
|
||||||
|
folio_ids = fields.Many2many(
|
||||||
|
string="Folios",
|
||||||
|
comodel_name="pms.folio",
|
||||||
|
ondelete="cascade",
|
||||||
|
relation="account_bank_statement_folio_rel",
|
||||||
|
column1="account_journal_id",
|
||||||
|
column2="folio_id",
|
||||||
|
)
|
||||||
|
|
||||||
|
def _create_payment(self, add_payment_vals=False):
|
||||||
|
self.ensure_one()
|
||||||
|
if not add_payment_vals:
|
||||||
|
add_payment_vals = {}
|
||||||
|
if self.folio_ids:
|
||||||
|
add_payment_vals["folio_ids"] = [(6, 0, self.folio_ids.ids)]
|
||||||
|
return super(PaymentTransaction, self)._create_payment(add_payment_vals)
|
||||||
@@ -181,6 +181,7 @@ class PmsFolio(models.Model):
|
|||||||
)
|
)
|
||||||
transaction_ids = fields.Many2many(
|
transaction_ids = fields.Many2many(
|
||||||
string="Transactions",
|
string="Transactions",
|
||||||
|
help="Payments made through payment acquirer",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
copy=False,
|
copy=False,
|
||||||
comodel_name="payment.transaction",
|
comodel_name="payment.transaction",
|
||||||
@@ -188,9 +189,29 @@ class PmsFolio(models.Model):
|
|||||||
column1="folio_id",
|
column1="folio_id",
|
||||||
column2="transaction_id",
|
column2="transaction_id",
|
||||||
)
|
)
|
||||||
|
payment_ids = fields.Many2many(
|
||||||
|
string="Bank Payments",
|
||||||
|
help="Payments made by bank direct",
|
||||||
|
readonly=True,
|
||||||
|
copy=False,
|
||||||
|
comodel_name="account.payment",
|
||||||
|
relation="account_payment_folio_rel",
|
||||||
|
column1="folio_id",
|
||||||
|
column2="payment_id",
|
||||||
|
)
|
||||||
|
statement_line_ids = fields.Many2many(
|
||||||
|
string="Cash Payments",
|
||||||
|
help="Payments made by cash",
|
||||||
|
readonly=True,
|
||||||
|
copy=False,
|
||||||
|
comodel_name="account.bank.statement.line",
|
||||||
|
relation="account_bank_statement_folio_rel",
|
||||||
|
column1="folio_id",
|
||||||
|
column2="account_journal_id",
|
||||||
|
)
|
||||||
payment_term_id = fields.Many2one(
|
payment_term_id = fields.Many2one(
|
||||||
string="Payment Terms",
|
string="Payment Terms",
|
||||||
help="Pricelist for current folio.",
|
help="Payment terms for current folio.",
|
||||||
readonly=False,
|
readonly=False,
|
||||||
store=True,
|
store=True,
|
||||||
comodel_name="account.payment.term",
|
comodel_name="account.payment.term",
|
||||||
@@ -1483,19 +1504,43 @@ class PmsFolio(models.Model):
|
|||||||
services=False,
|
services=False,
|
||||||
partner=False,
|
partner=False,
|
||||||
date=False,
|
date=False,
|
||||||
|
pay_type=False,
|
||||||
):
|
):
|
||||||
line = self._get_statement_line_vals(
|
"""
|
||||||
journal=journal,
|
create folio payment
|
||||||
receivable_account=receivable_account,
|
type: set cash to use statement or bank to use account.payment,
|
||||||
user=user,
|
by default, use the journal type
|
||||||
amount=amount,
|
"""
|
||||||
folios=folio,
|
if not pay_type:
|
||||||
reservations=reservations,
|
pay_type = journal.type
|
||||||
services=services,
|
if pay_type == "cash":
|
||||||
partner=partner,
|
line = self._get_statement_line_vals(
|
||||||
date=date,
|
journal=journal,
|
||||||
)
|
receivable_account=receivable_account,
|
||||||
self.env["account.bank.statement.line"].sudo().create(line)
|
user=user,
|
||||||
|
amount=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,
|
||||||
|
"date": fields.Date.today(),
|
||||||
|
"ref": folio.name,
|
||||||
|
"folio_ids": [(6, 0, [folio.id])],
|
||||||
|
"payment_type": "inbound",
|
||||||
|
"partner_type": "customer",
|
||||||
|
"state": "draft",
|
||||||
|
}
|
||||||
|
pay = self.env["account.payment"].create(vals)
|
||||||
|
pay.action_post()
|
||||||
|
|
||||||
folio.message_post(
|
folio.message_post(
|
||||||
body=_(
|
body=_(
|
||||||
"""Payment: <b>%s</b> by <b>%s</b>""",
|
"""Payment: <b>%s</b> by <b>%s</b>""",
|
||||||
|
|||||||
@@ -408,6 +408,7 @@ class PmsProperty(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
payment_methods = self.env["account.journal"].search(
|
payment_methods = self.env["account.journal"].search(
|
||||||
[
|
[
|
||||||
|
("allowed_pms_payments", "=", True),
|
||||||
"&",
|
"&",
|
||||||
("type", "in", ["cash", "bank"]),
|
("type", "in", ["cash", "bank"]),
|
||||||
"|",
|
"|",
|
||||||
|
|||||||
@@ -47,6 +47,13 @@ class TestPmsFolio(TestPms):
|
|||||||
"capacity": 2,
|
"capacity": 2,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
# make current journals payable
|
||||||
|
journals = self.env["account.journal"].search(
|
||||||
|
[
|
||||||
|
("type", "in", ["bank", "cash"]),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
journals.allowed_pms_payments = True
|
||||||
|
|
||||||
def create_sale_channel_scenario(self):
|
def create_sale_channel_scenario(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -8,3 +8,31 @@ freeze_time("2000-02-02")
|
|||||||
class TestPmsPayment(SavepointCase):
|
class TestPmsPayment(SavepointCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestPmsPayment, self).setUp()
|
super(TestPmsPayment, self).setUp()
|
||||||
|
|
||||||
|
# TODO: Test allowed manual payment
|
||||||
|
# create a journal with allowed_pms_payments = True and
|
||||||
|
# check that the _get_payment_methods property method return it
|
||||||
|
|
||||||
|
# TODO: Test not allowed manual payment
|
||||||
|
# create a journal without allowed_pms_payments = True and
|
||||||
|
# check that the _get_payment_methods property method dont return it
|
||||||
|
|
||||||
|
# TODO: Test default account payment create
|
||||||
|
# create a bank journal, a reservation, pay the reservation
|
||||||
|
# with do_payment method without pay_type parameter
|
||||||
|
# and check that account payment was created
|
||||||
|
|
||||||
|
# TODO: Test default statement line create
|
||||||
|
# create a cash journal, a reservation, pay the reservation
|
||||||
|
# with do_payment method without pay_type parameter
|
||||||
|
# and check that statement line was created
|
||||||
|
|
||||||
|
# TODO: Test set pay_type cash, statement line create
|
||||||
|
# create a bank journal, a reservation, pay the reservation
|
||||||
|
# with do_payment method with 'cash' pay_type parameter
|
||||||
|
# and check that statement line was created
|
||||||
|
|
||||||
|
# TODO: Test set pay_type bank, account payment create
|
||||||
|
# create a cash journal, a reservation, pay the reservation
|
||||||
|
# with do_payment method with 'bank' pay_type parameter
|
||||||
|
# and check that account payment was created
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='company_id']" position="after">
|
<xpath expr="//field[@name='company_id']" position="after">
|
||||||
<field name="pms_property_ids" widget="many2many_tags" />
|
<field name="pms_property_ids" widget="many2many_tags" />
|
||||||
|
<field name="allowed_pms_payments" />
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<field name="inherit_id" ref="account.view_account_payment_form" />
|
<field name="inherit_id" ref="account.view_account_payment_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='date']" position="after">
|
<xpath expr="//field[@name='date']" position="after">
|
||||||
<field name="folio_id" />
|
<field name="folio_ids" />
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
@@ -533,6 +533,40 @@
|
|||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
|
<page string="Payments">
|
||||||
|
<separator string="Cash" colspan="4" />
|
||||||
|
<field name="statement_line_ids" nolabel="1">
|
||||||
|
<tree>
|
||||||
|
<field name="journal_id" string="Payment Mode" />
|
||||||
|
<field name="date" />
|
||||||
|
<field name="amount" />
|
||||||
|
<field name="partner_id" invisible="1" />
|
||||||
|
<field name="state" invisible="1" />
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
<separator string="Bank" colspan="4" />
|
||||||
|
<field name="payment_ids" nolabel="1">
|
||||||
|
<tree>
|
||||||
|
<field name="journal_id" string="Payment Mode" />
|
||||||
|
<field name="date" />
|
||||||
|
<field name="amount" />
|
||||||
|
<field name="partner_id" invisible="1" />
|
||||||
|
<field name="state" invisible="1" />
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
<!-- REVIEW: transations has a payment related -->
|
||||||
|
<!-- <field
|
||||||
|
name="transaction_ids"
|
||||||
|
nolabel="1"
|
||||||
|
>
|
||||||
|
<tree>
|
||||||
|
<field name="journal_id" />
|
||||||
|
<field name="date" />
|
||||||
|
<field name="amount" />
|
||||||
|
<field name="partner_id" />
|
||||||
|
</tree>
|
||||||
|
</field> -->
|
||||||
|
</page>
|
||||||
<page string="Other data">
|
<page string="Other data">
|
||||||
<group>
|
<group>
|
||||||
<field name="user_id" />
|
<field name="user_id" />
|
||||||
|
|||||||
Reference in New Issue
Block a user