[DEL] l10n_es Wizard checkin

This commit is contained in:
Dario Lodeiros
2019-02-11 18:10:44 +01:00
parent bae27d9fc3
commit 5999a705e8
8 changed files with 0 additions and 538 deletions

View File

@@ -29,7 +29,6 @@
'data/menus.xml',
'views/inherited_account_payment_views.xml',
'views/inherited_account_invoice_views.xml',
'wizard/checkinwizard.xml',
'wizard/massive_price_reservation_days.xml',
'wizard/folio_make_invoice_advance_views.xml',
'data/hotel_sequence.xml',

View File

@@ -22,7 +22,6 @@
#
##############################################################################
from . import folio_make_invoice_advance
from . import checkinwizard
from . import massive_changes
from . import split_reservation
from . import duplicate_reservation

View File

@@ -1,221 +0,0 @@
import logging
from openerp import models, fields, api
_logger = logging.getLogger(__name__)
class Wizard(models.TransientModel):
_name = 'checkin.wizard'
def default_enter_date(self):
if ('reservation_ids' and 'folio') in self.env.context:
ids = [item[1] for item in self.env.context.get('reservation_ids')]
reservations = self.env['hotel.reservation'].browse(ids)
for res in reservations:
return res.checkin
if 'enter_date' in self.env.context:
return self.env.context['enter_date']
return False
def default_exit_date(self):
if ('reservation_ids' and 'folio') in self.env.context:
ids = [item[1] for item in self.env.context.get('reservation_ids')]
reservations = self.env['hotel.reservation'].browse(ids)
for res in reservations:
return res.checkout
if 'exit_date' in self.env.context:
return self.env.context['exit_date']
return False
def default_reservation_id(self):
if ('reservation_ids' and 'folio') in self.env.context:
ids = [item[1] for item in self.env.context.get('reservation_ids')]
reservations = self.env['hotel.reservation'].browse(ids)
if len(reservations) == 1:
# return current room line (onlyone in this case)
return reservations
for res in reservations:
# return the first room line with free space for a checkin
# TODO: add 'done' to res.state condition... Maybe too restrictive right now
if res.checkin_partner_count < (res.adults + res.children) and \
res.state not in ["cancelled"]:
return res
elif 'reservation_id' in self.env.context:
return self.env['hotel.reservation'].browse(
self.env.context['reservation_id'])
_logger.info('default_reservation_id is FALSE')
return False
def default_partner_id(self):
# no partner by default. User must search and choose one
return False
def default_checkin_partner_ids(self):
if ('reservation_ids' and 'folio') in self.env.context:
ids = [item[1] for item in self.env.context.get('reservation_ids')]
reservations = self.env['hotel.reservation'].browse(ids)
for res in reservations:
return res.checkin_partner_ids
def default_checkin_partner_ids(self):
if ('reservation_ids' and 'folio') in self.env.context:
ids = [item[1] for item in self.env.context.get('reservation_ids')]
reservations = self.env['hotel.reservation'].browse(ids)
for res in reservations:
return res.segmentation_id
''' TODO: clean-up
def default_count_checkin_partner(self):
if 'reservation_ids' and 'folio' in self.env.context:
ids = [item[1] for item in self.env.context['reservation_ids']]
reservations = self.env['hotel.reservation'].browse(ids)
for res in reservations:
return res.checkin_partner_count
'''
''' TODO: clean-up
def default_pending_checkin_partner(self):
if 'reservation_ids' and 'folio' in self.env.context:
ids = [item[1] for item in self.env.context['reservation_ids']]
reservations = self.env['hotel.reservation'].browse(ids)
for res in reservations:
return res.adults + res.children - res.checkin_partner_count
'''
''' TODO: clean-up - list of checkins on smart button clean is not used anymore
def comp_checkin_list_visible(self):
if 'partner_id' in self.env.context:
self.list_checkin_checkin_partner = False
return
'''
def comp_checkin_edit(self):
if 'edit_checkin_partner' in self.env.context:
return True
return False
checkin_partner_ids = fields.Many2many('hotel.checkin.partner', 'reservation_id',
default=default_checkin_partner_ids)
# count_checkin_partner = fields.Integer('Checkin counter',
# default=default_count_checkin_partner)
# pending_checkin_partner = fields.Integer('Checkin pending',
# default=default_pending_checkin_partner)
partner_id = fields.Many2one('res.partner',
default=default_partner_id)
reservation_id = fields.Many2one('hotel.reservation',
default=default_reservation_id)
enter_date = fields.Date(default=default_enter_date,
required=True)
exit_date = fields.Date(default=default_exit_date,
required=True)
firstname_checkin_partner = fields.Char('Firstname',
required=True)
lastname_checkin_partner = fields.Char('Lastname',
required=True)
email_checkin_partner = fields.Char('E-mail')
mobile_checkin_partner = fields.Char('Mobile')
segmentation_ids = fields.Many2many(
related='reservation_id.segmentation_ids')
''' TODO: clean-up - list of checkins on smart button clean is not used anymore
list_checkin_checkin_partner = fields.Boolean(compute=comp_checkin_list_visible,
default=True, store=True)
'''
# edit_checkin_checkin_partner = fields.Boolean(default=comp_checkin_edit,
# store=True)
op_select_partner = fields.Selection([
('S', 'Select a partner for checkin'),
('C', 'Create a new partner for checkin')
], default='S', string='Partner for checkin')
# checkin mode:
# 0 - no selection made by the user, so hide the client fields
# 1 - select a client for update his values and do the checkin
# 2 - create a new client with the values and do the checkin
checkin_mode = fields.Integer(default=0)
@api.multi
def action_save_check(self):
# prepare partner values
if self.op_select_partner == 'S':
partner_vals = {
'id': self.partner_id.id,
'firstname': self.firstname_checkin_partner,
'lastname': self.lastname_checkin_partner,
'email': self.email_checkin_partner,
'mobile': self.mobile_checkin_partner,
}
self.partner_id.sudo().write(partner_vals)
elif self.op_select_partner == 'C':
partner_vals = {
'firstname': self.firstname_checkin_partner,
'lastname': self.lastname_checkin_partner,
'email': self.email_checkin_partner,
'mobile': self.mobile_checkin_partner,
}
new_partner = self.env['res.partner'].create(partner_vals)
self.partner_id = self.env['res.partner'].browse(new_partner.id)
# prepare checkin values
checkin_partner_val = {
'partner_id': self.partner_id.id,
'enter_date': self.enter_date,
'exit_date': self.exit_date
}
record_id = self.env['hotel.reservation'].browse(
self.reservation_id.id)
# save the checkin for this reservation
record_id.write({
'checkin_partner_ids': [(0, False, checkin_partner_val)],
'segmentation_id': self.segmentation_id,
})
# update the state of the current reservation
if record_id.checkin_partner_count > 0:
record_id.state = 'booking'
@api.onchange('reservation_id')
def change_enter_exit_date(self):
record_id = self.env['hotel.reservation'].browse(
self.reservation_id.id)
self.enter_date = record_id.checkin
self.exit_date = record_id.checkout
''' trying to filter the reservations only to pending checkins ...
if 'reservation_ids' and 'folio' in self.env.context:
ids = [item[1] for item in self.env.context['reservation_ids']]
reservations = self.env['hotel.reservation'].browse(ids)
for res in reservations:
_logger.info('reservation checkin_partner_count %d', res.checkin_partner_count)
# return {
# 'domain': {'reservation_id': [('folio_id','=', self.env.context['folio']), 'count_checkin_partner','=','2']},
# 'warning': {'title': "Warning", 'message': self.env.context['checkin_partner_count']},
# }
'''
@api.onchange('partner_id')
def onchange_partner_id(self):
# update partner fields
write_vals = {
'firstname_checkin_partner': self.partner_id.firstname,
'lastname_checkin_partner': self.partner_id.lastname,
'email_checkin_partner': self.partner_id.email,
'mobile_checkin_partner': self.partner_id.mobile,
}
# show the checkin fields if a partner is selected
if self.op_select_partner == 'S' and self.partner_id.id != False:
write_vals.update({'checkin_mode': 1})
self.update(write_vals)
@api.onchange('op_select_partner')
def onchange_op_select_partner(self):
# field one2many return false is record does not exist
if self.op_select_partner == 'S' and self.partner_id.id:
self.checkin_mode = 1
# field one2many return 0 on empty record (nothing typed)
elif self.op_select_partner == 'C' and self.partner_id.id == 0:
self.checkin_mode = 2

