From f548389a8b5f91bea37b8d7f1b50fcf1aa3c8bb1 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Wed, 7 Nov 2018 13:53:03 +0100 Subject: [PATCH] [WIP] Refactoring Code --- .../hotel_room_type_restriction_item.py | 37 +++++++-------- hotel/models/hotel_service.py | 47 +++++++------------ hotel/models/hotel_service_line.py | 12 ++--- hotel/models/inherited_account_invoice.py | 26 ++-------- hotel/models/inherited_account_payment.py | 10 ++-- .../models/inherited_mail_compose_message.py | 10 +--- hotel/models/inherited_product_category.py | 11 ----- hotel/models/inherited_product_pricelist.py | 12 ++--- hotel/models/inherited_product_template.py | 3 +- hotel/models/inherited_res_company.py | 2 +- hotel/models/inherited_res_partner.py | 15 +----- hotel/views/hotel_room_amenities_views.xml | 35 +++++++------- 12 files changed, 77 insertions(+), 143 deletions(-) delete mode 100644 hotel/models/inherited_product_category.py diff --git a/hotel/models/hotel_room_type_restriction_item.py b/hotel/models/hotel_room_type_restriction_item.py index 5da342f08..6a3510b92 100644 --- a/hotel/models/hotel_room_type_restriction_item.py +++ b/hotel/models/hotel_room_type_restriction_item.py @@ -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")) diff --git a/hotel/models/hotel_service.py b/hotel/models/hotel_service.py index a58f523c2..23c434e88 100644 --- a/hotel/models/hotel_service.py +++ b/hotel/models/hotel_service.py @@ -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'], }) - - diff --git a/hotel/models/hotel_service_line.py b/hotel/models/hotel_service_line.py index 68d4fe446..0e5a2e978 100644 --- a/hotel/models/hotel_service_line.py +++ b/hotel/models/hotel_service_line.py @@ -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) diff --git a/hotel/models/inherited_account_invoice.py b/hotel/models/inherited_account_invoice.py index 75e77c2a5..e0e951f07 100644 --- a/hotel/models/inherited_account_invoice.py +++ b/hotel/models/inherited_account_invoice.py @@ -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 diff --git a/hotel/models/inherited_account_payment.py b/hotel/models/inherited_account_payment.py index 9ac50cb80..bf3b2ee01 100644 --- a/hotel/models/inherited_account_payment.py +++ b/hotel/models/inherited_account_payment.py @@ -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: diff --git a/hotel/models/inherited_mail_compose_message.py b/hotel/models/inherited_mail_compose_message.py index f2d51b6e1..3fd0ac22b 100644 --- a/hotel/models/inherited_mail_compose_message.py +++ b/hotel/models/inherited_mail_compose_message.py @@ -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) diff --git a/hotel/models/inherited_product_category.py b/hotel/models/inherited_product_category.py deleted file mode 100644 index b83e75cae..000000000 --- a/hotel/models/inherited_product_category.py +++ /dev/null @@ -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') diff --git a/hotel/models/inherited_product_pricelist.py b/hotel/models/inherited_product_pricelist.py index 4f9ce2695..4df33a799 100644 --- a/hotel/models/inherited_product_pricelist.py +++ b/hotel/models/inherited_product_pricelist.py @@ -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') diff --git a/hotel/models/inherited_product_template.py b/hotel/models/inherited_product_template.py index 4b5a9f180..2ae139ff0 100644 --- a/hotel/models/inherited_product_template.py +++ b/hotel/models/inherited_product_template.py @@ -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" diff --git a/hotel/models/inherited_res_company.py b/hotel/models/inherited_res_company.py index 815baeea1..43393f253 100644 --- a/hotel/models/inherited_res_company.py +++ b/hotel/models/inherited_res_company.py @@ -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): diff --git a/hotel/models/inherited_res_partner.py b/hotel/models/inherited_res_partner.py index 88a1192f3..043f5a55a 100644 --- a/hotel/models/inherited_res_partner.py +++ b/hotel/models/inherited_res_partner.py @@ -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) - """ diff --git a/hotel/views/hotel_room_amenities_views.xml b/hotel/views/hotel_room_amenities_views.xml index 757230b76..0daa83a39 100644 --- a/hotel/views/hotel_room_amenities_views.xml +++ b/hotel/views/hotel_room_amenities_views.xml @@ -3,9 +3,9 @@ - - hotel.room.amenities.form - hotel.room.amenities + + hotel.room.amenitie.form + hotel.room.amenitie
@@ -19,7 +19,7 @@ - + @@ -63,13 +63,13 @@ - - hotel.room_amenities_search - hotel.room.amenities + + hotel.room_amenitie_search + hotel.room.amenitie - + @@ -82,29 +82,28 @@ - - hotel.room_amenities_list - hotel.room.amenities + + hotel.room_amenitie_list + hotel.room.amenitie - + - + Hotel Room Amenities - hotel.room.amenities + hotel.room.amenitie form tree,form - - + -