[FIX] unit price computed taxes

This commit is contained in:
Dario Lodeiros
2019-03-13 15:21:10 +01:00
parent 623fe2f263
commit 8cb90d7264
4 changed files with 57 additions and 106 deletions

View File

@@ -891,8 +891,8 @@ class HotelReservation(models.Model):
date=idate,
pricelist=pricelist_id,
uom=product.uom_id.id)
line_price = self.env['account.tax']._fix_tax_included_price_company(
product.price, product.taxes_id, self.tax_ids, self.company_id)
# REVIEW this forces to have configured the taxes included in the price
line_price = product.price
if old_line and old_line.id:
cmds.append((1, old_line.id, {
'price': line_price

View File

@@ -8,7 +8,7 @@
<xpath expr="//field[@name='communication']" position="after">
<field name="folio_id"/>
<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"/>
</xpath>
</field>

View File

@@ -49,7 +49,17 @@ class FolioWizard(models.TransientModel):
if user.has_group('hotel.group_hotel_call'):
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,
default=_get_default_checkin)
checkout = fields.Date('Check Out', required=True,
@@ -68,13 +78,28 @@ class FolioWizard(models.TransientModel):
('mail', 'Mail'),
('phone', 'Phone')
], string='Sales Channel', default=_get_default_channel_type)
room_type_wizard_ids = fields.Many2many('hotel.room.type.wizard',
string="Room Types")
room_type_wizard_ids = fields.One2many('hotel.room.type.wizard',
'folio_wizard_id',
string="Room Types")
call_center = fields.Boolean(default=_get_default_center_user)
def assign_rooms(self):
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')
def create_reservations(self):
self.ensure_one()
@@ -103,10 +128,7 @@ class FolioWizard(models.TransientModel):
checkout_dt = fields.Date.from_string(line.checkout)
nights = abs((checkout_dt - checkin_dt).days)
for room in room_list:
pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_pricelist_id')
if pricelist_id:
pricelist_id = int(pricelist_id)
pricelist_id = self.pricelist_id.id
res_price = 0
for i in range(0, nights):
ndate = checkin_dt + timedelta(days=i)
@@ -198,6 +220,7 @@ class FolioWizard(models.TransientModel):
services = [(5, False, False)]
if self.autoassign:
self.create_reservations()
import wdb; wdb.set_trace()
for line in self.reservation_wizard_ids:
reservations.append((0, False, {
'room_id': line.room_id.id,
@@ -297,16 +320,9 @@ class HotelRoomTypeWizards(models.TransientModel):
dates.append(ndate_str)
if minstay_restrictions:
date_min_days = minstay_restrictions.filtered(
lambda r: r.date_start <= ndate_str and \
r.date_end >= ndate_str).min_stay
lambda r: r.date == ndate_str).min_stay
if date_min_days > min_stay:
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:
avail = real_max
@@ -330,12 +346,7 @@ class HotelRoomTypeWizards(models.TransientModel):
if chkin_utc_dt >= chkout_utc_dt:
chkout_utc_dt = chkin_utc_dt + timedelta(days=1)
nights = abs((chkout_utc_dt - chkin_utc_dt).days)
pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_pricelist_id')
if pricelist_id:
pricelist_id = int(pricelist_id)
pricelist_id = self.folio_wizard_id.pricelist_id.id
res_price = 0
for i in range(0, nights):
ndate = chkin_utc_dt + timedelta(days=i)
@@ -347,8 +358,7 @@ class HotelRoomTypeWizards(models.TransientModel):
date=ndate_str,
pricelist=pricelist_id,
uom=record.room_type_id.product_id.uom_id.id)
res_price += self.env['account.tax']._fix_tax_included_price_company(
product.price, product.taxes_id, product.taxes_id, self.env.user.company_id)
res_price += product.price
price = res_price - ((res_price * record.discount) * 0.01)
total_price = record.rooms_num * price
@@ -427,10 +437,7 @@ class ReservationWizard(models.TransientModel):
end_date_utc_dt = fields.Date.from_string(line.checkout)
if line.room_type_id:
pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_pricelist_id')
if pricelist_id:
pricelist_id = int(pricelist_id)
pricelist_id = self.folio_wizard_id.pricelist_id.id
nights = abs((end_date_utc_dt - start_date_utc_dt).days)
res_price = 0
for i in range(0, nights):
@@ -443,8 +450,7 @@ class ReservationWizard(models.TransientModel):
date=ndate_str,
pricelist=pricelist_id,
uom=line.room_type_id.product_id.uom_id.id)
res_price += self.env['account.tax']._fix_tax_included_price_company(
product.price, product.taxes_id, product.taxes_id, self.env.user.company_id)
res_price += product.price
res_price = res_price - (res_price * self.discount) * 0.01
line.amount_reservation = res_price
line.price = res_price
@@ -469,7 +475,6 @@ class ServiceWizard(models.TransientModel):
default=0.0)
price_total = fields.Float(compute='_compute_amount', string='Subtotal',
readonly=True, store=True)
reservation_wizard_ids = fields.Many2many('hotel.reservation.wizard', 'Rooms')
product_uom_qty = fields.Float(string='Quantity',
digits=dp.get_precision('Product Unit of Measure'),
required=True,
@@ -478,70 +483,16 @@ class ServiceWizard(models.TransientModel):
@api.onchange('product_id', 'reservation_wizard_ids')
def onchange_product_id(self):
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
pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_pricelist_id')
product = self.product_id.with_context(
lang=self.folio_wizard_id.partner_id.lang,
partner=self.folio_wizard_id.partner_id.id,
quantity=1,
date=fields.Datetime.now(),
pricelist=pricelist_id,
uom=product.uom_id.id)
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)
pricelist_id = self.folio_wizard_id.pricelist_id.id
prod = self.product_id.with_context(
lang=self.folio_wizard_id.partner_id.lang,
partner=self.folio_wizard_id.partner_id.id,
quantity=1,
date=fields.Datetime.now(),
pricelist=pricelist_id,
uom=self.product_id.uom_id.id)
self.price_unit = prod.price
@api.depends('price_unit', 'product_uom_qty', 'discount')
def _compute_amount(self):