View File

@@ -1,104 +0,0 @@
<?xml version="1.0"?>
<odoo>
<record id="checkin_wizard_form_2" model="ir.ui.view">
<field name="name">wizard.form2</field>
<field name="model">checkin.wizard</field>
<field name="arch" type="xml">
<form string="Add Checkin">
<sheet>
<group col="4">
<field options="{'no_quick_create': True, 'no_create_edit' : True, 'no_open': True}"
name="reservation_id" nolabel="1"
domain="[('folio_id','=',context.get('folio')), ('state', '!=', 'cancelled'), ('checkin_partner_pending_count', '>', 0)]"
style="max-width: 95%; width: 32.2em"/>
</group>
<group col="4">
<field name="enter_date" colspan="2"/>
<field name="exit_date" colspan="2"/>
</group>
<group attrs="{'invisible':[('checkin_mode', '>', 0)]}">
<field name="op_select_partner" widget="radio" options="{'horizontal': true}"/>
<field options="{'no_quick_create': True, 'no_create_edit' : True, 'no_open': True}"
name="partner_id" string="Client name"
style="max-width: 95%; width: 20em"/>
</group>
<group col="4" attrs="{'invisible':[('checkin_mode', '=', 0)]}" >
<field name="firstname_checkin_partner" colspan="2"/>
<field name="lastname_checkin_partner" colspan="2"/>
</group>
<group col="4" attrs="{'invisible':[('checkin_mode', '=', 0)]}" >
<field name="email_checkin_partner" colspan="2"/>
<field name="mobile_checkin_partner" colspan="2"/>
</group>
<footer>
<button name="action_save_check" string="Save Checkin and Print" type="object"
attrs="{'invisible':[('checkin_mode', '=', 0)]}" />
<button name="cancel" string="Cancel" special="cancel"/>
<field name="checkin_mode" invisible="True"/>
<!-- <field name="checkin_show" invisible="True"/> -->
<!-- <field name="edit_checkin_checkin_partner" invisible="True"/> -->
</footer>
</sheet>
</form>
</field>
</record>
<record id="launch_checkin_wizard_add" model="ir.actions.act_window">
<field name="name">Add Check</field>
<field name="res_model">checkin.wizard</field>
<field name="view_id" ref="checkin_wizard_form_2"/>
<field name="target">new</field>
</record>
<!-- TODO: clean-up
<record id="checkin_wizard_form_view" model="ir.ui.view">
<field name="name">wizard.form</field>
<field name="model">checkin.wizard</field>
<field name="arch" type="xml">
<form string="List Checkin">
<sheet>
<group col="4">
<label for="reservation_id" string="Resevation"/>
<field name="reservation_id" nolabel="1" domain="[('folio_id','=',context.get('folio'))]"/>
<button type="action" class="oe_stat_button"
id="checkin_partner_smart_button"
icon="fa-user-plus"
name="%(launch_checkin_wizard_add)d"
context="{'reservation_id': reservation_id, 'hidden_checkin_partner': True}">
<div>
<field name="pending_checkin_partner"
string="Pending" widget="statinfo"/>
</div>
</button>
</group>
<field name="checkin_partner_ids" readonly="1"/>
</sheet>
</form>
</field>
</record>
-->
<!-- TODO: clean-up
<act_window id="launch_checkin_wizard_list"
name="List Checks"
res_model="checkin.wizard"
view_mode="form"
view_id="checkin_wizard_form_view"
target="new"
key2="client_action_multi"/>
-->
<!-- TODO: clean-up
<act_window id="launch_checkin_wizard"
name="List Checkin"
res_model="checkin.wizard"
view_mode="form"
target="new"
key2="client_action_multi"/>
-->
</odoo>

