98 lines
4.4 KiB
Python
98 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import models, fields, api, _
|
|
|
|
|
|
class AddPayments(models.TransientModel):
|
|
_name = "add.payments.wizard"
|
|
_description = "Add Payments Wizard"
|
|
|
|
payment_type = fields.Many2one(comodel_name="hms.payment.types", string="Payment Type")
|
|
|
|
@api.model
|
|
def _transaction_domain(self):
|
|
return [('status_code_id', '=', self.env.ref('bross_bank_management.transaction_code_3').id)]
|
|
|
|
transaction_id = fields.Many2one(comodel_name="brosse.bank.transactions", domain=_transaction_domain, string="Bank Transaction")
|
|
pending_transcation = fields.Boolean(string="Pending Transaction")
|
|
|
|
amount_gel = fields.Monetary(string="Amount GEL", currency_field='gel_currency_id')
|
|
gel_currency_id = fields.Many2one('res.currency', string='Gel Currency', default=lambda self: self.env['res.currency'].search([('name', '=', 'GEL')]).id)
|
|
show_amount_gel = fields.Boolean(string="Show Amount GEL")
|
|
|
|
amount = fields.Monetary(string="Amount", currency_field='currency_id')
|
|
currency_id = fields.Many2one('res.currency', string='Currency', default=lambda self: self.env['res.currency'].search([('name', '=', 'GEL')]).id)
|
|
|
|
exchange_rate = fields.Float(string="Exchange Rate")
|
|
hide_exchange_rate = fields.Boolean(string="Hide Exchange Rate")
|
|
|
|
booking_id = fields.Many2one(comodel_name="hms.bookings", string="Booking ID")
|
|
|
|
expected_payment = fields.Monetary(string="Expected Payment", currency_field='expected_payment_currency')
|
|
expected_payment_currency = fields.Many2one('res.currency', string='Expected Payment Currency')
|
|
|
|
pos_terminal_code = fields.Char(string="POS Terminal Code")
|
|
wire_transfer_code = fields.Char(string="Wire Transfer Code")
|
|
|
|
@api.onchange('payment_type')
|
|
def onchange_payment_type(self):
|
|
if self.payment_type == self.env.ref('bross_hms.payment_type_1'):
|
|
self.pending_transcation = True
|
|
if self.payment_type == self.env.ref('bross_hms.payment_type_0') or not self.payment_type:
|
|
self.pending_transcation = False
|
|
|
|
@api.onchange('transaction_id')
|
|
def onchange_transaction_id(self):
|
|
if self.transaction_id:
|
|
self.amount = self.transaction_id.amount
|
|
self.currency_id = self.transaction_id.currency_id
|
|
|
|
@api.onchange('currency_id')
|
|
def onchange_currency_id(self):
|
|
if self.currency_id:
|
|
gel_currency = self.env['res.currency'].search([('name', '=', 'GEL')])
|
|
if self.currency_id.id == gel_currency.id:
|
|
self.exchange_rate = 1.0
|
|
self.amount_gel = self.amount
|
|
self.hide_exchange_rate = True
|
|
else:
|
|
self.exchange_rate = self.currency_id.rate_ids.sorted('id', reverse=True)[0].rate
|
|
self.amount_gel = self.amount * self.exchange_rate
|
|
self.show_amount_gel = True
|
|
self.hide_exchange_rate = False
|
|
|
|
@api.onchange('exchange_rate')
|
|
def onchange_exchange_rate(self):
|
|
if self.exchange_rate:
|
|
self.amount_gel = self.amount * self.exchange_rate
|
|
|
|
def add_payments(self):
|
|
for rec in self:
|
|
if rec.payment_type == self.env.ref('bross_hms.payment_type_0'):
|
|
pending_transcation = False
|
|
transaction_id = False
|
|
pos_terminal_code = False
|
|
wire_transfer_code = False
|
|
elif rec.payment_type == self.env.ref('bross_hms.payment_type_1'):
|
|
pending_transcation = rec.pending_transcation
|
|
transaction_id = False
|
|
pos_terminal_code = rec.pos_terminal_code
|
|
wire_transfer_code = False
|
|
else:
|
|
pending_transcation = rec.pending_transcation
|
|
transaction_id = rec.transaction_id.id if rec.transaction_id else False
|
|
pos_terminal_code = False
|
|
wire_transfer_code = rec.wire_transfer_code
|
|
|
|
self.env['hms.payments'].create({
|
|
'hms_payment_type_id': rec.payment_type.id,
|
|
'booking_id': rec.booking_id.id,
|
|
'currency_id': rec.currency_id.id,
|
|
'amount': rec.amount,
|
|
'exchange_rate': rec.exchange_rate,
|
|
'pending_transcation': rec.pending_transcation,
|
|
'transaction_id': transaction_id,
|
|
'pos_terminal_code': pos_terminal_code,
|
|
'wire_transfer_code': wire_transfer_code,
|
|
})
|