View File

@@ -11,11 +11,12 @@
<group>
<field name="checkin" required="1" />
<field name="checkout" required="1" />
<field name="partner_id"/>
</group>
<group>
<field name="call_center" invisible="1" />
<field name="channel_type" required="1" attrs="{'readonly':[('call_center','=',True)]}"/>
<field name="partner_id"/>
<field name="channel_type" required="1" force_save="1" attrs="{'readonly':[('call_center','=',True)]}"/>
<field name="pricelist_id"/>
</group>
</group>
<group>
@@ -27,13 +28,14 @@
decoration-success="max_rooms &gt;= rooms_num and rooms_num &gt; 0">
<field name="min_stay" />
<field name="max_rooms" />
<field name="room_type_id" string="Room Type" readonly="1"/>
<field name="rooms_num" attrs="{'readonly': [('can_confirm','=',False)]}" />
<field name="folio_wizard_id" />
<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="checkout" widget="date" />
<field name="discount" attrs="{'readonly': [('can_confirm','=',False)]}"/>
<field name="price" attrs="{'readonly': [('can_confirm','=',False)]}"/>
<field name="amount_reservation" readonly="1" />
<field name="discount" force_save="1" attrs="{'readonly': [('can_confirm','=',False)]}"/>
<field name="price" force_save="1" attrs="{'readonly': [('can_confirm','=',False)]}"/>
<field name="amount_reservation" force_save="1" readonly="1" />
<field name="total_price" invisible="1" />
<field name="can_confirm" invisible="1" />
</tree>
@@ -56,7 +58,7 @@
<field name="nights" />
<field name="adults" />
<field name="children" />
<field name="discount" />
<field name="discount" />
<field name="amount_reservation" />
<field name="price" invisible = "1"/>
<field name="partner_id" invisible = "1" />
@@ -76,8 +78,6 @@
<field name="product_uom_qty" />
<field name="price_unit" />
<field name="discount" />
<field name="reservation_wizard_ids" widget="many2many_tags"
domain="[('folio_wizard_id', '=', folio_wizard_id)]"/>
<field name="price_total" />
</tree>
</field>