[WIP] Refactoring Code

This commit is contained in:
Dario Lodeiros
2018-11-07 13:53:03 +01:00
parent 62f46fdf45
commit f548389a8b
12 changed files with 77 additions and 143 deletions

View File

@@ -1,9 +1,7 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import datetime
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
class HotelRoomTypeRestrictionItem(models.Model): class HotelRoomTypeRestrictionItem(models.Model):
@@ -12,15 +10,11 @@ class HotelRoomTypeRestrictionItem(models.Model):
restriction_id = fields.Many2one('hotel.room.type.restriction', restriction_id = fields.Many2one('hotel.room.type.restriction',
'Restriction Plan', ondelete='cascade', 'Restriction Plan', ondelete='cascade',
index=True) 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', room_type_id = fields.Many2one('hotel.room.type', 'Room Type',
required=True, ondelete='cascade') required=True, ondelete='cascade')
date = fields.Date('Date') date = fields.Date('Date')
applied_on = fields.Selection([ applied_on = fields.Selection([
('1_global', 'Global'), ('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, ('0_room_type', 'Room Type')], string="Apply On", required=True,
default='0_room_type', default='0_room_type',
help='Pricelist Item applicable on selected option') help='Pricelist Item applicable on selected option')
@@ -37,22 +31,25 @@ class HotelRoomTypeRestrictionItem(models.Model):
'unique(restriction_id, room_type_id, date)', 'unique(restriction_id, room_type_id, date)',
'Only can exists one restriction in the same day for the same room type!')] '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', @api.constrains('min_stay', 'min_stay_arrival', 'max_stay',
'max_stay_arrival') 'max_stay_arrival')
def _check_min_stay_min_stay_arrival_max_stay(self): def _check_min_stay(self):
if self.min_stay < 0: for record in self:
raise ValidationError(_("Min. Stay can't be less than zero")) if record.self.min_stay < 0:
elif self.min_stay_arrival < 0: raise ValidationError(_("Min. Stay can't be less than zero"))
raise ValidationError( elif record.min_stay_arrival < 0:
("Min. Stay Arrival can't be less than zero")) raise ValidationError(
elif self.max_stay < 0: ("Min. Stay Arrival can't be less than zero"))
raise ValidationError(_("Max. Stay can't be less than zero")) elif record.max_stay < 0:
elif self.max_stay_arrival < 0: raise ValidationError(_("Max. Stay can't be less than zero"))
raise ValidationError( elif record.max_stay_arrival < 0:
("Max. Stay Arrival can't be less than zero")) raise ValidationError(
("Max. Stay Arrival can't be less than zero"))
@api.constrains('applied_on') @api.constrains('applied_on')
def _check_applied_on(self): def _check_applied_on(self):
count = self.search_count([('applied_on', '=', '1_global')]) for record in self:
if count > 1: count = record.search_count([('applied_on', '=', '1_global')])
raise ValidationError(_("Already exists an global rule")) if count > 1:
raise ValidationError(_("Already exists an global rule"))

View File

