mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Refactoring Code
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from datetime import datetime
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
|
||||
class HotelRoomTypeRestrictionItem(models.Model):
|
||||
@@ -12,15 +10,11 @@ class HotelRoomTypeRestrictionItem(models.Model):
|
||||
restriction_id = fields.Many2one('hotel.room.type.restriction',
|
||||
'Restriction Plan', ondelete='cascade',
|
||||
index=True)
|
||||
# room_type_id = fields.Many2one('hotel.virtual.room', 'Virtual Room',
|
||||
# required=True, ondelete='cascade')
|
||||
room_type_id = fields.Many2one('hotel.room.type', 'Room Type',
|
||||
required=True, ondelete='cascade')
|
||||
date = fields.Date('Date')
|
||||
applied_on = fields.Selection([
|
||||
('1_global', 'Global'),
|
||||
# ('0_room_type', 'Virtual Room')], string="Apply On", required=True,
|
||||
# default='0_room_type',
|
||||
('0_room_type', 'Room Type')], string="Apply On", required=True,
|
||||
default='0_room_type',
|
||||
help='Pricelist Item applicable on selected option')
|
||||
@@ -37,22 +31,25 @@ class HotelRoomTypeRestrictionItem(models.Model):
|
||||
'unique(restriction_id, room_type_id, date)',
|
||||
'Only can exists one restriction in the same day for the same room type!')]
|
||||
|
||||
@api.multi
|
||||
@api.constrains('min_stay', 'min_stay_arrival', 'max_stay',
|
||||
'max_stay_arrival')
|
||||
def _check_min_stay_min_stay_arrival_max_stay(self):
|
||||
if self.min_stay < 0:
|
||||
raise ValidationError(_("Min. Stay can't be less than zero"))
|
||||
elif self.min_stay_arrival < 0:
|
||||
raise ValidationError(
|
||||
("Min. Stay Arrival can't be less than zero"))
|
||||
elif self.max_stay < 0:
|
||||
raise ValidationError(_("Max. Stay can't be less than zero"))
|
||||
elif self.max_stay_arrival < 0:
|
||||
raise ValidationError(
|
||||
("Max. Stay Arrival can't be less than zero"))
|
||||
def _check_min_stay(self):
|
||||
for record in self:
|
||||
if record.self.min_stay < 0:
|
||||
raise ValidationError(_("Min. Stay can't be less than zero"))
|
||||
elif record.min_stay_arrival < 0:
|
||||
raise ValidationError(
|
||||
("Min. Stay Arrival can't be less than zero"))
|
||||
elif record.max_stay < 0:
|
||||
raise ValidationError(_("Max. Stay can't be less than zero"))
|
||||
elif record.max_stay_arrival < 0:
|
||||
raise ValidationError(
|
||||
("Max. Stay Arrival can't be less than zero"))
|
||||
|
||||
@api.constrains('applied_on')
|
||||
def _check_applied_on(self):
|
||||
count = self.search_count([('applied_on', '=', '1_global')])
|
||||
if count > 1:
|
||||
raise ValidationError(_("Already exists an global rule"))
|
||||
for record in self:
|
||||
count = record.search_count([('applied_on', '=', '1_global')])
|
||||
if count > 1:
|
||||
raise ValidationError(_("Already exists an global rule"))
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import time
|
||||
import logging
|
||||
from odoo import models, fields, api
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
_logger = logging.getLogger(__name__)
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
from datetime import timedelta
|
||||
|
||||
class HotelService(models.Model):
|
||||
_name = 'hotel.service'
|
||||
@@ -13,25 +11,20 @@ class HotelService(models.Model):
|
||||
|
||||
@api.model
|
||||
def _default_ser_room_line(self):
|
||||
if 'room_lines' in self.env.context and self.env.context['room_lines']:
|
||||
if self.env.context.get('room_lines'):
|
||||
ids = [item[1] for item in self.env.context['room_lines']]
|
||||
return self.env['hotel.reservation'].search([
|
||||
('id', 'in', ids),
|
||||
], limit=1)
|
||||
return self.env['hotel.reservation'].browse([
|
||||
(ids)], limit=1)
|
||||
return False
|
||||
|
||||
name = fields.Char('Service description')
|
||||
product_id = fields.Many2one('product.product', 'Service',
|
||||
required=True)
|
||||
folio_id = fields.Many2one('hotel.folio', 'Folio',
|
||||
ondelete='cascade')
|
||||
product_id = fields.Many2one('product.product', 'Service', required=True)
|
||||
folio_id = fields.Many2one('hotel.folio', 'Folio', ondelete='cascade')
|
||||
ser_room_line = fields.Many2one('hotel.reservation', 'Room',
|
||||
default=_default_ser_room_line)
|
||||
service_line_ids = fields.One2many('hotel.service.line',
|
||||
'service_id')
|
||||
service_line_ids = fields.One2many('hotel.service.line', 'service_id')
|
||||
product_qty = fields.Integer('Quantity')
|
||||
pricelist_id = fields.Many2one(
|
||||
related='folio_id.pricelist_id')
|
||||
pricelist_id = fields.Many2one(related='folio_id.pricelist_id')
|
||||
channel_type = fields.Selection([
|
||||
('door', 'Door'),
|
||||
('mail', 'Mail'),
|
||||
@@ -87,24 +80,20 @@ class HotelService(models.Model):
|
||||
reservation.checkin,
|
||||
days_diff))
|
||||
else:
|
||||
record.update(rec.prepare_service_lines(
|
||||
record.update(record.prepare_service_lines(
|
||||
reservation.checkin, 1))
|
||||
|
||||
|
||||
##WIP##
|
||||
@api.multi
|
||||
def prepare_service_lines(self, dfrom, days, vals=False):
|
||||
self.ensure_one()
|
||||
old_qty = 0
|
||||
cmds = [(5, 0, 0)]
|
||||
if not vals:
|
||||
vals
|
||||
product = vals.get('product_id') or self.product_id
|
||||
old_lines_days = self.mapped('service_line_ids.date')
|
||||
for day in service_line_ids:
|
||||
for day in self.service_line_ids:
|
||||
old_qty = old_qty + day.day_qty
|
||||
qty_day = (self.product_qty - old_qty) // (days - count(old_line_days))
|
||||
rest_day = (self.product_qty - old_qty) % (days - count(old_line_days))
|
||||
reservation = rec.ser_room_line
|
||||
qty_day = (self.product_qty - old_qty) // (days - len(old_line_days))
|
||||
rest_day = (self.product_qty - old_qty) % (days - len(old_line_days))
|
||||
for i in range(0, days):
|
||||
idate = (fields.Date.from_string(dfrom) + timedelta(days=i)).strftime(
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
@@ -112,7 +101,7 @@ class HotelService(models.Model):
|
||||
if idate not in old_lines_days:
|
||||
cmds.append((0, False, {
|
||||
'date': idate,
|
||||
'day_qty': qty
|
||||
'day_qty': qty_day
|
||||
}))
|
||||
else:
|
||||
cmds.append((4, old_line.id))
|
||||
@@ -123,8 +112,8 @@ class HotelService(models.Model):
|
||||
"""
|
||||
Compute the amounts of the service line.
|
||||
"""
|
||||
for record in self:
|
||||
product = rec.product_id
|
||||
for record in self:
|
||||
product = record.product_id
|
||||
price = amount_room * (1 - (record.discount or 0.0) * 0.01)
|
||||
taxes = record.tax_id.compute_all(price, record.currency_id, 1, product=product)
|
||||
record.update({
|
||||
@@ -132,5 +121,3 @@ class HotelService(models.Model):
|
||||
'price_total': taxes['total_included'],
|
||||
'price_subtotal': taxes['total_excluded'],
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# Copyright 2017-2018 Alexandre Díaz
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import models, fields, api
|
||||
from odoo.addons import decimal_precision as dp
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
class HotelServiceLine(models.Model):
|
||||
_name = "hotel.service.line"
|
||||
_order = "date"
|
||||
|
||||
service_id = fields.Many2one('hotel.service', string='Service',
|
||||
ondelete='cascade', required=True,
|
||||
copy=False)
|
||||
ondelete='cascade', required=True,
|
||||
copy=False)
|
||||
date = fields.Date('Date')
|
||||
day_qty = fields.Integer('Units')
|
||||
product_id = fields.Many2one(related='service_id.product_id')
|
||||
@@ -21,8 +21,8 @@ class HotelServiceLine(models.Model):
|
||||
limit = record.product_id.daily_limit
|
||||
if limit > 0:
|
||||
out_qty = sum(self.env['hotel.service.line'].search([(
|
||||
'product_id','=',record.product_id,
|
||||
'date','=',record.date)]).mapped('day_qty'))
|
||||
'product_id', '=', record.product_id,
|
||||
'date', '=', record.date)]).mapped('day_qty'))
|
||||
if limit < out_qty + record.day_qty:
|
||||
raise ValidationError(
|
||||
_("Limit exceeded for %s")% record.date)
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||
import logging
|
||||
from openerp import models, fields, api, _
|
||||
from openerp.exceptions import UserError, ValidationError
|
||||
_logger = logging.getLogger(__name__)
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
@@ -12,12 +10,11 @@ class AccountInvoice(models.Model):
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
cr, uid, context = self.env.args
|
||||
context = dict(context)
|
||||
if context.get('invoice_origin', False):
|
||||
vals.update({'origin': context['invoice_origin']})
|
||||
if self.env.context.get('invoice_origin', False):
|
||||
vals.update({'origin': self.env.context.get['invoice_origin']})
|
||||
return super(AccountInvoice, self).create(vals)
|
||||
|
||||
"""WIP"""
|
||||
@api.multi
|
||||
def action_folio_payments(self):
|
||||
self.ensure_one()
|
||||
@@ -70,16 +67,3 @@ class AccountInvoice(models.Model):
|
||||
raise ValidationError(vat_error)
|
||||
return super(AccountInvoice, self).action_invoice_open()
|
||||
|
||||
# ~ @api.multi
|
||||
# ~ def confirm_paid(self):
|
||||
# ~ '''
|
||||
# ~ This method change pos orders states to done when folio invoice
|
||||
# ~ is in done.
|
||||
# ~ ----------------------------------------------------------
|
||||
# ~ @param self: object pointer
|
||||
# ~ '''
|
||||
# ~ pos_order_obj = self.env['pos.order']
|
||||
# ~ res = super(AccountInvoice, self).confirm_paid()
|
||||
# ~ pos_odr_rec = pos_order_obj.search([('invoice_id', 'in', self._ids)])
|
||||
# ~ pos_odr_rec and pos_odr_rec.write({'state': 'done'})
|
||||
# ~ return res
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import logging
|
||||
from openerp.exceptions import except_orm
|
||||
from openerp import models, fields, api, _
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
from odoo.exceptions import except_orm
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
class AccountPayment(models.Model):
|
||||
_inherit = 'account.payment'
|
||||
@@ -15,6 +12,7 @@ class AccountPayment(models.Model):
|
||||
string="Total amount in folio",
|
||||
)
|
||||
|
||||
"""WIP"""
|
||||
@api.multi
|
||||
def return_payment_folio(self):
|
||||
journal = self.journal_id
|
||||
@@ -78,7 +76,7 @@ class AccountPayment(models.Model):
|
||||
return
|
||||
if not any(fol):
|
||||
return
|
||||
elif len(fol) > 1:
|
||||
if len(fol) > 1:
|
||||
raise except_orm(_('Warning'), _('This pay is related with \
|
||||
more than one Reservation.'))
|
||||
else:
|
||||
|
||||
@@ -15,13 +15,7 @@ class MailComposeMessage(models.TransientModel):
|
||||
self._context['default_res_id']
|
||||
])
|
||||
if folio:
|
||||
cmds = []
|
||||
for lid in folio.room_lines.ids:
|
||||
cmds.append((
|
||||
1,
|
||||
lid,
|
||||
{'to_send': False}
|
||||
))
|
||||
if cmds:
|
||||
cmds = [(1, lid, {'to_send': False}) for lid in folio.room_lines.ids]
|
||||
if any(cmds):
|
||||
folio.room_lines = cmds
|
||||
return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
|
||||
class ProductCategory(models.Model):
|
||||
_inherit = "product.category"
|
||||
|
||||
# isroomtype = fields.Boolean('Is Room Type')
|
||||
isamenitytype = fields.Boolean('Is Amenities Type')
|
||||
isservicetype = fields.Boolean('Is Service Type')
|
||||
@@ -1,26 +1,24 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
from odoo import models, fields, api
|
||||
|
||||
class ProductPricelist(models.Model):
|
||||
_inherit = 'product.pricelist'
|
||||
|
||||
is_staff = fields.Boolean('Is Staff')
|
||||
|
||||
@api.multi
|
||||
@api.depends('name')
|
||||
def name_get(self):
|
||||
pricelist_id = self.env['ir.default'].sudo().get(
|
||||
'res.config.settings', 'parity_pricelist_id')
|
||||
'res.config.settings', 'default_pricelist_id')
|
||||
if pricelist_id:
|
||||
pricelist_id = int(pricelist_id)
|
||||
org_names = super(ProductPricelist, self).name_get()
|
||||
names = []
|
||||
for name in org_names:
|
||||
if name[0] == pricelist_id:
|
||||
names.append((name[0], '%s (Parity)' % name[1]))
|
||||
names.append((name[0], '%s (Default)' % name[1]))
|
||||
else:
|
||||
names.append((name[0], name[1]))
|
||||
return names
|
||||
|
||||
|
||||
is_staff = fields.Boolean('Is Staff')
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
from openerp import models, fields
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = "product.template"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from openerp import models, fields, api, _
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
# Copyright 2017 Alexandre Díaz
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
from openerp import models, fields
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
@@ -21,15 +20,5 @@ class ResPartner(models.Model):
|
||||
('partner_id.id', '=', record.id)
|
||||
])
|
||||
|
||||
reservations_count = fields.Integer('Reservations',
|
||||
compute='_compute_reservations_count')
|
||||
reservations_count = fields.Integer('Reservations', compute='_compute_reservations_count')
|
||||
folios_count = fields.Integer('Folios', compute='_compute_folios_count')
|
||||
|
||||
""" TODO
|
||||
@api.onchange('is_staff')
|
||||
def onchange_staff(self):
|
||||
staff_listprice = TODO: Search the pricelist checked like staff_listprice
|
||||
if staff_listprice:
|
||||
values = {'pricelist_id': staff_listprice}
|
||||
self.update(values)
|
||||
"""
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
<!--===== Room Amenities ===== -->
|
||||
<!-- Form view of hotel room amenities -->
|
||||
<record id="view_hotel_room_amenities_form" model="ir.ui.view">
|
||||
<field name="name">hotel.room.amenities.form</field>
|
||||
<field name="model">hotel.room.amenities</field>
|
||||
<record id="view_hotel_room_amenitie_form" model="ir.ui.view">
|
||||
<field name="name">hotel.room.amenitie.form</field>
|
||||
<field name="model">hotel.room.amenitie</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Hotel Room Amenities">
|
||||
<sheet>
|
||||
@@ -19,7 +19,7 @@
|
||||
<notebook>
|
||||
<page string="Information">
|
||||
<group colspan="4" col="4">
|
||||
<field name="room_amenities_type_id" select="2" string="Amenity Type" />
|
||||
<field name="room_amenitie_type_id" select="2" string="Amenity Type" />
|
||||
<!-- <field name="categ_id" select="1"
|
||||
domain="[('isamenitytype','=',True)]" /> -->
|
||||
</group>
|
||||
@@ -63,13 +63,13 @@
|
||||
</record>
|
||||
|
||||
<!-- Search view of hotel room amenities -->
|
||||
<record model="ir.ui.view" id="view_hotel_room_aenities_search">
|
||||
<field name="name">hotel.room_amenities_search</field>
|
||||
<field name="model">hotel.room.amenities</field>
|
||||
<record model="ir.ui.view" id="view_hotel_room_amenitie_search">
|
||||
<field name="name">hotel.room_amenitie_search</field>
|
||||
<field name="model">hotel.room.amenitie</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Hotel Room Amenities">
|
||||
<field name="name" />
|
||||
<field name="room_amenities_type_id" select="1" />
|
||||
<field name="room_amenitie_type_id" select="1" />
|
||||
<!-- <field name="list_price" string="ty rate" /> -->
|
||||
<newline />
|
||||
<group expand="0" string="Group By...">
|
||||
@@ -82,29 +82,28 @@
|
||||
</record>
|
||||
|
||||
<!-- Tree view of hotel room amenities -->
|
||||
<record model="ir.ui.view" id="view_hotel_room_amenities_list">
|
||||
<field name="name">hotel.room_amenities_list</field>
|
||||
<field name="model">hotel.room.amenities</field>
|
||||
<record model="ir.ui.view" id="view_hotel_room_amenitie_list">
|
||||
<field name="name">hotel.room_amenitie_list</field>
|
||||
<field name="model">hotel.room.amenitie</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Hotel Room Amenities">
|
||||
<field name="name" />
|
||||
<field name="room_amenities_type_id" select="1" />
|
||||
<field name="room_amenitie_type_id" select="1" />
|
||||
<!-- <field name="list_price" string="Ty rate" invisible="1" /> -->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Action for hotel room amenities -->
|
||||
<record model="ir.actions.act_window" id="action_hotel_room_amenities_view_form">
|
||||
<record model="ir.actions.act_window" id="action_hotel_room_amenitie_view_form">
|
||||
<field name="name">Hotel Room Amenities</field>
|
||||
<field name="res_model">hotel.room.amenities</field>
|
||||
<field name="res_model">hotel.room.amenitie</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<!-- <field name="context">{'default_iscategid':1}</field> -->
|
||||
<field name="view_id" ref="view_hotel_room_amenities_list" />
|
||||
<field name="view_id" ref="view_hotel_room_amenitie_list" />
|
||||
</record>
|
||||
<menuitem name="Amenities" id="menu_action_hotel_room_amenities_view_form"
|
||||
action="action_hotel_room_amenities_view_form" sequence="2"
|
||||
<menuitem name="Amenities" id="menu_action_hotel_room_amenitie_view_form"
|
||||
action="action_hotel_room_amenitie_view_form" sequence="2"
|
||||
parent="hotel.menu_amenity" />
|
||||
|
||||
<!-- Amenities Categories -->
|
||||
|
||||
Reference in New Issue
Block a user