mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] unit price computed taxes
This commit is contained in:
@@ -891,8 +891,8 @@ class HotelReservation(models.Model):
|
|||||||
date=idate,
|
date=idate,
|
||||||
pricelist=pricelist_id,
|
pricelist=pricelist_id,
|
||||||
uom=product.uom_id.id)
|
uom=product.uom_id.id)
|
||||||
line_price = self.env['account.tax']._fix_tax_included_price_company(
|
# REVIEW this forces to have configured the taxes included in the price
|
||||||
product.price, product.taxes_id, self.tax_ids, self.company_id)
|
line_price = product.price
|
||||||
if old_line and old_line.id:
|
if old_line and old_line.id:
|
||||||
cmds.append((1, old_line.id, {
|
cmds.append((1, old_line.id, {
|
||||||
'price': line_price
|
'price': line_price
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<xpath expr="//field[@name='communication']" position="after">
|
<xpath expr="//field[@name='communication']" position="after">
|
||||||
<field name="folio_id"/>
|
<field name="folio_id"/>
|
||||||
<field name="save_amount" invisible="1"/>
|
<field name="save_amount" invisible="1"/>
|
||||||
<field name="save_journal" invisible="1"/>
|
<field name="save_journal_id" invisible="1"/>
|
||||||
<field name="save_date" invisible="1"/>
|
<field name="save_date" invisible="1"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
@@ -49,7 +49,17 @@ class FolioWizard(models.TransientModel):
|
|||||||
if user.has_group('hotel.group_hotel_call'):
|
if user.has_group('hotel.group_hotel_call'):
|
||||||
return 'phone'
|
return 'phone'
|
||||||
|
|
||||||
partner_id = fields.Many2one('res.partner',string="Customer")
|
@api.model
|
||||||
|
def _get_default_pricelist(self):
|
||||||
|
return self.env['ir.default'].sudo().get(
|
||||||
|
'res.config.settings', 'default_pricelist_id')
|
||||||
|
|
||||||
|
partner_id = fields.Many2one('res.partner', required=True, string="Customer")
|
||||||
|
pricelist_id = fields.Many2one('product.pricelist',
|
||||||
|
string='Pricelist',
|
||||||
|
required=True,
|
||||||
|
default=_get_default_pricelist,
|
||||||
|
help="Pricelist for current folio.")
|
||||||
checkin = fields.Date('Check In', required=True,
|
checkin = fields.Date('Check In', required=True,
|
||||||
default=_get_default_checkin)
|
default=_get_default_checkin)
|
||||||
checkout = fields.Date('Check Out', required=True,
|
checkout = fields.Date('Check Out', required=True,
|
||||||
@@ -68,13 +78,28 @@ class FolioWizard(models.TransientModel):
|
|||||||
('mail', 'Mail'),
|
('mail', 'Mail'),
|
||||||
('phone', 'Phone')
|
('phone', 'Phone')
|
||||||
], string='Sales Channel', default=_get_default_channel_type)
|
], string='Sales Channel', default=_get_default_channel_type)
|
||||||
room_type_wizard_ids = fields.Many2many('hotel.room.type.wizard',
|
room_type_wizard_ids = fields.One2many('hotel.room.type.wizard',
|
||||||
string="Room Types")
|
'folio_wizard_id',
|
||||||
|
string="Room Types")
|
||||||
call_center = fields.Boolean(default=_get_default_center_user)
|
call_center = fields.Boolean(default=_get_default_center_user)
|
||||||
|
|
||||||
def assign_rooms(self):
|
def assign_rooms(self):
|
||||||
self.assign = True
|
self.assign = True
|
||||||
|
|
||||||
|
@api.onchange('pricelist_id')
|
||||||
|
def onchange_pricelist_id(self):
|
||||||
|
if self.pricelist_id:
|
||||||
|
self.onchange_checks()
|
||||||
|
|
||||||
|
@api.onchange('partner_id')
|
||||||
|
def onchange_partner_id(self):
|
||||||
|
if self.partner_id:
|
||||||
|
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')
|
||||||
|
self.pricelist_id = pricelist
|
||||||
|
|
||||||
@api.onchange('autoassign')
|
@api.onchange('autoassign')
|
||||||
def create_reservations(self):
|
def create_reservations(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@@ -103,10 +128,7 @@ class FolioWizard(models.TransientModel):
|
|||||||
checkout_dt = fields.Date.from_string(line.checkout)
|
checkout_dt = fields.Date.from_string(line.checkout)
|
||||||
nights = abs((checkout_dt - checkin_dt).days)
|
nights = abs((checkout_dt - checkin_dt).days)
|
||||||
for room in room_list:
|
for room in room_list:
|
||||||
pricelist_id = self.env['ir.default'].sudo().get(
|
pricelist_id = self.pricelist_id.id
|
||||||
'res.config.settings', 'default_pricelist_id')
|
|
||||||
if pricelist_id:
|
|
||||||
pricelist_id = int(pricelist_id)
|
|
||||||
res_price = 0
|
res_price = 0
|
||||||
for i in range(0, nights):
|
for i in range(0, nights):
|
||||||
ndate = checkin_dt + timedelta(days=i)
|
ndate = checkin_dt + timedelta(days=i)
|
||||||
@@ -198,6 +220,7 @@ class FolioWizard(models.TransientModel):
|
|||||||
services = [(5, False, False)]
|
services = [(5, False, False)]
|
||||||
if self.autoassign:
|
if self.autoassign:
|
||||||
self.create_reservations()
|
self.create_reservations()
|
||||||
|
import wdb; wdb.set_trace()
|
||||||
for line in self.reservation_wizard_ids:
|
for line in self.reservation_wizard_ids:
|
||||||
reservations.append((0, False, {
|
reservations.append((0, False, {
|
||||||
'room_id': line.room_id.id,
|
'room_id': line.room_id.id,
|
||||||
@@ -297,16 +320,9 @@ class HotelRoomTypeWizards(models.TransientModel):
|
|||||||
dates.append(ndate_str)
|
dates.append(ndate_str)
|
||||||
if minstay_restrictions:
|
if minstay_restrictions:
|
||||||
date_min_days = minstay_restrictions.filtered(
|
date_min_days = minstay_restrictions.filtered(
|
||||||
lambda r: r.date_start <= ndate_str and \
|
lambda r: r.date == ndate_str).min_stay
|
||||||
r.date_end >= ndate_str).min_stay
|
|
||||||
if date_min_days > min_stay:
|
if date_min_days > min_stay:
|
||||||
min_stay = date_min_days
|
min_stay = date_min_days
|
||||||
if user.has_group('hotel.group_hotel_call'):
|
|
||||||
if avail_restrictions:
|
|
||||||
max_avail = avail_restrictions.filtered(
|
|
||||||
lambda r: r.date == ndate_str).wmax_avail
|
|
||||||
if max_avail < avail:
|
|
||||||
avail = min(max_avail, real_max)
|
|
||||||
else:
|
else:
|
||||||
avail = real_max
|
avail = real_max
|
||||||
|
|
||||||
@@ -330,12 +346,7 @@ class HotelRoomTypeWizards(models.TransientModel):
|
|||||||
if chkin_utc_dt >= chkout_utc_dt:
|
if chkin_utc_dt >= chkout_utc_dt:
|
||||||
chkout_utc_dt = chkin_utc_dt + timedelta(days=1)
|
chkout_utc_dt = chkin_utc_dt + timedelta(days=1)
|
||||||
nights = abs((chkout_utc_dt - chkin_utc_dt).days)
|
nights = abs((chkout_utc_dt - chkin_utc_dt).days)
|
||||||
|
pricelist_id = self.folio_wizard_id.pricelist_id.id
|
||||||
pricelist_id = self.env['ir.default'].sudo().get(
|
|
||||||
'res.config.settings', 'default_pricelist_id')
|
|
||||||
if pricelist_id:
|
|
||||||
pricelist_id = int(pricelist_id)
|
|
||||||
|
|
||||||
res_price = 0
|
res_price = 0
|
||||||
for i in range(0, nights):
|
for i in range(0, nights):
|
||||||
ndate = chkin_utc_dt + timedelta(days=i)
|
ndate = chkin_utc_dt + timedelta(days=i)
|
||||||
@@ -347,8 +358,7 @@ class HotelRoomTypeWizards(models.TransientModel):
|
|||||||
date=ndate_str,
|
date=ndate_str,
|
||||||
pricelist=pricelist_id,
|
pricelist=pricelist_id,
|
||||||
uom=record.room_type_id.product_id.uom_id.id)
|
uom=record.room_type_id.product_id.uom_id.id)
|
||||||
res_price += self.env['account.tax']._fix_tax_included_price_company(
|
res_price += product.price
|
||||||
product.price, product.taxes_id, product.taxes_id, self.env.user.company_id)
|
|
||||||
|
|
||||||
price = res_price - ((res_price * record.discount) * 0.01)
|
price = res_price - ((res_price * record.discount) * 0.01)
|
||||||
total_price = record.rooms_num * price
|
total_price = record.rooms_num * price
|
||||||
@@ -427,10 +437,7 @@ class ReservationWizard(models.TransientModel):
|
|||||||
end_date_utc_dt = fields.Date.from_string(line.checkout)
|
end_date_utc_dt = fields.Date.from_string(line.checkout)
|
||||||
|
|
||||||
if line.room_type_id:
|
if line.room_type_id:
|
||||||
pricelist_id = self.env['ir.default'].sudo().get(
|
pricelist_id = self.folio_wizard_id.pricelist_id.id
|
||||||
'res.config.settings', 'default_pricelist_id')
|
|
||||||
if pricelist_id:
|
|
||||||
pricelist_id = int(pricelist_id)
|
|
||||||
nights = abs((end_date_utc_dt - start_date_utc_dt).days)
|
nights = abs((end_date_utc_dt - start_date_utc_dt).days)
|
||||||
res_price = 0
|
res_price = 0
|
||||||
for i in range(0, nights):
|
for i in range(0, nights):
|
||||||
@@ -443,8 +450,7 @@ class ReservationWizard(models.TransientModel):
|
|||||||
date=ndate_str,
|
date=ndate_str,
|
||||||
pricelist=pricelist_id,
|
pricelist=pricelist_id,
|
||||||
uom=line.room_type_id.product_id.uom_id.id)
|
uom=line.room_type_id.product_id.uom_id.id)
|
||||||
res_price += self.env['account.tax']._fix_tax_included_price_company(
|
res_price += product.price
|
||||||
product.price, product.taxes_id, product.taxes_id, self.env.user.company_id)
|
|
||||||
res_price = res_price - (res_price * self.discount) * 0.01
|
res_price = res_price - (res_price * self.discount) * 0.01
|
||||||
line.amount_reservation = res_price
|
line.amount_reservation = res_price
|
||||||
line.price = res_price
|
line.price = res_price
|
||||||
@@ -469,7 +475,6 @@ class ServiceWizard(models.TransientModel):
|
|||||||
default=0.0)
|
default=0.0)
|
||||||
price_total = fields.Float(compute='_compute_amount', string='Subtotal',
|
price_total = fields.Float(compute='_compute_amount', string='Subtotal',
|
||||||
readonly=True, store=True)
|
readonly=True, store=True)
|
||||||
reservation_wizard_ids = fields.Many2many('hotel.reservation.wizard', 'Rooms')
|
|
||||||
product_uom_qty = fields.Float(string='Quantity',
|
product_uom_qty = fields.Float(string='Quantity',
|
||||||
digits=dp.get_precision('Product Unit of Measure'),
|
digits=dp.get_precision('Product Unit of Measure'),
|
||||||
required=True,
|
required=True,
|
||||||
@@ -478,70 +483,16 @@ class ServiceWizard(models.TransientModel):
|
|||||||
@api.onchange('product_id', 'reservation_wizard_ids')
|
@api.onchange('product_id', 'reservation_wizard_ids')
|
||||||
def onchange_product_id(self):
|
def onchange_product_id(self):
|
||||||
if self.product_id:
|
if self.product_id:
|
||||||
vals = {}
|
|
||||||
qty = 0
|
|
||||||
vals['product_uom_qty'] = 1.0
|
|
||||||
service_obj = self.env['hotel.service']
|
|
||||||
if self.product_id.per_day:
|
|
||||||
product = self.product_id
|
|
||||||
for room in self.reservation_wizard_ids:
|
|
||||||
lines = {}
|
|
||||||
lines.update(service_obj.prepare_service_lines(
|
|
||||||
dfrom=room.checkin,
|
|
||||||
days=room.nights,
|
|
||||||
per_person=product.per_person,
|
|
||||||
persons=room.adults))
|
|
||||||
qty += lines.get('service_line_ids')[1][2]['day_qty']
|
|
||||||
if self.product_id.daily_limit > 0:
|
|
||||||
limit = self.product_id.daily_limit
|
|
||||||
for day in self.service_line_ids:
|
|
||||||
out_qty = sum(self.env['hotel.service.line'].search([
|
|
||||||
('product_id', '=', self.product_id.id),
|
|
||||||
('date', '=', self.date),
|
|
||||||
('service_id', '!=', self.product_id.id)
|
|
||||||
]).mapped('day_qty'))
|
|
||||||
if limit < out_qty + self.day_qty:
|
|
||||||
raise ValidationError(
|
|
||||||
_("%s limit exceeded for %s")% (self.service_id.product_id.name,
|
|
||||||
self.date))
|
|
||||||
vals['product_uom_qty'] = qty
|
|
||||||
"""
|
|
||||||
Description and warnings
|
|
||||||
"""
|
|
||||||
product = self.product_id.with_context(
|
|
||||||
lang=self.folio_wizard_id.partner_id.lang,
|
|
||||||
partner=self.folio_wizard_id.partner_id.id
|
|
||||||
)
|
|
||||||
title = False
|
|
||||||
message = False
|
|
||||||
warning = {}
|
|
||||||
if product.sale_line_warn != 'no-message':
|
|
||||||
title = _("Warning for %s") % product.name
|
|
||||||
message = product.sale_line_warn_msg
|
|
||||||
warning['title'] = title
|
|
||||||
warning['message'] = message
|
|
||||||
result = {'warning': warning}
|
|
||||||
if product.sale_line_warn == 'block':
|
|
||||||
self.product_id = False
|
|
||||||
return result
|
|
||||||
"""
|
|
||||||
Compute tax and price unit
|
|
||||||
"""
|
|
||||||
#REVIEW: self._compute_tax_ids()
|
|
||||||
# TODO change pricelist for partner
|
# TODO change pricelist for partner
|
||||||
pricelist_id = self.env['ir.default'].sudo().get(
|
pricelist_id = self.folio_wizard_id.pricelist_id.id
|
||||||
'res.config.settings', 'default_pricelist_id')
|
prod = self.product_id.with_context(
|
||||||
product = self.product_id.with_context(
|
lang=self.folio_wizard_id.partner_id.lang,
|
||||||
lang=self.folio_wizard_id.partner_id.lang,
|
partner=self.folio_wizard_id.partner_id.id,
|
||||||
partner=self.folio_wizard_id.partner_id.id,
|
quantity=1,
|
||||||
quantity=1,
|
date=fields.Datetime.now(),
|
||||||
date=fields.Datetime.now(),
|
pricelist=pricelist_id,
|
||||||
pricelist=pricelist_id,
|
uom=self.product_id.uom_id.id)
|
||||||
uom=product.uom_id.id)
|
self.price_unit = prod.price
|
||||||
vals['price_unit'] = self.env['account.tax']._fix_tax_included_price_company(
|
|
||||||
product.price, product.taxes_id, product.taxes_id, self.env.user.company_id)
|
|
||||||
import wdb; wdb.set_trace()
|
|
||||||
self.update(vals)
|
|
||||||
|
|
||||||
@api.depends('price_unit', 'product_uom_qty', 'discount')
|
@api.depends('price_unit', 'product_uom_qty', 'discount')
|
||||||
def _compute_amount(self):
|
def _compute_amount(self):
|
||||||
|
|||||||
@@ -11,11 +11,12 @@
|
|||||||
<group>
|
<group>
|
||||||
<field name="checkin" required="1" />
|
<field name="checkin" required="1" />
|
||||||
<field name="checkout" required="1" />
|
<field name="checkout" required="1" />
|
||||||
|
<field name="partner_id"/>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="call_center" invisible="1" />
|
<field name="call_center" invisible="1" />
|
||||||
<field name="channel_type" required="1" attrs="{'readonly':[('call_center','=',True)]}"/>
|
<field name="channel_type" required="1" force_save="1" attrs="{'readonly':[('call_center','=',True)]}"/>
|
||||||
<field name="partner_id"/>
|
<field name="pricelist_id"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
@@ -27,13 +28,14 @@
|
|||||||
decoration-success="max_rooms >= rooms_num and rooms_num > 0">
|
decoration-success="max_rooms >= rooms_num and rooms_num > 0">
|
||||||
<field name="min_stay" />
|
<field name="min_stay" />
|
||||||
<field name="max_rooms" />
|
<field name="max_rooms" />
|
||||||
<field name="room_type_id" string="Room Type" readonly="1"/>
|
<field name="folio_wizard_id" />
|
||||||
<field name="rooms_num" attrs="{'readonly': [('can_confirm','=',False)]}" />
|
<field name="room_type_id" string="Room Type" force_save="1" readonly="1"/>
|
||||||
|
<field name="rooms_num" force_save="1" attrs="{'readonly': [('can_confirm','=',False)]}" />
|
||||||
<field name="checkin" widget="date" />
|
<field name="checkin" widget="date" />
|
||||||
<field name="checkout" widget="date" />
|
<field name="checkout" widget="date" />
|
||||||
<field name="discount" attrs="{'readonly': [('can_confirm','=',False)]}"/>
|
<field name="discount" force_save="1" attrs="{'readonly': [('can_confirm','=',False)]}"/>
|
||||||
<field name="price" attrs="{'readonly': [('can_confirm','=',False)]}"/>
|
<field name="price" force_save="1" attrs="{'readonly': [('can_confirm','=',False)]}"/>
|
||||||
<field name="amount_reservation" readonly="1" />
|
<field name="amount_reservation" force_save="1" readonly="1" />
|
||||||
<field name="total_price" invisible="1" />
|
<field name="total_price" invisible="1" />
|
||||||
<field name="can_confirm" invisible="1" />
|
<field name="can_confirm" invisible="1" />
|
||||||
</tree>
|
</tree>
|
||||||
@@ -56,7 +58,7 @@
|
|||||||
<field name="nights" />
|
<field name="nights" />
|
||||||
<field name="adults" />
|
<field name="adults" />
|
||||||
<field name="children" />
|
<field name="children" />
|
||||||
<field name="discount" />
|
<field name="discount" />
|
||||||
<field name="amount_reservation" />
|
<field name="amount_reservation" />
|
||||||
<field name="price" invisible = "1"/>
|
<field name="price" invisible = "1"/>
|
||||||
<field name="partner_id" invisible = "1" />
|
<field name="partner_id" invisible = "1" />
|
||||||
@@ -76,8 +78,6 @@
|
|||||||
<field name="product_uom_qty" />
|
<field name="product_uom_qty" />
|
||||||
<field name="price_unit" />
|
<field name="price_unit" />
|
||||||
<field name="discount" />
|
<field name="discount" />
|
||||||
<field name="reservation_wizard_ids" widget="many2many_tags"
|
|
||||||
domain="[('folio_wizard_id', '=', folio_wizard_id)]"/>
|
|
||||||
<field name="price_total" />
|
<field name="price_total" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user