我想创建一个按钮,将来自reservation.chambre和chambre的字段值发送到account.invoice和account.invoice.line。
这是我的代码
class reservation_chambre(osv.Model):
_name = 'reservation.chambre'
@api.multi
def confirmer_reservation(self):
"""
This method create a new recordset for hotel room reservation line
------------------------------------------------------------------
@param self: The object pointer
@return: new record set for hotel room reservation line.
"""
reservation_line_obj = self.env['reservation_line.chambre']
for reservation in self:
self._cr.execute("select count(*) from reservation_chambre as hr "
"inner join reservation_line_hotel as hrl on \
hrl.id_line = hr.id "
"inner join hotel_reservation_line_room_relation as \
hrlrr on hrlrr.numch = hrl.id "
"where (date_d_arrivee,date_de_depart) overlaps \
( timestamp %s, timestamp %s ) "
"and hr.id <> cast(%s as integer) "
"and hr.state = 'confirmé' "
"and hrlrr.reservation_line_id in ("
"select hrlrr.reservation_line_id \
from reservation_chambre as hr "
"inner join reservation_line_hotel as \
hrl on hrl.id_line = hr.id "
"inner join hotel_reservation_line_room_relation \
as hrlrr on hrlrr.numch = hrl.id "
"where hr.id = cast(%s as integer) )",
(reservation.date_d_arrivee, reservation.date_de_depart,
str(reservation.id), str(reservation.id)))
res = self._cr.fetchone()
roomcount = res and res[0] or 0.0
if roomcount:
raise except_orm(_('Attention'), _('Vous avez essayé de confirmer la réservation avec une chambre qui est déjà réservé dans cette période !'))
else:
self.write({'state': 'confirmé'})
for id_line in reservation.reservation_line:
line_id = id_line.reserver
for numch in line_id:
vals = {
'room_id': numch.id,
'check_in': reservation.date_d_arrivee,
'check_out': reservation.date_de_depart,
'state': 'assigned',
'reservation_id': reservation.id,
}
numch.write({'isroom': False, 'status': 'occupée'})
reservation_line_obj.create(vals)
return True
_rec_name = 'no_reservation'
_columns = {
'no_reservation' : fields.char('Reservation no', size=64, readonly=True, states={'brouillon': [('readonly', False)]}, copy=False),
'id_partner': fields.many2one('res.partner','Client',required=True,help='le nom du client.'),
'date_d_arrivee': fields.datetime("Date d'arrivée", size=64, required=True),
'date_de_depart': fields.datetime('Date de départ', size=64, required=True),
'Adultes':fields.integer('Adultes', help='Le nombre des adultes.' ),
'enfants':fields.integer('Enfant',states={'draft': [('readonly', False)]}, help='Le nombre des enfants.'),
'date_order' : fields.datetime("Date d'aujourd'hui", required=True),
'partner_invoice_id': fields.many2one('res.partner', 'Adresse',
readonly=True,
help="Invoice address for "
"current reservation."),
'partner_order_id' : fields.many2one('res.partner', 'Ordering Contact',
readonly=True,
states={'draft':
[('readonly', False)]},
help="The name and address of the "
"contact that requested the order "
"or quotation."),
'id_chambre': fields.many2one('room.gestion','Chambre'),
'chambre': fields.one2many('room.gestion', 'numch', 'Chambre'),
'state': fields.selection([('brouillon', 'Brouillon'), ('confirmé', 'Confirmé'),
('cancel', 'Annulé'), ('terminé', 'Terminé')],'Etat'),
'reservation_line': fields.one2many('reservation_line.hotel', 'id_line',
'Reservation',
help='Hôtel détails de la réservation de la chambre.'),
'date': fields.datetime('date'),
'isroom': fields.boolean('isroom'),
'duration': fields.float(string='Durée',
help="Nombre de jours sera automatiquement compter du date d'arrivée et date de départ."),
'prix': fields.float('Prix'),
'description': fields.text('Description'),
}
_defaults = {
'date_order': lambda * a: time.strftime('%Y-%m-%d %H:%M:%S'),
'state':lambda * a:'brouillon',
'no_reservation': lambda obj, cr, uid, context: '/',
}
_sql_constraints = [
('no_uniq', 'unique(no_reservation)', 'Numéro réservation doit étre unique! , choisissez un autre numéro svp'),
]
class reservation_line_hotel(osv.Model):
_name = 'reservation_line.hotel'
_columns = {
'id_line': fields.many2one('reservation.chambre','Chambre'),
'reserver': fields.many2many('room.gestion',
'hotel_reservation_line_room_relation',
'numch', 'reservation_line_id'),
}
reservation_line_hotel()
class chambre(osv.Model):
_name = 'room.gestion'
_rec_name = 'numch'
_columns = {
'name': fields.char('Name'),
'photo': fields.binary('photo'),
'nom': fields.char('Nom'),
'numch' : fields.char('Chambre', size=64),
'capacite': fields.char('Capacite', size=64,required=True),
'montant' : fields.float('Prix',size=64),
'etage': fields.many2one('etage.gestion','Etage',required=True),
'etat': fields.selection((('n','Occupée'), ('c','Disponible')),'Etat'),
'datedecreation': fields.date('Date de création'),
'description': fields.text('Description'),
'service_id': fields.one2many('services.hotel','service_id','Service'),
'room_reservation_line_ids' : fields.one2many('reservation_line.chambre',
'room_id',
string='Ligne de réservation chambre'),
'status':fields.selection([('disponible', 'Disponible'),
('occupée', 'Occupée')],
'Status', default='disponible'),
'categorie': fields.many2one('categorie.chambre','type'),
'color': fields.integer('couleur'),
}
_sql_constraints = [
('numch_uniq', 'unique(numch)', 'numero chambre doit étre unique!'),
]
chambre()