View File

@@ -43,7 +43,6 @@
'views/report_viajero.xml',
'wizard/police_wizard.xml',
'wizard/ine_wizard.xml',
'wizard/inherit_checkin_wizard.xml',
'views/category_tourism.xml',
'views/code_ine.xml',
'views/inherit_res_company.xml',

View File

@@ -21,5 +21,4 @@
##############################################################################
from . import police_wizard
from . import inherit_checkin_wizard
from . import ine_wizard

View File

@@ -1,172 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2018 Alda Hotels <informatica@aldahotels.com>
# Jose Luis Algara <osotranquilo@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api
from openerp.exceptions import UserError
from openerp.tools.translate import _
from datetime import datetime, timedelta
class CheckinWizard(models.TransientModel):
_inherit = 'checkin.wizard'
def validation_under_age(self):
if self.birthdate_date_cardex != False:
years = str(datetime.now().date() - timedelta(days=365*16+4))
limit_date = datetime.strptime(years, "%Y-%m-%d")
birth_date = datetime.strptime(self.birthdate_date_cardex, '%Y-%m-%d')
limit = str(limit_date.day)+ ' de ' + str(limit_date.month)+ ' de ' + str(limit_date.year)
if limit_date < birth_date:
return {'warning': {'title': _('Error in Birthdate'), 'message': _('Does the client have less than 16 years?. Data collection is not performed for those born before %s.' % (limit)),},}
if self.polexpedition_cardex != False:
if self.birthdate_date_cardex > self.polexpedition_cardex:
raise ValidationError(_('Date of document shipment, prior to birth date'))
@api.onchange('polexpedition_cardex')
def validation_polexpedition(self):
if self.birthdate_date_cardex != False and self.polexpedition_cardex != False:
if self.birthdate_date_cardex > self.polexpedition_cardex:
return {'warning': {'title': _('Error in Birthdate or Expedition date'), 'message': _('Date of document shipment, prior to birth date'),},}
# Validation for DNI/Permiso conducir erroneo
@api.onchange('poldocument_cardex', 'documenttype_cardex')
def validation_poldocument_dni(self):
if self.poldocument_cardex != False:
if self.documenttype_cardex in ['D','C']:
validcaracter = "TRWAGMYFPDXBNJZSQVHLCKE"
dig_ext = "XYZ"
reemp_dig_ext = {'X':'0', 'Y':'1', 'Z':'2'}
numeros = "1234567890"
dni = self.poldocument_cardex.upper()
if len(dni) == 9:
dig_control = dni[8]
dni = dni[:8]
# 'extranjero empieza por XYZ'
if dni[0] in dig_ext:
dni = dni.replace(dni[0], reemp_dig_ext[dni[0]])
if not ((len(dni) == len([n for n in dni if n in numeros])) and (validcaracter[int(dni)%23] == dig_control)):
return {'warning': {'title': _('Error in DNI/NIE/DRIVE LICENSE'), 'message': _('Wrong DNI/NIE/DRIVE LICENSE, check it.'),},}
else:
return {'warning': {'title': _('Error in DNI/NIE/DRIVE LICENSE'), 'message': _('DNI/NIE/DRIVE LICENSE erroneous length, the correct format is: (12345678A or X1234567A)'),},}
# Validation for Tipo de documento no valido para Extranjero
# @api.onchange('x')
# Pendiente
# Validation for Nacionalidad erronea
# @api.onchange('x')
# Pendiente
# NOTE: All the fields are required but they are set required=True in the .xml
# The reason is found in the bt_select_partner and bt_create_partner buttons to bypass the ORM null constraint
# when the buttons are clicked to show the hidden fields
documenttype_cardex = fields.Selection([
('D', 'DNI'),
('P', 'Pasaporte'),
('C', 'Permiso de Conducir'),
('I', 'Carta o Doc. de Identidad'),
('N', 'Permiso Residencia Español'),
('X', 'Permiso Residencia Europeo')],
help='Select a valid document type',
default='D',
string='Doc. type')
poldocument_cardex = fields.Char('Doc. number')
polexpedition_cardex = fields.Date('Expedition date')
gender_cardex = fields.Selection([('male', 'Male'), ('female', 'Female')])
birthdate_date_cardex = fields.Date("Birthdate")
code_ine_cardex = fields.Many2one('code.ine',
help='Country or province of origin. Used for INE statistics.')
# TODO: Add tags in the cardex not in the partner anb move this field to out of localization
#category_id_cardex = fields.Many2many('res.partner.category', 'id', required=True)
@api.multi
def pdf_viajero(self, cardex_id):
cardex = self.env['cardex'].search([('id', '=', cardex_id)])
return self.env['report'].get_action(cardex, 'action.report.viajero')
@api.multi
def action_save_check(self):
# Check dates
self.validation_under_age()
# take a 'snapshot' of the current cardexes in this reservation
record_id = self.env['hotel.reservation'].browse(self.reservation_id.id)
old_cardex = self.env['cardex'].search([('reservation_id', '=', record_id.id)])
# the above lines must be executed before call the super().action_save_check()
# call the super action_save_check() for checkin
super(Wizard, self).action_save_check()
# prepare category in partner from category_id
the_list = self.segmentation_id - self.partner_id.category_id
the_list = self.partner_id.category_id + the_list
# prepare localization partner values
partner_vals = {
'documenttype': self.documenttype_cardex,
'poldocument': self.poldocument_cardex,
'polexpedition': self.polexpedition_cardex,
'gender': self.gender_cardex,
'birthdate_date': self.birthdate_date_cardex,
# (4, ID) link to existing record with id = ID (adds a relationship) ...
'code_ine': self.code_ine_cardex.id,
# (6, 0, [IDs]) replace the list of linked IDs ...
'category_id': [(6, False, [x.id for x in the_list])],
}
# Update Accounting VAT number on customer
if self.documenttype_cardex in ('D','C'):
partner_vat = 'ES' + self.poldocument_cardex
partner_vals.update({
'vat': partner_vat
})
# Are you templed to merge the following write with the super() ?
# Be warned: Premature optimization is the root of all evil -- DonaldKnuth
# This TransientModel inherit from checkin.wizard and it is intended for localization
# So, if you need to write something here must be _after_ the super()
# update the localization partner values for this reservation
self.partner_id.sudo().write(partner_vals);
# get the last cardex in this reservation (set difference theory)
cardex = self.env['cardex'].search([('reservation_id', '=', record_id.id)]) - old_cardex
return self.pdf_viajero(cardex.id)
@api.onchange('partner_id')
def onchange_partner_id(self):
# call the super update_partner_fields
super(Wizard, self).onchange_partner_id()
# update local fields
self.documenttype_cardex = self.partner_id.documenttype;
self.poldocument_cardex = self.partner_id.poldocument;
self.polexpedition_cardex = self.partner_id.polexpedition;
self.gender_cardex = self.partner_id.gender;
self.birthdate_date_cardex = self.partner_id.birthdate_date;
self.code_ine_cardex = self.partner_id.code_ine;
#self.category_id_cardex = self.partner_id.category_id;

