From e3b642d832ed28a32b4d5a5a8b50b7a50ee9358e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Tue, 12 Oct 2021 19:44:03 +0200 Subject: [PATCH 1/5] [IMP]pms: payments and statements uses --- pms/models/account_payment.py | 160 +++++++++++++++------------- pms/models/payment_transaction.py | 22 ++++ pms/models/pms_folio.py | 71 +++++++++--- pms/views/account_payment_views.xml | 2 +- pms/views/pms_folio_views.xml | 34 ++++++ 5 files changed, 203 insertions(+), 86 deletions(-) create mode 100644 pms/models/payment_transaction.py diff --git a/pms/models/account_payment.py b/pms/models/account_payment.py index 271dacaf2..197b7c575 100644 --- a/pms/models/account_payment.py +++ b/pms/models/account_payment.py @@ -1,88 +1,104 @@ # Copyright 2017 Dario Lodeiros # 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): _inherit = "account.payment" # Fields declaration - folio_id = fields.Many2one( - string="Folio Reference", - help="Folio in account payment", + folio_ids = fields.Many2many( + string="Folios", 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 - def modify(self): - self.cancel() - vals = { - "journal_id": self.journal_id, - "partner_id": self.partner_id, - "amount": self.amount, - "payment_date": self.payment_date, - "communication": self.communication, - "state": "draft", - } - self.update(vals) - self.with_context({"ignore_notification_post": True}).post() - self._compute_folio_amount() - if self.folio_id: - msg = _("Payment %s modified: \n") % (self.communication) - if self.save_amount and self.save_amount != self.amount: - msg += _("Amount from %s to %s %s \n") % ( - self.save_amount, - self.amount, - self.currency_id.symbol, - ) - if self.save_date and 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: - msg += _("Journal from %s to %s") % ( - self.env["account.journal"].browse(self.save_journal_id).name, - self.journal_id.name, - ) - self.folio_id.message_post(subject=_("Payment"), body=msg) + # def modify(self): + # self.cancel() + # vals = { + # "journal_id": self.journal_id, + # "partner_id": self.partner_id, + # "amount": self.amount, + # "payment_date": self.payment_date, + # "communication": self.communication, + # "state": "draft", + # } + # self.update(vals) + # self.with_context({"ignore_notification_post": True}).post() + # self._compute_folio_amount() + # if self.folio_id: + # msg = _("Payment %s modified: \n") % (self.communication) + # if self.save_amount and self.save_amount != self.amount: + # msg += _("Amount from %s to %s %s \n") % ( + # self.save_amount, + # self.amount, + # self.currency_id.symbol, + # ) + # if self.save_date and 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: + # msg += _("Journal from %s to %s") % ( + # self.env["account.journal"].browse(self.save_journal_id).name, + # self.journal_id.name, + # ) + # self.folio_id.message_post(subject=_("Payment"), body=msg) - def delete(self): - msg = False - if self.folio_id: - msg = _("Deleted payment: %s %s ") % (self.amount, self.currency_id.symbol) - self.cancel() - self.move_name = "" - self.unlink() - if msg: - self.folio_id.message_post(subject=_("Payment Deleted"), body=msg) + # def delete(self): + # msg = False + # if self.folio_id: + # msg = _("Deleted payment: %s %s ") % (self.amount, self.currency_id.symbol) + # self.cancel() + # self.move_name = "" + # self.unlink() + # if msg: + # self.folio_id.message_post(subject=_("Payment Deleted"), body=msg) - def post(self): - rec = super(AccountPayment, self).post() - if rec and not self._context.get("ignore_notification_post", False): - for pay in self: - if pay.folio_id: - msg = _( - "Payment of %s %s registered from %s \ - using %s payment method" - ) % ( - pay.amount, - pay.currency_id.symbol, - pay.communication, - pay.journal_id.name, - ) - pay.folio_id.message_post(subject=_("Payment"), body=msg) + # def post(self): + # rec = super(AccountPayment, self).post() + # if rec and not self._context.get("ignore_notification_post", False): + # for pay in self: + # if pay.folio_id: + # msg = _( + # "Payment of %s %s registered from %s \ + # using %s payment method" + # ) % ( + # pay.amount, + # pay.currency_id.symbol, + # pay.communication, + # pay.journal_id.name, + # ) + # pay.folio_id.message_post(subject=_("Payment"), body=msg) - def modify_payment(self): - self.ensure_one() - view_form_id = self.env.ref("pms.account_payment_view_form_folio").id - # moves = self.mapped('move_ids.id') - return { - "name": _("Payment"), - "view_type": "form", - "views": [(view_form_id, "form")], - "view_mode": "tree,form", - "res_model": "account.payment", - "target": "new", - "init_mode": "edit", - "type": "ir.actions.act_window", - "res_id": self.id, - } + # def modify_payment(self): + # self.ensure_one() + # view_form_id = self.env.ref("pms.account_payment_view_form_folio").id + # # moves = self.mapped('move_ids.id') + # return { + # "name": _("Payment"), + # "view_type": "form", + # "views": [(view_form_id, "form")], + # "view_mode": "tree,form", + # "res_model": "account.payment", + # "target": "new", + # "init_mode": "edit", + # "type": "ir.actions.act_window", + # "res_id": self.id, + # } diff --git a/pms/models/payment_transaction.py b/pms/models/payment_transaction.py new file mode 100644 index 000000000..ca61bc106 --- /dev/null +++ b/pms/models/payment_transaction.py @@ -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) diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index b49ecaab5..f6398d850 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -181,6 +181,7 @@ class PmsFolio(models.Model): ) transaction_ids = fields.Many2many( string="Transactions", + help="Payments made through payment acquirer", readonly=True, copy=False, comodel_name="payment.transaction", @@ -188,9 +189,29 @@ class PmsFolio(models.Model): column1="folio_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( string="Payment Terms", - help="Pricelist for current folio.", + help="Payment terms for current folio.", readonly=False, store=True, comodel_name="account.payment.term", @@ -1481,19 +1502,43 @@ class PmsFolio(models.Model): services=False, partner=False, date=False, + type=False, ): - line = self._get_statement_line_vals( - journal=journal, - receivable_account=receivable_account, - user=user, - amount=amount, - folios=folio, - reservations=reservations, - services=services, - partner=partner, - date=date, - ) - self.env["account.bank.statement.line"].sudo().create(line) + """ + create folio payment + type: set cash to use statement or bank to use account.payment, + by default, use the journal type + """ + if not type: + type = journal.type + if type == "cash": + line = self._get_statement_line_vals( + journal=journal, + receivable_account=receivable_account, + 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( body=_( """Payment: %s by %s""", diff --git a/pms/views/account_payment_views.xml b/pms/views/account_payment_views.xml index d28522193..161f2b19f 100644 --- a/pms/views/account_payment_views.xml +++ b/pms/views/account_payment_views.xml @@ -5,7 +5,7 @@ - + diff --git a/pms/views/pms_folio_views.xml b/pms/views/pms_folio_views.xml index 686605043..e28776af9 100644 --- a/pms/views/pms_folio_views.xml +++ b/pms/views/pms_folio_views.xml @@ -533,6 +533,40 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + From 7d2b4715034e47e183a7abb1ccdb01d3e1a5bb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Tue, 12 Oct 2021 19:44:52 +0200 Subject: [PATCH 2/5] [IMP]pms: payments and statements uses --- pms/models/pms_folio.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index f6398d850..169e6d8a5 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -1502,16 +1502,16 @@ class PmsFolio(models.Model): services=False, partner=False, date=False, - type=False, + pay_type=False, ): """ create folio payment type: set cash to use statement or bank to use account.payment, by default, use the journal type """ - if not type: - type = journal.type - if type == "cash": + if not pay_type: + pay_type = journal.type + if pay_type == "cash": line = self._get_statement_line_vals( journal=journal, receivable_account=receivable_account, From 00cef25ec129ea61edb6cbd171872e833baf2c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Tue, 12 Oct 2021 19:59:39 +0200 Subject: [PATCH 3/5] [IMP]pms: journal filter manual payment allowed --- pms/models/account_journal.py | 4 ++++ pms/models/pms_property.py | 1 + pms/views/account_journal_views.xml | 1 + 3 files changed, 6 insertions(+) diff --git a/pms/models/account_journal.py b/pms/models/account_journal.py index ca1266390..c7afb21cf 100644 --- a/pms/models/account_journal.py +++ b/pms/models/account_journal.py @@ -19,3 +19,7 @@ class AccountJournal(models.Model): help="The company for Account Jouarnal", check_pms_properties=True, ) + allowed_pms_payments = fields.Boolean( + string="For manual payments", + help="Use to pay for reservations", + ) diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index 4069b5ab9..27dcfcb56 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -408,6 +408,7 @@ class PmsProperty(models.Model): self.ensure_one() payment_methods = self.env["account.journal"].search( [ + ("allowed_pms_payments", "=", True), "&", ("type", "in", ["cash", "bank"]), "|", diff --git a/pms/views/account_journal_views.xml b/pms/views/account_journal_views.xml index 0dfa4250c..f787708c8 100644 --- a/pms/views/account_journal_views.xml +++ b/pms/views/account_journal_views.xml @@ -6,6 +6,7 @@ + From 1a1e32882505db7be8b9eafbecff0329d787ed47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Tue, 12 Oct 2021 20:11:29 +0200 Subject: [PATCH 4/5] [WIP]pms: payment type test cases --- pms/tests/test_pms_payment.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pms/tests/test_pms_payment.py b/pms/tests/test_pms_payment.py index 9b7948450..5f3f0d7e6 100644 --- a/pms/tests/test_pms_payment.py +++ b/pms/tests/test_pms_payment.py @@ -8,3 +8,31 @@ freeze_time("2000-02-02") class TestPmsPayment(SavepointCase): def setUp(self): 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 From 61ff2918ef96ef7af82067cc9fad92f8b4185e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sat, 16 Oct 2021 16:04:08 +0200 Subject: [PATCH 5/5] [FIX]pms: tests allowed payments pms journals --- pms/tests/test_pms_folio.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pms/tests/test_pms_folio.py b/pms/tests/test_pms_folio.py index 5a266e9cc..cb772a1b5 100644 --- a/pms/tests/test_pms_folio.py +++ b/pms/tests/test_pms_folio.py @@ -47,6 +47,13 @@ class TestPmsFolio(TestPms): "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): """