diff --git a/hotel/models/hotel_folio.py b/hotel/models/hotel_folio.py
index daa3236db..23558e7c7 100644
--- a/hotel/models/hotel_folio.py
+++ b/hotel/models/hotel_folio.py
@@ -276,16 +276,17 @@ class HotelFolio(models.Model):
'amount_total': amount_untaxed + amount_tax,
})
- @api.depends('amount_total', 'payment_ids', 'return_ids', 'reservation_type')
+ @api.depends('amount_total', 'payment_ids', 'return_ids',
+ 'reservation_type', 'state')
@api.multi
def compute_amount(self):
acc_pay_obj = self.env['account.payment']
for record in self:
if record.reservation_type in ('staff', 'out'):
vals = {
- 'pending_amount': 0,
- 'invoices_paid': 0,
- 'refund_amount': 0,
+ 'pending_amount': 0,
+ 'invoices_paid': 0,
+ 'refund_amount': 0,
}
record.update(vals)
else:
@@ -294,10 +295,17 @@ class HotelFolio(models.Model):
('folio_id', '=', record.id)
])
total_paid = sum(pay.amount for pay in payments)
- return_lines = self.env['payment.return.line'].search([('move_line_ids','in',payments.mapped('move_line_ids.id')),('return_id.state','=', 'done')])
+ return_lines = self.env['payment.return.line'].search([
+ ('move_line_ids', 'in', payments.mapped('move_line_ids.id')),
+ ('return_id.state', '=', 'done')
+ ])
total_inv_refund = sum(pay_return.amount for pay_return in return_lines)
+ total = record.amount_total
+ # REVIEW: Must We ignored services in cancelled folios pending amount?
+ if record.state == 'cancelled':
+ total = total - sum(record.service_ids.mapped('price_total'))
vals = {
- 'pending_amount': record.amount_total - total_paid + total_inv_refund,
+ 'pending_amount': total - total_paid + total_inv_refund,
'invoices_paid': total_paid,
'refund_amount': total_inv_refund,
}
@@ -408,7 +416,6 @@ class HotelFolio(models.Model):
else:
vals['name'] = self.env['ir.sequence'].next_by_code('hotel.folio') or _('New')
-
# Makes sure partner_invoice_id' and 'pricelist_id' are defined
lfields = ('partner_invoice_id', 'partner_shipping_id', 'pricelist_id')
if any(f not in vals for f in lfields):
@@ -471,7 +478,7 @@ class HotelFolio(models.Model):
@api.onchange('partner_diff_invoicing')
def onchange_partner_diff_invoicing(self):
- if self.partner_diff_invoicing == False:
+ if self.partner_diff_invoicing is False:
self.update({'partner_invoice_id': self.partner_id.id})
elif self.partner_id == self.partner_invoice_id:
self.update({'partner_invoice_id': self.partner_id.address_get(['invoice'])['invoice'] or None})
@@ -515,17 +522,14 @@ class HotelFolio(models.Model):
@api.multi
def action_cancel(self):
- '''
- @param self: object pointer
- '''
- pass
- # for sale in self:
- # if not sale.order_id:
- # raise ValidationError(_('Order id is not available'))
- # for invoice in sale.invoice_ids:
- # invoice.state = 'cancel'
- # sale.room_lines.action_cancel()
- # sale.order_id.action_cancel()
+ for folio in self:
+ for reservation in folio.room_lines.filtered(lambda res:
+ res.state != 'cancelled'):
+ reservation.action_cancel()
+ self.write({
+ 'state': 'cancel',
+ })
+ return True
@api.multi
def print_quotation(self):
@@ -544,13 +548,14 @@ class HotelFolio(models.Model):
'state': 'confirm',
'confirmation_date': fields.Datetime.now()
})
- #~ if self.env.context.get('send_email'):
- #~ self.force_quotation_send()
+
+ # if self.env.context.get('send_email'):
+ # self.force_quotation_send()
# create an analytic account if at least an expense product
- #~ if any([expense_policy != 'no' for expense_policy in self.order_line.mapped('product_id.expense_policy')]):
- #~ if not self.analytic_account_id:
- #~ self._create_analytic_account()
+ # if any([expense_policy != 'no' for expense_policy in self.order_line.mapped('product_id.expense_policy')]):
+ # if not self.analytic_account_id:
+ # self._create_analytic_account()
return True
diff --git a/hotel/models/hotel_service.py b/hotel/models/hotel_service.py
index c507b78fc..cd71ff1ed 100644
--- a/hotel/models/hotel_service.py
+++ b/hotel/models/hotel_service.py
@@ -117,6 +117,7 @@ class HotelService(models.Model):
folio_id = fields.Many2one('hotel.folio', 'Folio',
ondelete='cascade',
default=_default_folio_id)
+ state = fields.Selection(related='folio_id.state')
ser_room_line = fields.Many2one('hotel.reservation', 'Room',
default=_default_ser_room_line)
per_day = fields.Boolean(related='product_id.per_day', related_sudo=True)
diff --git a/hotel/models/hotel_service_line.py b/hotel/models/hotel_service_line.py
index e7e986b84..c5b257387 100644
--- a/hotel/models/hotel_service_line.py
+++ b/hotel/models/hotel_service_line.py
@@ -4,6 +4,7 @@
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
+
class HotelServiceLine(models.Model):
_name = "hotel.service.line"
_order = "date"
@@ -11,6 +12,7 @@ class HotelServiceLine(models.Model):
service_id = fields.Many2one('hotel.service', string='Service Room',
ondelete='cascade', required=True,
copy=False)
+ active = fields.Boolean('Active', compute="_compute_active")
date = fields.Date('Date')
day_qty = fields.Integer('Units')
product_id = fields.Many2one(related='service_id.product_id', store=True)
diff --git a/hotel/views/hotel_folio_views.xml b/hotel/views/hotel_folio_views.xml
index 61086d516..cbdd0134f 100644
--- a/hotel/views/hotel_folio_views.xml
+++ b/hotel/views/hotel_folio_views.xml
@@ -21,17 +21,15 @@
-
-
+
-
+ help="If a Hotel Folio is done, you cannot modify it manually anymore. However, you will still be able to invoice. This is used to freeze the Hotel Folio." />