From ef4bab656d0e761fdd53cd7b21d190f8ead6c6a6 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Tue, 12 Mar 2019 16:53:34 +0100 Subject: [PATCH 01/22] [WIP] Payments Notifications --- hotel/__manifest__.py | 1 + hotel/models/hotel_folio.py | 14 +++--- hotel/models/inherited_account_payment.py | 46 +++++++++++++++++-- hotel/models/inherited_payment_return.py | 8 +++- hotel/views/hotel_reservation_views.xml | 2 +- .../views/inherited_account_payment_views.xml | 39 +++++++++------- .../src/lib/hcalendar/css/hcalendar.css | 2 +- .../models/hotel_reservation/common.py | 2 +- 8 files changed, 81 insertions(+), 33 deletions(-) diff --git a/hotel/__manifest__.py b/hotel/__manifest__.py index c5f3201a2..dd9d641b8 100644 --- a/hotel/__manifest__.py +++ b/hotel/__manifest__.py @@ -16,6 +16,7 @@ 'sale_stock', 'account_payment_return', 'partner_firstname', + 'account_cancel' ], 'license': "AGPL-3", 'demo': ['data/hotel_demo.xml'], diff --git a/hotel/models/hotel_folio.py b/hotel/models/hotel_folio.py index 06716b2cf..b55c8c4aa 100644 --- a/hotel/models/hotel_folio.py +++ b/hotel/models/hotel_folio.py @@ -101,12 +101,6 @@ class HotelFolio(models.Model): # @api.depends('state', 'product_uom_qty', 'qty_delivered', 'qty_to_invoice', 'qty_invoiced') def _compute_invoice_status(self): pass - # @api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id') - def _compute_amount(self): - pass - # @api.depends('order_line.price_total') - def _amount_all(self): - pass @api.model def _get_default_team(self): @@ -336,13 +330,17 @@ class HotelFolio(models.Model): self.ensure_one() payments_obj = self.env['account.payment'] payments = payments_obj.search([('folio_id', '=', self.id)]) - #invoices = self.mapped('invoice_ids.id') + view_form_id = self.env.ref('hotel.account_payment_view_form_folio').id + view_tree_id = self.env.ref('account.view_account_payment_tree').id + # invoices = self.mapped('invoice_ids.id') return{ 'name': _('Payments'), 'view_type': 'form', + 'views': [(view_tree_id, 'tree'),(view_form_id, 'form')], 'view_mode': 'tree,form', 'res_model': 'account.payment', 'target': 'new', + 'init_mode': 'edit', 'type': 'ir.actions.act_window', 'domain': [('id', 'in', payments.ids)], } @@ -854,7 +852,7 @@ class HotelFolio(models.Model): 'mail_template_reservation_reminder_24hrs')[1] template_rec = self.env['mail.template'].browse(template_id) for reserv_rec in self.search([]): - checkin_date = datetime.strptime(reserv_rec.checkin, DEFAULT_SERVER_DATETIME_FORMAT) + checkin_date = datetime.strptime(reserv_rec.checkin, dt) difference = relativedelta(now_date, checkin_date) if(difference.days == -1 and reserv_rec.partner_id.email and reserv_rec.state == 'confirm'): diff --git a/hotel/models/inherited_account_payment.py b/hotel/models/inherited_account_payment.py index bf3b2ee01..b4f5e2103 100644 --- a/hotel/models/inherited_account_payment.py +++ b/hotel/models/inherited_account_payment.py @@ -11,6 +11,16 @@ class AccountPayment(models.Model): compute="_compute_folio_amount", store=True, string="Total amount in folio", ) + save_amount = fields.Monetary(string='onchange_amount') + save_date = fields.Date() + save_journal_id = fields.Integer() + + @api.onchange('amount','payment_date','journal_id') + def onchange_amount(self): + if self._origin: + self.save_amount = self._origin.amount + self.save_journal_id = self._origin.journal_id.id + self.save_date = self._origin.payment_date """WIP""" @api.multi @@ -32,6 +42,12 @@ class AccountPayment(models.Model): 'line_ids': [(0, 0, return_line_vals)], } return_pay = self.env['payment.return'].create(return_vals) + if self.save_amount: + self.amount = self.save_amount + if self.save_date: + self.payment_date = self.save_date + if self.save_journal_id: + self.journal_id = self.env['account.journal'].browse(self.save_journal_id) return { 'name': 'Folio Payment Return', 'view_type': 'form', @@ -40,6 +56,7 @@ class AccountPayment(models.Model): 'type': 'ir.actions.act_window', 'res_id': return_pay.id, } + @api.multi def modify(self): self.cancel() @@ -49,15 +66,29 @@ class AccountPayment(models.Model): 'amount': self.amount, 'payment_date': self.payment_date, 'communication': self.communication, - 'folio_id': self.folio_id} + 'state': 'draft'} self.update(vals) - self.post() + self.with_context({'ignore_notification_post': True}).post() + 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) @api.multi 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) @api.multi @api.depends('state') @@ -66,8 +97,6 @@ class AccountPayment(models.Model): res = [] fol = () for payment in self: - amount_pending = 0 - total_amount = 0 if payment.folio_id: fol = payment.env['hotel.folio'].search([ ('id', '=', payment.folio_id.id) @@ -82,3 +111,12 @@ class AccountPayment(models.Model): else: fol.compute_amount() return res + + @api.multi + 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) diff --git a/hotel/models/inherited_payment_return.py b/hotel/models/inherited_payment_return.py index bb1c214bc..29cb0ca72 100644 --- a/hotel/models/inherited_payment_return.py +++ b/hotel/models/inherited_payment_return.py @@ -13,10 +13,14 @@ class PaymentReturn(models.Model): pay = super(PaymentReturn,self).action_confirm() if pay: folio_ids = [] + folios = self.env['hotel.folio'].browse(folio_ids) for line in self.line_ids: payments = self.env['account.payment'].search([ ('move_line_ids', 'in', line.move_line_ids.ids) ]) - folio_ids += payments.mapped('folio_id.id') - folios = self.env['hotel.folio'].browse(folio_ids) + folios_line = self.env['hotel.folio'].browse(payments.mapped('folio_id.id')) + for folio in folios_line: + msg = _("Return of %s registered") % (line.amount) + folio.message_post(subject=_('Payment Return'), body=msg) + folios += folios_line folios.compute_amount() diff --git a/hotel/views/hotel_reservation_views.xml b/hotel/views/hotel_reservation_views.xml index 9f1c24678..f23724348 100644 --- a/hotel/views/hotel_reservation_views.xml +++ b/hotel/views/hotel_reservation_views.xml @@ -428,7 +428,7 @@ decoration-success="folio_pending_amount == 0 and checkout <= current_date and not overbooking" decoration-warning="overbooking"> - + - - -