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 @@ /> + + + + + + + + + + + + + + + + + + + + + + + +