@@ -1,11 +1,9 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import time
import logging
from odoo import models, fields, api from odoo import models, fields, api
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
_logger = logging.getLogger(__name__) from datetime import timedelta
class HotelService(models.Model): class HotelService(models.Model):
_name = 'hotel.service' _name = 'hotel.service'
@@ -13,25 +11,20 @@ class HotelService(models.Model):
@api.model @api.model
def _default_ser_room_line(self): 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']] ids = [item[1] for item in self.env.context['room_lines']]
return self.env['hotel.reservation'].search([ return self.env['hotel.reservation'].browse([
('id', 'in', ids), (ids)], limit=1)
], limit=1)
return False return False
name = fields.Char('Service description') name = fields.Char('Service description')
product_id = fields.Many2one('product.product', 'Service', product_id = fields.Many2one('product.product', 'Service', required=True)
required=True) folio_id = fields.Many2one('hotel.folio', 'Folio', ondelete='cascade')
folio_id = fields.Many2one('hotel.folio', 'Folio',
ondelete='cascade')
ser_room_line = fields.Many2one('hotel.reservation', 'Room', ser_room_line = fields.Many2one('hotel.reservation', 'Room',
default=_default_ser_room_line) default=_default_ser_room_line)
service_line_ids = fields.One2many('hotel.service.line', service_line_ids = fields.One2many('hotel.service.line', 'service_id')
'service_id')
product_qty = fields.Integer('Quantity') product_qty = fields.Integer('Quantity')
pricelist_id = fields.Many2one( pricelist_id = fields.Many2one(related='folio_id.pricelist_id')
related='folio_id.pricelist_id')
channel_type = fields.Selection([ channel_type = fields.Selection([
('door', 'Door'), ('door', 'Door'),
('mail', 'Mail'), ('mail', 'Mail'),
@@ -87,24 +80,20 @@ class HotelService(models.Model):
reservation.checkin, reservation.checkin,
days_diff)) days_diff))
else: else:
record.update(rec.prepare_service_lines( record.update(record.prepare_service_lines(
reservation.checkin, 1)) reservation.checkin, 1))
##WIP##
@api.multi @api.multi
def prepare_service_lines(self, dfrom, days, vals=False): def prepare_service_lines(self, dfrom, days, vals=False):
self.ensure_one() self.ensure_one()
old_qty = 0 old_qty = 0
cmds = [(5, 0, 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') 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 old_qty = old_qty + day.day_qty
qty_day = (self.product_qty - old_qty) // (days - count(old_line_days)) qty_day = (self.product_qty - old_qty) // (days - len(old_line_days))
rest_day = (self.product_qty - old_qty) % (days - count(old_line_days)) rest_day = (self.product_qty - old_qty) % (days - len(old_line_days))
reservation = rec.ser_room_line
for i in range(0, days): for i in range(0, days):
idate = (fields.Date.from_string(dfrom) + timedelta(days=i)).strftime( idate = (fields.Date.from_string(dfrom) + timedelta(days=i)).strftime(
DEFAULT_SERVER_DATE_FORMAT) DEFAULT_SERVER_DATE_FORMAT)
@@ -112,7 +101,7 @@ class HotelService(models.Model):
if idate not in old_lines_days: if idate not in old_lines_days:
cmds.append((0, False, { cmds.append((0, False, {
'date': idate, 'date': idate,
'day_qty': qty 'day_qty': qty_day
})) }))
else: else:
cmds.append((4, old_line.id)) cmds.append((4, old_line.id))
@@ -123,8 +112,8 @@ class HotelService(models.Model):
""" """
Compute the amounts of the service line. Compute the amounts of the service line.
""" """
for record in self: for record in self:
product = rec.product_id product = record.product_id
price = amount_room * (1 - (record.discount or 0.0) * 0.01) price = amount_room * (1 - (record.discount or 0.0) * 0.01)
taxes = record.tax_id.compute_all(price, record.currency_id, 1, product=product) taxes = record.tax_id.compute_all(price, record.currency_id, 1, product=product)
record.update({ record.update({
@@ -132,5 +121,3 @@ class HotelService(models.Model):
'price_total': taxes['total_included'], 'price_total': taxes['total_included'],
'price_subtotal': taxes['total_excluded'], 'price_subtotal': taxes['total_excluded'],
}) })

View File

@@ -1,16 +1,16 @@
# Copyright 2017-2018 Alexandre Díaz # Copyright 2017-2018 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api from odoo import models, fields, api, _
from odoo.addons import decimal_precision as dp from odoo.exceptions import ValidationError
class HotelServiceLine(models.Model): class HotelServiceLine(models.Model):
_name = "hotel.service.line" _name = "hotel.service.line"
_order = "date" _order = "date"
service_id = fields.Many2one('hotel.service', string='Service', service_id = fields.Many2one('hotel.service', string='Service',
ondelete='cascade', required=True, ondelete='cascade', required=True,
copy=False) copy=False)
date = fields.Date('Date') date = fields.Date('Date')
day_qty = fields.Integer('Units') day_qty = fields.Integer('Units')
product_id = fields.Many2one(related='service_id.product_id') product_id = fields.Many2one(related='service_id.product_id')
@@ -21,8 +21,8 @@ class HotelServiceLine(models.Model):
limit = record.product_id.daily_limit limit = record.product_id.daily_limit
if limit > 0: if limit > 0:
out_qty = sum(self.env['hotel.service.line'].search([( out_qty = sum(self.env['hotel.service.line'].search([(
'product_id','=',record.product_id, 'product_id', '=', record.product_id,
'date','=',record.date)]).mapped('day_qty')) 'date', '=', record.date)]).mapped('day_qty'))
if limit < out_qty + record.day_qty: if limit < out_qty + record.day_qty:
raise ValidationError( raise ValidationError(
_("Limit exceeded for %s")% record.date) _("Limit exceeded for %s")% record.date)

View File

@@ -1,10 +1,8 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import logging from odoo import models, fields, api, _
from openerp import models, fields, api, _ from odoo.exceptions import ValidationError
from openerp.exceptions import UserError, ValidationError
_logger = logging.getLogger(__name__)
class AccountInvoice(models.Model): class AccountInvoice(models.Model):
@@ -12,12 +10,11 @@ class AccountInvoice(models.Model):
@api.model @api.model
def create(self, vals): def create(self, vals):
cr, uid, context = self.env.args if self.env.context.get('invoice_origin', False):
context = dict(context) vals.update({'origin': self.env.context.get['invoice_origin']})
if context.get('invoice_origin', False):
vals.update({'origin': context['invoice_origin']})
return super(AccountInvoice, self).create(vals) return super(AccountInvoice, self).create(vals)
"""WIP"""
@api.multi @api.multi
def action_folio_payments(self): def action_folio_payments(self):
self.ensure_one() self.ensure_one()
@@ -70,16 +67,3 @@ class AccountInvoice(models.Model):
raise ValidationError(vat_error) raise ValidationError(vat_error)
return super(AccountInvoice, self).action_invoice_open() 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

View File

@@ -1,10 +1,7 @@
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging from odoo.exceptions import except_orm
from openerp.exceptions import except_orm from odoo import models, fields, api, _
from openerp import models, fields, api, _
_logger = logging.getLogger(__name__)
class AccountPayment(models.Model): class AccountPayment(models.Model):
_inherit = 'account.payment' _inherit = 'account.payment'
@@ -15,6 +12,7 @@ class AccountPayment(models.Model):
string="Total amount in folio", string="Total amount in folio",
) )
"""WIP"""
@api.multi @api.multi
def return_payment_folio(self): def return_payment_folio(self):
journal = self.journal_id journal = self.journal_id
@@ -78,7 +76,7 @@ class AccountPayment(models.Model):
return return
if not any(fol): if not any(fol):
return return
elif len(fol) > 1: if len(fol) > 1:
raise except_orm(_('Warning'), _('This pay is related with \ raise except_orm(_('Warning'), _('This pay is related with \
more than one Reservation.')) more than one Reservation.'))
else: else:

View File

@@ -15,13 +15,7 @@ class MailComposeMessage(models.TransientModel):
self._context['default_res_id'] self._context['default_res_id']
]) ])
if folio: if folio:
cmds = [] cmds = [(1, lid, {'to_send': False}) for lid in folio.room_lines.ids]
for lid in folio.room_lines.ids: if any(cmds):
cmds.append((
1,
lid,
{'to_send': False}
))
if cmds:
folio.room_lines = cmds folio.room_lines = cmds
return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit) return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)

View File

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

View File

@@ -1,26 +1,24 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class ProductPricelist(models.Model):
_inherit = 'product.pricelist' _inherit = 'product.pricelist'
is_staff = fields.Boolean('Is Staff')
@api.multi @api.multi
@api.depends('name') @api.depends('name')
def name_get(self): def name_get(self):
pricelist_id = self.env['ir.default'].sudo().get( pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'parity_pricelist_id') 'res.config.settings', 'default_pricelist_id')
if pricelist_id: if pricelist_id:
pricelist_id = int(pricelist_id) pricelist_id = int(pricelist_id)
org_names = super(ProductPricelist, self).name_get() org_names = super(ProductPricelist, self).name_get()
names = [] names = []
for name in org_names: for name in org_names:
if name[0] == pricelist_id: if name[0] == pricelist_id:
names.append((name[0], '%s (Parity)' % name[1])) names.append((name[0], '%s (Default)' % name[1]))
else: else:
names.append((name[0], name[1])) names.append((name[0], name[1]))
return names return names
is_staff = fields.Boolean('Is Staff')

