mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] Discount, Massive Changes Prices
This commit is contained in:
@@ -202,7 +202,7 @@ class HotelFolio(models.Model):
|
||||
compute='_amount_all', track_visibility='always')
|
||||
|
||||
#Checkin Fields-----------------------------------------------------
|
||||
checkin_partner_ids = fields.One2many('hotel.checkin.partner', 'reservation_id')
|
||||
checkin_partner_ids = fields.One2many('hotel.checkin.partner', 'folio_id')
|
||||
booking_pending = fields.Integer('Booking pending',
|
||||
compute='_compute_checkin_partner_count')
|
||||
checkin_partner_count = fields.Integer('Checkin counter',
|
||||
|
||||
@@ -78,6 +78,20 @@ class HotelReservation(models.Model):
|
||||
else:
|
||||
return default_departure_hour
|
||||
|
||||
@api.model
|
||||
def _default_diff_invoicing(self):
|
||||
"""
|
||||
If the guest has an invoicing address set,
|
||||
this method return diff_invoicing = True, else, return False
|
||||
"""
|
||||
if 'reservation_id' in self.env.context:
|
||||
reservation = self.env['hotel.reservation'].browse([
|
||||
self.env.context['reservation_id']
|
||||
])
|
||||
if reservation.partner_id.id == reservation.partner_invoice_id.id:
|
||||
return False
|
||||
return True
|
||||
|
||||
@api.depends('state', 'qty_to_invoice', 'qty_invoiced')
|
||||
def _compute_invoice_status(self):
|
||||
"""
|
||||
@@ -172,14 +186,12 @@ class HotelReservation(models.Model):
|
||||
ondelete='cascade')
|
||||
|
||||
checkin = fields.Date('Check In', required=True,
|
||||
default=_get_default_checkin,
|
||||
track_visibility='onchange')
|
||||
default=_get_default_checkin)
|
||||
checkout = fields.Date('Check Out', required=True,
|
||||
default=_get_default_checkout,
|
||||
track_visibility='onchange')
|
||||
real_checkin = fields.Date('Real Check In', required=True,
|
||||
default=_get_default_checkout)
|
||||
real_checkin = fields.Date('Arrival', required=True,
|
||||
track_visibility='onchange')
|
||||
real_checkout = fields.Date('Real Check Out', required=True,
|
||||
real_checkout = fields.Date('Departure', required=True,
|
||||
track_visibility='onchange')
|
||||
arrival_hour = fields.Char('Arrival Hour',
|
||||
default=_get_default_arrival_hour,
|
||||
@@ -203,6 +215,9 @@ class HotelReservation(models.Model):
|
||||
partner_invoice_email = fields.Char(related="partner_invoice_id.email")
|
||||
partner_invoice_lang = fields.Selection(related="partner_invoice_id.lang")
|
||||
closure_reason_id = fields.Many2one(related='folio_id.closure_reason_id')
|
||||
partner_invoice_type = fields.Selection(related="partner_invoice_id.type")
|
||||
partner_invoice_parent_id = fields.Many2one(related="partner_invoice_id.parent_id")
|
||||
partner_diff_invoicing = fields.Boolean('Bill to another Address', default='_default_diff_invoicing')
|
||||
company_id = fields.Many2one(related='folio_id.company_id', string='Company', store=True, readonly=True)
|
||||
reservation_line_ids = fields.One2many('hotel.reservation.line',
|
||||
'reservation_id',
|
||||
@@ -307,8 +322,10 @@ class HotelReservation(models.Model):
|
||||
readonly=True,
|
||||
store=True,
|
||||
compute='_compute_amount_set')
|
||||
# FIXME discount per night
|
||||
discount = fields.Float(string='Discount (%)', digits=dp.get_precision('Discount'), default=0.0)
|
||||
discount = fields.Float(string='Discount (€)',
|
||||
digits=dp.get_precision('Discount'),
|
||||
compute='_compute_discount',
|
||||
store=True)
|
||||
|
||||
analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags')
|
||||
|
||||
@@ -562,11 +579,14 @@ class HotelReservation(models.Model):
|
||||
|
||||
@api.onchange('partner_id')
|
||||
def onchange_partner_id(self):
|
||||
addr = self.partner_id.address_get(['invoice'])
|
||||
pricelist = self.partner_id.property_product_pricelist and \
|
||||
self.partner_id.property_product_pricelist.id or \
|
||||
self.env['ir.default'].sudo().get('res.config.settings', 'default_pricelist_id')
|
||||
values = {
|
||||
'pricelist_id': pricelist,
|
||||
'partner_invoice_id': addr['invoice'],
|
||||
'partner_diff_invoicing': False if self.partner_id.id == addr['invoice'] else True
|
||||
}
|
||||
self.update(values)
|
||||
|
||||
@@ -666,6 +686,21 @@ class HotelReservation(models.Model):
|
||||
]
|
||||
return {'domain': {'room_id': domain_rooms}}
|
||||
|
||||
@api.onchange('partner_diff_invoicing')
|
||||
def onchange_partner_diff_invoicing(self):
|
||||
if self.partner_diff_invoicing == False:
|
||||
self.update({'partner_invoice_id': self.partner_id.id})
|
||||
elif self.partner_id == self.partner_invoice_id:
|
||||
self.update({'partner_invoice_id': self.partner_id.address_get(['invoice'])['invoice'] or None})
|
||||
|
||||
@api.onchange('partner_invoice_id')
|
||||
def onchange_partner_invoice_id(self):
|
||||
if self.partner_invoice_id and not self.partner_invoice_id.parent_id and \
|
||||
self.partner_invoice_id != self.partner_id:
|
||||
self.update({
|
||||
'partner_invoice_parent_id': self.partner_id.id,
|
||||
'partner_invoice_type': 'invoice'})
|
||||
|
||||
@api.onchange('board_service_room_id')
|
||||
def onchange_board_service(self):
|
||||
if self.board_service_room_id:
|
||||
@@ -742,7 +777,6 @@ class HotelReservation(models.Model):
|
||||
for record in self:
|
||||
record.write({
|
||||
'state': 'cancelled',
|
||||
'discount': 100.0,
|
||||
})
|
||||
if record.splitted:
|
||||
master_reservation = record.parent_reservation or record
|
||||
@@ -801,7 +835,13 @@ class HotelReservation(models.Model):
|
||||
return True
|
||||
return False
|
||||
|
||||
@api.depends('reservation_line_ids', 'reservation_line_ids.discount', 'tax_ids')
|
||||
@api.depends('reservation_line_ids.discount')
|
||||
def _compute_discount(self):
|
||||
for record in self:
|
||||
record.discount = sum(line.price * (1 - (line.discount or 0.0) * 0.01) \
|
||||
for line in record.reservation_line_ids)
|
||||
|
||||
@api.depends('reservation_line_ids.price', 'discount', 'tax_ids')
|
||||
def _compute_amount_reservation(self):
|
||||
"""
|
||||
Compute the amounts of the reservation.
|
||||
@@ -810,7 +850,7 @@ class HotelReservation(models.Model):
|
||||
amount_room = sum(record.reservation_line_ids.mapped('price'))
|
||||
if amount_room > 0:
|
||||
product = record.room_type_id.product_id
|
||||
price = amount_room * (1 - (record.discount or 0.0) * 0.01)
|
||||
price = amount_room - record.discount
|
||||
taxes = record.tax_ids.compute_all(price, record.currency_id, 1, product=product)
|
||||
record.update({
|
||||
'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
|
||||
|
||||
@@ -132,6 +132,8 @@
|
||||
<field name="email" placeholder="email"/>
|
||||
<field name="mobile" placeholder="mobile"/>
|
||||
<field name="phone" />
|
||||
<field name="segmentation_ids" widget="many2many_tags" placeholder="Segmentation..."
|
||||
options="{'no_create': True,'no_open': True}" />
|
||||
<field name="cancelled_reason" attrs="{'invisible':[('state','not in',('cancel'))]}"/>
|
||||
</group>
|
||||
<group>
|
||||
@@ -140,8 +142,6 @@
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
<field name="reservation_type" attrs="{'readonly':[('state','not in',('draft'))]}"/>
|
||||
<field name="channel_type" attrs="{'required':[('reservation_type','=','normal')]}"/>
|
||||
<field name="segmentation_ids" widget="many2many_tags" placeholder="Segmentation..."
|
||||
options="{'no_create': True,'no_open': True}" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="partner_internal_comment"/>
|
||||
@@ -179,10 +179,6 @@
|
||||
nolabel="1" />
|
||||
</page>
|
||||
<page name="persons" string="Persons">
|
||||
<group>
|
||||
<field name="segmentation_ids" widget="many2many_tags" placeholder="Segmentation..."
|
||||
options="{'no_create': True,'no_open': True}" />
|
||||
</group>
|
||||
<field name="checkin_partner_ids"
|
||||
context="{
|
||||
'default_reservation_id': id,
|
||||
|
||||
@@ -320,18 +320,24 @@
|
||||
}"
|
||||
/>
|
||||
</page>
|
||||
<page name="invoicing" string="invoicing">
|
||||
<page name="invoicing" string="Invoicing">
|
||||
<group>
|
||||
<field name="partner_diff_invoicing" string="Bill to another Address"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="partner_invoice_id"
|
||||
string="Contact Invoiced"
|
||||
attrs="{'invisible':[('partner_diff_invoicing','=',False)]}"/>
|
||||
</group>
|
||||
<group>
|
||||
<group>
|
||||
<field name="partner_invoice_id" />
|
||||
<field name="partner_invoice_name" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="partner_invoice_vat" />
|
||||
<field name="partner_invoice_email" />
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<group>
|
||||
<field name="partner_invoice_parent_id" />
|
||||
<field name="partner_invoice_type" />
|
||||
</group>
|
||||
<group>
|
||||
<label for="partner_invoice_street" string="Address"/>
|
||||
<div class="o_address_format">
|
||||
@@ -345,7 +351,7 @@
|
||||
</group>
|
||||
<group>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
<page name="others" string="Others">
|
||||
<group>
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
<field name="folio_ids" widget="many2many_tags"/>
|
||||
<field name="from_folio" invisible="1" />
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='product_id']" position="after">
|
||||
<field name="reservation_line_ids" widget="many2many_tags"/>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='%(account.action_account_invoice_payment)d']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|',('from_folio','=',True)]}</attribute>
|
||||
</xpath>
|
||||
|
||||
@@ -195,10 +195,6 @@ class FolioAdvancePaymentInv(models.TransientModel):
|
||||
inv_obj = self.env['account.invoice']
|
||||
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
|
||||
folios = self.folio_ids
|
||||
|
||||
for folio in folios:
|
||||
if folio.partner_invoice_id != self.partner_invoice_id:
|
||||
raise UserError(_('The billing directions must match'))
|
||||
|
||||
if self.advance_payment_method == 'all':
|
||||
inv_data = self._prepare_invoice()
|
||||
|
||||
@@ -7,6 +7,9 @@ class MassivePriceChangeWizard(models.TransientModel):
|
||||
_name = 'hotel.wizard.massive.price.reservation.days'
|
||||
|
||||
new_price = fields.Float('New Price', default=1, min=1)
|
||||
change_price = fields.Boolean('Change Prices', default=False)
|
||||
new_discount = fields.Float('New Discount', default=0, min=1)
|
||||
change_discount = fields.Boolean('Change Discounts', default=False)
|
||||
|
||||
@api.multi
|
||||
def massive_price_change_days(self):
|
||||
@@ -18,29 +21,16 @@ class MassivePriceChangeWizard(models.TransientModel):
|
||||
return False
|
||||
|
||||
cmds = []
|
||||
for rline in reservation_id.reservation_lines:
|
||||
for rline in reservation_id.reservation_line_ids:
|
||||
cmds.append((
|
||||
1,
|
||||
rline.id,
|
||||
{
|
||||
'price': self.new_price
|
||||
'price': self.new_price if self.change_price == True else rline.price,
|
||||
'discount': self.new_discount if self.change_discount == True else rline.discount
|
||||
}
|
||||
))
|
||||
reservation_id.write({
|
||||
'reservation_lines': cmds
|
||||
'reservation_line_ids': cmds
|
||||
})
|
||||
# FIXME: For some reason need force reservation price calcs
|
||||
reservation_id._computed_amount_reservation()
|
||||
# FIXME: Workaround for dispatch updated price
|
||||
reservation_id.folio_id.write({
|
||||
'room_lines': [
|
||||
(
|
||||
1,
|
||||
reservation_id.id, {
|
||||
'reservation_lines': cmds
|
||||
}
|
||||
)
|
||||
]
|
||||
})
|
||||
|
||||
return True
|
||||
|
||||
@@ -7,7 +7,14 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Massive Price Change" >
|
||||
<group>
|
||||
<field name="new_price" required="1" />
|
||||
<field name="change_price"/>
|
||||
<field name="new_price" required="1"
|
||||
attrs="{'readonly':[('change_price','=', False)]}" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="change_discount"/>
|
||||
<field name="new_discount" required="1"
|
||||
attrs="{'readonly':[('change_discount','=', False)]}" />
|
||||
</group>
|
||||
<footer>
|
||||
<button name="massive_price_change_days" string="Massive Change" type="object"
|
||||
|
||||
Reference in New Issue
Block a user