View File

@@ -1,37 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="checkin_wizard_form_2" model="ir.ui.view">
<field name="name">wizard.form2</field>
<field name="model">checkin.wizard</field>
<field name="inherit_id" ref="hotel.checkin_wizard_form_2" />
<field name="arch" type="xml">
<xpath expr="//footer" position="before">
<group col="4" attrs="{'invisible':[('checkin_mode', '=', 0)]}" >
<field name="documenttype_cardex" colspan="2" required="True"/>
<newline/>
<field name="poldocument_cardex" colspan="2" required="True"/>
<field name="polexpedition_cardex" colspan="2" required="True"/>
</group>
<group col="4" attrs="{'invisible':[('checkin_mode', '=', 0)]}" >
<field name="gender_cardex" colspan="2" required="True"/>
<field name="birthdate_date_cardex" colspan="2" required="True"/>
</group>
<group col="4" attrs="{'invisible':[('checkin_mode', '=', 0)]}" >
<field name="code_ine_cardex" placeholder="Code in INE"
options="{'no_create': True,'no_open': True}" required="True"/>
<!-- <field name="category_id_cardex" widget="many2many_tags" placeholder="Tags..."
options="{'no_create': True,'no_open': True}" /> -->
<field name="segmentation_id" widget="many2many_tags" placeholder="Segmentation..."
options="{'no_create': True,'no_open': True}" required="True"/>
</group>
</xpath>
<xpath expr="//button[@name='action_save_check']" position="replace">
<button name="action_save_check" string="Save Checkin and Print" type="object"
attrs="{'invisible':[('checkin_mode', '=', 0)]}"/>
</xpath>
</field>
</record>
</data>
</openerp>