[WIP] Payments Notifications

This commit is contained in:
Dario Lodeiros
2019-03-12 16:53:34 +01:00
parent 1567820bef
commit 20b6de582b
8 changed files with 91 additions and 32 deletions

View File

@@ -16,6 +16,7 @@
'sale_stock',
'account_payment_return',
'partner_firstname',
'account_cancel'
],
'license': "AGPL-3",
'demo': ['data/hotel_demo.xml'],

View File

@@ -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'):

View File

@@ -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)

View File

@@ -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()

View File

@@ -428,7 +428,7 @@
decoration-success="folio_pending_amount == 0 and checkout <= current_date and not overbooking"
decoration-warning="overbooking">
<field name="splitted" invisible="1" />
<field name="pricelist_id" invisible="1" />
<field name="pricelist_id" invisible="1" />
<button icon="fa fa-1x fa-chain-broken"
type="object"
class="oe_stat_button"

View File

@@ -7,6 +7,9 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='communication']" position="after">
<field name="folio_id"/>
<field name="save_amount" invisible="1"/>
<field name="save_journal" invisible="1"/>
<field name="save_date" invisible="1"/>
</xpath>
</field>
</record>
@@ -19,6 +22,15 @@
<header>
<button name="post" class="oe_highlight" states="draft" string="Confirm" type="object"/>
<button name="action_draft" class="oe_highlight" states="cancelled" string="Set To Draft" type="object"/>
<button string="Validate" name="post" type="object" class="btn-primary"
attrs="{'invisible': [('state','!=','draft')]}"/>
<button string="Modify" name="modify" type="object" class="btn-primary"
attrs="{'invisible': [('state','=','draft')]}"/>
<button string="Return" name="return_payment_folio" type="object" class="btn-primary"
attrs="{'invisible': [('state','=','draft')]}"/>
<button string="Delete" name="delete" type="object" class="btn-primary"
attrs="{'invisible': [('state','=','draft')]}"/>
<button string="Cancel" class="btn-default" special="cancel"/>
<field name="state" widget="statusbar" statusbar_visible="draft,posted,reconciled,cancelled"/>
</header>
<sheet>
@@ -44,36 +56,31 @@
<group>
<group>
<field name="payment_type" invisible="1"/>
<field name="save_amount" invisible="1"/>
<field name="save_date" invisible="1"/>
<field name="save_journal_id" invisible="1"/>
<field name="partner_type" widget="selection" invisible="1"/>
<field name="partner_id" attrs="{'required': [('state', '=', 'draft'), ('payment_type', 'in', ('inbound', 'outbound'))], 'invisible': [('payment_type', 'not in', ('inbound', 'outbound'))], 'readonly': [('state', '!=', 'draft')]}" context="{'default_is_company': True, 'default_supplier': payment_type == 'outbound', 'default_customer': payment_type == 'inbound'}"/>
<field name="partner_id" attrs="{'required': [('state', '=', 'draft'), ('payment_type', 'in', ('inbound', 'outbound'))], 'invisible': [('payment_type', 'not in', ('inbound', 'outbound'))]}" context="{'default_is_company': True, 'default_supplier': payment_type == 'outbound', 'default_customer': payment_type == 'inbound'}"/>
<label for="amount"/>
<div name="amount_div" class="o_row">
<field name="amount" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="amount" />
<field name="currency_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_currency" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
</div>
<field name="journal_id" widget="selection" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="journal_id" widget="selection" />
<field name="destination_journal_id" widget="selection" attrs="{'required': [('payment_type', '=', 'transfer')], 'invisible': [('payment_type', '!=', 'transfer')], 'readonly': [('state', '!=', 'draft')]}"/>
<field name="hide_payment_method" invisible="1"/>
<field name="payment_method_id" string=" " widget="radio" attrs="{'invisible': [('hide_payment_method', '=', True)], 'readonly': [('state', '!=', 'draft')]}"/>
<field name="payment_method_id" string=" " widget="radio" attrs="{'invisible': [('hide_payment_method', '=', True)]}"/>
<field name="payment_method_code" invisible="1"/>
</group>
<group>
<field name="payment_date" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="communication" attrs="{'invisible': [('state', '!=', 'draft'), ('communication', '=', False)], 'readonly': [('state', '!=', 'draft')]}"/>
<field name="folio_id"/>
<field name="payment_date" />
<field name="communication" attrs="{'invisible': [('state', '!=', 'draft'), ('communication', '=', False)]}"/>
<field name="folio_id" readonly="1" force_save="1"/>
</group>
</group>
</sheet>
<footer>
<button string="Validate" name="post" type="object" class="btn-primary"
attrs="{'invisible': [('state','!=','draft')]}"/>
<button string="Modify" name="modify" type="object" class="btn-primary"
attrs="{'invisible': [('state','=','draft')]}"/>
<button string="Return" name="return_payment_folio" type="object" class="btn-primary"
attrs="{'invisible': [('state','=','draft')]}"/>
<button string="Delete" name="delete" type="object" class="btn-primary"
attrs="{'invisible': [('state','=','draft')]}"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>

View File

@@ -155,7 +155,7 @@
}
.hcal-restriction-room-day {
background-color: #b3218366 !important;
background-color: #9b18704d !important;
}
.hcal-table-day {

View File

@@ -60,7 +60,18 @@ class HotelReservation(models.Model):
if user.has_group('hotel.group_hotel_call'):
self.write({'to_assign': True})
<<<<<<< b9c294db6ea8fe0ebb7998209a7a905c3c240082
return super(HotelReservation, self).action_cancel()
=======
res = super(HotelReservation, self).action_cancel()
for record in self:
# Only can cancel reservations created directly in wubook
for binding in record.channel_bind_ids:
if binding.external_id and not binding.ota_id and \
int(binding.channel_status) in WUBOOK_STATUS_GOOD:
self.sudo().env['channel.hotel.reservation']._event('on_record_cancel').notify(binding)
return res
>>>>>>> [WIP] Payments Notifications
@api.multi
def confirm(self):