View File

@@ -1,8 +1,7 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class ProductTemplate(models.Model):
_inherit = "product.template" _inherit = "product.template"

View File

@@ -1,7 +1,7 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class ResCompany(models.Model):

View File

@@ -1,8 +1,7 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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): class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
@@ -21,15 +20,5 @@ class ResPartner(models.Model):
('partner_id.id', '=', record.id) ('partner_id.id', '=', record.id)
]) ])
reservations_count = fields.Integer('Reservations', reservations_count = fields.Integer('Reservations', compute='_compute_reservations_count')
compute='_compute_reservations_count')
folios_count = fields.Integer('Folios', compute='_compute_folios_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)
"""

View File

@@ -3,9 +3,9 @@
<!--===== Room Amenities ===== --> <!--===== Room Amenities ===== -->
<!-- Form view of hotel room amenities --> <!-- Form view of hotel room amenities -->
<record id="view_hotel_room_amenities_form" model="ir.ui.view"> <record id="view_hotel_room_amenitie_form" model="ir.ui.view">
<field name="name">hotel.room.amenities.form</field> <field name="name">hotel.room.amenitie.form</field>
<field name="model">hotel.room.amenities</field> <field name="model">hotel.room.amenitie</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Hotel Room Amenities"> <form string="Hotel Room Amenities">
<sheet> <sheet>
@@ -19,7 +19,7 @@
<notebook> <notebook>
<page string="Information"> <page string="Information">
<group colspan="4" col="4"> <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" <!-- <field name="categ_id" select="1"
domain="[('isamenitytype','=',True)]" /> --> domain="[('isamenitytype','=',True)]" /> -->
</group> </group>
@@ -63,13 +63,13 @@
</record> </record>
<!-- Search view of hotel room amenities --> <!-- Search view of hotel room amenities -->
<record model="ir.ui.view" id="view_hotel_room_aenities_search"> <record model="ir.ui.view" id="view_hotel_room_amenitie_search">
<field name="name">hotel.room_amenities_search</field> <field name="name">hotel.room_amenitie_search</field>
<field name="model">hotel.room.amenities</field> <field name="model">hotel.room.amenitie</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Hotel Room Amenities"> <search string="Hotel Room Amenities">
<field name="name" /> <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" /> --> <!-- <field name="list_price" string="ty rate" /> -->
<newline /> <newline />
<group expand="0" string="Group By..."> <group expand="0" string="Group By...">
@@ -82,29 +82,28 @@
</record> </record>
<!-- Tree view of hotel room amenities --> <!-- Tree view of hotel room amenities -->
<record model="ir.ui.view" id="view_hotel_room_amenities_list"> <record model="ir.ui.view" id="view_hotel_room_amenitie_list">
<field name="name">hotel.room_amenities_list</field> <field name="name">hotel.room_amenitie_list</field>
<field name="model">hotel.room.amenities</field> <field name="model">hotel.room.amenitie</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Hotel Room Amenities"> <tree string="Hotel Room Amenities">
<field name="name" /> <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" /> --> <!-- <field name="list_price" string="Ty rate" invisible="1" /> -->
</tree> </tree>
</field> </field>
</record> </record>
<!-- Action for hotel room amenities --> <!-- 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="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_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<!-- <field name="context">{'default_iscategid':1}</field> --> <field name="view_id" ref="view_hotel_room_amenitie_list" />
<field name="view_id" ref="view_hotel_room_amenities_list" />
</record> </record>
<menuitem name="Amenities" id="menu_action_hotel_room_amenities_view_form" <menuitem name="Amenities" id="menu_action_hotel_room_amenitie_view_form"
action="action_hotel_room_amenities_view_form" sequence="2" action="action_hotel_room_amenitie_view_form" sequence="2"
parent="hotel.menu_amenity" /> parent="hotel.menu_amenity" />
<!-- Amenities Categories --> <!-- Amenities Categories -->