Refactory 07

This commit is contained in:
Oscar 2021-10-10 18:52:01 -05:00
parent f26cf50bca
commit 75ee48a402
5 changed files with 52 additions and 398 deletions

BIN
folio (copy).fodt Normal file

Binary file not shown.

Binary file not shown.

445
folio.py
View File

@ -70,6 +70,8 @@ class Folio(ModelSQL, ModelView):
'required': Bool(Eval('product')),
'readonly': Eval('registration_state') == 'check_in',
})
unit_price_w_tax = fields.Function(fields.Numeric('Unit Price'),
'get_unit_price_w_tax')
uom = fields.Many2One('product.uom', 'UOM', readonly=True)
main_guest = fields.Many2One('party.party', 'Main Guest', select=True,
states={
@ -108,14 +110,18 @@ class Folio(ModelSQL, ModelView):
'readonly': Eval('registration_state').in_(['check_out']),
})
invoice_line = fields.Many2One('account.invoice.line', 'Invoice Line')
invoice = fields.Function(fields.Many2One('account.invoice', 'Invoice'),
'get_invoice')
invoice = fields.Function(fields.Many2One('account.invoice', 'Invoice',
depends=['invoice_line']), 'get_invoice')
invoice_state = fields.Selection(INVOICE_STATES, 'Invoice State', readonly=True)
type_complementary = fields.Selection(COMPLEMENTARY, 'Type Complementary',
states={
'invisible': ~Bool(Eval('complementary')),
'required': Bool(Eval('complementary')),
})
room_amount = fields.Function(fields.Numeric('Room Amount',
digits=(16, 2)), 'get_room_amount')
stock_moves = fields.Many2Many('hotel.operation-stock.move', 'operation',
'move', 'Stock Moves', states={'readonly': True})
@classmethod
def __setup__(cls):
@ -194,8 +200,8 @@ class Folio(ModelSQL, ModelView):
@ModelView.button
def bill(cls, records):
for rec in records:
# if rec.complementary:
# return
if rec.type_complementary:
continue
cls.create_invoice(rec)
def set_registration_number(self):
@ -217,7 +223,6 @@ class Folio(ModelSQL, ModelView):
@classmethod
def create_invoice(cls, record):
pool = Pool()
Date = pool.get('ir.date')
InvoiceLine = pool.get('account.invoice.line')
FolioCharge = pool.get('hotel.folio.charge')
Configuration = pool.get('hotel.configuration')
@ -226,7 +231,6 @@ class Folio(ModelSQL, ModelView):
# date_ = Date.today()
# ctx = {}
invoice_to_create = cls.get_grouped_invoices([record])
print(invoice_to_create)
for rec in invoice_to_create.values():
# if rec.get('price_list'):
# ctx['price_list'] = rec.get('price_list')
@ -264,7 +268,6 @@ class Folio(ModelSQL, ModelView):
if new_line:
InvoiceLine.create([new_line])
print('XXXXX', rec)
for _line in rec['lines']:
line, = InvoiceLine.create([
cls._get_invoice_line(invoice, _line, rec)
@ -279,6 +282,7 @@ class Folio(ModelSQL, ModelView):
'invoice_line': line.id,
'state': 'invoiced',
})
invoice.save()
@classmethod
def _get_invoice_line(cls, invoice, line, record):
@ -296,12 +300,37 @@ class Folio(ModelSQL, ModelView):
'party': invoice.party.id,
'description': line['description'],
}
print(line['taxes_exception'])
if not line['taxes_exception']:
taxes_ids = cls.get_taxes(invoice, line['product'], record)
print(taxes_ids)
if taxes_ids:
new_line.update({'taxes': [('add', taxes_ids)]})
return new_line
def get_unit_price_w_tax(self, name=None):
Tax = Pool().get('account.tax')
res = self.unit_price or 0
if self.unit_price:
values = Tax.compute(
self.product.template.customer_taxes_used,
self.unit_price, 1)
if values:
value = values[0]
res = value['base'] + value['amount']
return res
def get_room_amount(self, name=None):
res = 0
Date = Pool().get('ir.date')
if self.unit_price_w_tax and self.nights_quantity:
if name == 'room_amount':
res = self.unit_price_w_tax * self.nights_quantity
else:
delta = (Date.today() - self.start_date).days
res = self.unit_price_w_tax * delta
return round(res, Folio.total_amount.digits[1])
@classmethod
def get_taxes(cls, invoice, product, rec):
ctx = cls.get_context_price(invoice, product, rec)
@ -359,7 +388,7 @@ class Folio(ModelSQL, ModelView):
def get_invoice(self, name=None):
if self.invoice_line and self.invoice_line.invoice:
self.invoice_line.invoice.id
return self.invoice_line.invoice.id
# @fields.depends('accommodation', 'product')
# def on_change_accommodation(self):
@ -764,108 +793,6 @@ class HotelCharge(Workflow, ModelSQL, ModelView):
self.description = self.product.description
# class Operation(Workflow, ModelSQL, ModelView):
# 'Operation'
# __name__ = 'hotel.operation'
# _rec_name = 'reference'
# reference = fields.Char('Reference', select=True, readonly=True)
# kind = fields.Selection([
# ('occupancy', 'Occupancy'),
# ('maintenance', 'Maintenance'),
# ('statement', 'Statement'),
# ], 'Kind')
# party = fields.Many2One('party.party', 'Party', select=True,
# states=STATES_OP, required=True)
# main_guest = fields.Many2One('party.party', 'Main Guest', select=True,
# states=STATES_OP, required=True)
# room = fields.Many2One('hotel.room', 'Room', select=True, required=False,
# states=STATES_OP)
# accommodation = fields.Many2One('product.product', 'Accommodation Product',
# domain=[('kind', '=', 'accommodation')], states=STATES_OP)
# start_date = fields.Date('Arrival Date', states=STATES_OP)
# end_date = fields.Date('Departure Date', states=STATES_OP)
# description = fields.Char('Description', states=STATES_OP)
# state = fields.Selection(OPERATION_STATES, 'State', readonly=True)
# state_string = state.translated('state')
# invoice_state = fields.Selection(INVOICE_STATES, 'Invoice State',
# readonly=True)
# lines = fields.One2Many('hotel.folio.charge', 'operation', 'Lines',
# states=STATES_OP)
# origin = fields.Reference('Origin', selection='get_origin', select=True,
# states={'readonly': True})
# guests = fields.One2Many('hotel.operation.guest', 'operation',
# 'Guests', add_remove=[], states=STATES_OP)
# price_list = fields.Many2One('product.price_list', 'Price List',
# states=STATES_OP, depends=['state', 'lines'])
# currency = fields.Many2One('currency.currency', 'Currency',
# required=True, depends=['state'])
# nights_quantity = fields.Function(fields.Integer('Nights'),
# 'get_nights_quantity')
# unit_price = fields.Numeric('Unit Price', digits=(16, 4), states=STATES_OP)
# unit_price_w_tax = fields.Function(fields.Numeric('Unit Price With Tax'),
# 'get_unit_price_w_tax')
# taxes_exception = fields.Boolean('Taxes Exception', states=STATES_OP)
# breakfast_included = fields.Boolean('Breakfast Included', states=STATES_OP)
# add_default_charges = fields.Boolean('Add Default Charges', states=STATES_OP)
# # sale = fields.Function(fields.Many2One('sale.sale', 'Sale'), 'get_sale')
# sale_line = fields.Many2One('sale.line', 'Sale Line', select=True)
# company = fields.Many2One('company.company', 'Company', states=STATES_OP)
# total_amount = fields.Function(fields.Numeric('Total Amount',
# digits=(16, 2)), 'get_total_amount')
# total_amount_today = fields.Function(fields.Numeric('Total Amount Today',
# digits=(16, 2)), 'get_total_amount')
# room_amount = fields.Function(fields.Numeric('Room Amount',
# digits=(16, 2)), 'get_room_amount')
# room_amount_today = fields.Function(fields.Numeric('Room Amount Today',
# digits=(16, 2)), 'get_room_amount')
# pending_payment = fields.Function(fields.Numeric('Pending Payment',
# digits=(16, 2)), 'get_pending_payment')
# notes = fields.Text('Notes', select=True, states=STATES_OP)
# complementary = fields.Boolean('Complementary', states=STATES_OP)
# type_complementary = fields.Selection(COMPLEMENTARY, 'Type Complementary', states={
# 'invisible': ~Bool(Eval('complementary')),
# 'required': Bool(Eval('complementary')),
# })
# operation_target = fields.Many2One('hotel.operation', 'Operation Target')
# transfered_operations = fields.One2Many('hotel.operation',
# 'operation_target', 'Transfered Operations', states=STATES_OP)
# vouchers = fields.Many2Many('hotel.operation-account.voucher', 'operation',
# 'voucher', 'Vouchers', states=STATES_OP, domain=[], depends=['party'])
# agent = fields.Many2One('commission.agent', 'Agent')
# # stock_moves = fields.Many2Many('hotel.operation-stock.move', 'operation',
# # 'move', 'Stock Moves', states={'readonly': True})
#
# @classmethod
# def __setup__(cls):
# super(Operation, cls).__setup__()
# cls._transitions |= set((
# ('draft', 'open'),
# ('draft', 'cancelled'),
# ('open', 'draft'),
# ('open', 'closed'),
# ('closed', 'open'),
# ))
# cls._buttons.update({
# 'draft': {
# 'invisible': True,
# },
# 'open': {
# 'invisible': Eval('state') != 'draft',
# },
# 'close': {
# 'invisible': Eval('state') == 'closed',
# },
# 'cancel': {
# 'invisible': Eval('state') != 'draft',
# },
# 'bill': {
# 'invisible': Eval('invoice_state') == 'invoiced',
# },
# 'pay_advance': {
# 'invisible': Eval('state') == 'closed',
# },
# })
#
# @classmethod
# def validate(cls, records):
# super(Operation, cls).validate(records)
@ -948,96 +875,11 @@ class HotelCharge(Workflow, ModelSQL, ModelView):
# return round(sum(res), Operation.total_amount.digits[1])
# return _ZERO
#
# def get_room_amount(self, name=None):
# res = 0
# Date = Pool().get('ir.date')
# if self.unit_price_w_tax and self.nights_quantity:
# if name == 'room_amount':
# res = self.unit_price_w_tax * self.nights_quantity
# else:
# delta = (Date.today() - self.start_date).days
# res = self.unit_price_w_tax * delta
# return round(res, Operation.total_amount.digits[1])
#
# @staticmethod
# def default_invoice_state():
# return 'pending'
#
# @staticmethod
# def default_company():
# return Transaction().context.get('company')
#
# @staticmethod
# def default_currency():
# Company = Pool().get('company.company')
# company = Company(Transaction().context.get('company'))
# return company.currency.id
#
# @staticmethod
# def default_state():
# return 'draft'
#
# @staticmethod
# def default_kind():
# return 'occupancy'
#
# @classmethod
# def search_rec_name(cls, name, clause):
# _, operator, value = clause
# if operator.startswith('!') or operator.startswith('not '):
# bool_op = 'AND'
# else:
# bool_op = 'OR'
# domain = [
# bool_op,
# ('main_guest', operator, value),
# ('reference', operator, value),
# ('room.name', operator, value),
# ('party.name', operator, value),
# ]
# return domain
#
# @classmethod
# @ModelView.button
# @Workflow.transition('open')
# def open(cls, records):
# for rec in records:
# rec.update_housekeeping('check_in')
#
# @classmethod
# @ModelView.button
# @Workflow.transition('closed')
# def close(cls, records):
# pass
# # for rec in records:
# # rec.update_housekeeping('check_out')
#
# @classmethod
# @ModelView.button
# def bill(cls, records):
# for rec in records:
# if rec.complementary:
# return
# cls.create_sales([rec])
#
# @classmethod
# @ModelView.button
# @Workflow.transition('draft')
# def draft(cls, records):
# pass
#
# @classmethod
# @ModelView.button
# @Workflow.transition('cancelled')
# def cancel(cls, records):
# pass
#
# @classmethod
# @ModelView.button_action('hotel.wizard_operation_check_out')
# def check_out_wizard(cls, records):
# pass
#
# @classmethod
# @ModelView.button_action('hotel.wizard_operation_advance_voucher')
# def pay_advance(cls, records):
# pass
@ -1082,16 +924,6 @@ class HotelCharge(Workflow, ModelSQL, ModelView):
# return ['hotel.operation.maintenance', 'hotel.folio']
#
# @classmethod
# def copy(cls, operations, default=None):
# if default is None:
# default = {}
# else:
# default = default.copy()
# default.setdefault('state', 'draft')
# default.setdefault('invoice_state', '')
# return super(Operation, cls).copy(operations, default=default)
#
# @classmethod
# def get_origin(cls):
# Model = Pool().get('ir.model')
# models = cls._get_origin()
@ -1147,16 +979,16 @@ class HotelCharge(Workflow, ModelSQL, ModelView):
# })
# return [resources, events]
#
# # @classmethod
# # def validate(cls, operations):
# # for op in operations:
# # op.check_dates(
# # op.start_date,
# # op.end_date,
# # op.room,
# # op,
# # )
# # super(Operation, cls).validate(operations)
# @classmethod
# def validate(cls, operations):
# for op in operations:
# op.check_dates(
# op.start_date,
# op.end_date,
# op.room,
# op,
# )
# super(Operation, cls).validate(operations)
#
# @classmethod
# def get_available_rooms(cls, start_date, end_date, rooms_ids=[], oper=None):
@ -1217,159 +1049,6 @@ class HotelCharge(Workflow, ModelSQL, ModelView):
# if room.id not in available_rooms:
# raise AccessError(gettext('hotel.overlap_operation_line', s=room.name))
#
# def get_nights_quantity(self, name=None):
# """
# Compute nights between start and end
# return a integer the mean days of occupancy.
# """
# nights = 0
# if self.start_date and self.end_date:
# nights = (self.end_date - self.start_date).days
# return nights
#
# @classmethod
# def get_room_info(cls, op):
# description = ' \n'.join([
# op.accommodation.rec_name,
# 'Huesped Principal: ' + op.main_guest.name,
# 'Habitacion: ' + op.room.name,
# 'Llegada: ' + str(op.start_date),
# 'Salida: ' + str(op.end_date),
# ])
# return description
#
# @classmethod
# def get_grouped_sales(cls, operations):
# res = {}
# transfered = []
# for op in operations:
# for top in op.transfered_operations:
# top.party = op.party
# transfered.append(top)
#
# operations.extend(transfered)
# filtered_ops = [op for op in operations if op.invoice_state == 'pending']
# for op in filtered_ops:
# if op.party.id not in res.keys():
# # Add room product to sale
# res[op.party.id] = {
# 'party': op.party.id,
# 'currency': op.currency.id,
# 'payment_term': None,
# 'guests_qty': len(op.guests) + 1,
# 'reference': op.reference,
# 'agent': op.agent or None,
# 'rooms': op.room.name,
# 'company': op.company.id,
# 'add_default_charges': op.add_default_charges,
# 'vouchers': op.vouchers,
# 'lines': [{
# 'operations': [op],
# 'description': cls.get_room_info(op),
# 'quantity': op.nights_quantity,
# 'product': op.accommodation,
# 'unit_price': op.unit_price,
# 'taxes_exception': op.taxes_exception,
# }]
# }
# else:
# res[op.party.id]['rooms'] += ' ' + op.room.name
# res[op.party.id]['lines'].append({
# 'operations': [op],
# 'description': cls.get_room_info(op),
# 'quantity': op.nights_quantity,
# 'product': op.accommodation,
# 'unit_price': op.unit_price,
# 'taxes_exception': op.taxes_exception,
# })
# for line in op.lines:
# if line.sale_line:
# continue
# invoice_party_id = line.invoice_to.id
# unit_price = op.currency.round(line.unit_price)
# if invoice_party_id != op.party.id:
# if invoice_party_id not in res.keys():
# res[invoice_party_id] = {
# 'party': line.invoice_to.id,
# 'currency': op.currency.id,
# 'payment_term': None,
# 'lines': [],
# }
# res[invoice_party_id]['lines'].append({
# 'description': ' | '.join([
# str(line.date_service),
# line.order or '',
# line.description or ''
# ]),
# 'quantity': line.quantity,
# 'product': line.product,
# 'operation_line': line,
# 'unit_price': unit_price,
# 'operation_line': line,
# 'taxes_exception': op.taxes_exception,
# })
# return res
#
# @classmethod
# def create_sales(cls, records):
# pool = Pool()
# Date = pool.get('ir.date')
# SaleLine = pool.get('sale.line')
# FolioCharge = pool.get('hotel.folio.charge')
# Configuration = pool.get('hotel.configuration')
# SaleVoucher = pool.get('sale.sale-account.voucher')
# configuration = Configuration.get_configuration()
# date_ = Date.today()
# ctx = {}
# sales_to_create = cls.get_grouped_sales(records)
# for rec in sales_to_create.values():
# if rec.get('price_list'):
# ctx['price_list'] = rec.get('price_list')
# ctx['sale_date'] = date_
# ctx['currency'] = rec['currency']
# ctx['customer'] = rec.party.id
#
# sale = cls._get_new_sale(rec)
# sale.save()
# if rec.get('vouchers'):
# for v in rec['vouchers']:
# SaleVoucher.create([{
# 'voucher': v.id,
# 'sale': sale.id
# }])
#
# # Add and create default charges lines if exists
# if rec.get('guests_qty') and rec.get('add_default_charges'):
# for product in configuration.default_charges:
# if rec.party:
# taxes_ids = cls.get_taxes(sale, product)
# new_line = {
# 'sale': sale.id,
# 'type': 'line',
# 'unit': product.template.default_uom.id,
# 'quantity': rec['guests_qty'],
# 'unit_price': product.template.list_price,
# 'product': product.id,
# 'description': product.rec_name,
# }
# if taxes_ids:
# new_line.update({'taxes': [('add', taxes_ids)]})
# if new_line:
# SaleLine.create([new_line])
#
# for _line in rec['lines']:
# line, = SaleLine.create([cls._get_sale_line(sale, _line)])
# if _line.get('operations'):
# cls.write(_line.get('operations'), {
# 'sale_line': line.id,
# 'invoice_state': 'in_process'
# })
# else:
# FolioCharge.write([_line.get('operation_line')], {
# 'sale_line': line.id,
# 'state': 'invoiced',
# })
#
# @classmethod
# def get_context_price(cls, sale, product):
# context = {}
@ -1401,36 +1080,6 @@ class HotelCharge(Workflow, ModelSQL, ModelView):
# def get_taxes(cls, sale, product):
# ctx = cls.get_context_price(sale, product)
# return ctx['taxes']
#
# @classmethod
# def _get_sale_line(cls, sale, line):
# new_line = {
# 'sale': sale.id,
# 'type': 'line',
# 'unit': line['product'].template.default_uom.id,
# 'quantity': line['quantity'],
# 'unit_price': line['unit_price'],
# 'product': line['product'].id,
# 'description': line['description'],
# }
# if not line['taxes_exception']:
# taxes_ids = cls.get_taxes(sale, line['product'])
# if taxes_ids:
# new_line.update({'taxes': [('add', taxes_ids)]})
# return new_line
#
#
# class OperationGuest(ModelSQL, ModelView):
# 'Operation Guest'
# __name__ = 'hotel.operation.guest'
# _rec_name = 'party'
# operation = fields.Many2One('hotel.operation', 'Operation',
# required=True, ondelete='CASCADE')
# party = fields.Many2One('party.party', 'Party', required=True)
#
# def get_rec_name(self, name):
# if self.party:
# return self.party.name
class OperationMaintenance(Workflow, ModelSQL, ModelView):

View File

@ -33,6 +33,9 @@ this repository contains the full copyright notices and license terms. -->
<page string="Guests" id="hotel_guests">
<field name="guests" colspan="4"/>
</page>
<page string="Stock" id="stock">
<field name="stock_moves" colspan="4"/>
</page>
<page string="Additional Info" id="folio_additional_info">
<label name="nationality"/>
<field name="nationality"/>

View File

@ -20,6 +20,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="total_amount"/>
<label name="host_quantity"/>
<field name="host_quantity"/>
<label name="invoice"/>
<field name="invoice"/>
<notebook colspan="6">
<page string="Charges" id="hotel_charges">
<field name="charges" colspan="4"/>