2021-01-23 16:56:32 +01:00
|
|
|
# This file is part of Presik. The COPYRIGHT file at the top level of
|
2020-04-16 14:45:13 +02:00
|
|
|
# this repository contains the full copyright notices and license terms.
|
2022-03-19 06:21:49 +01:00
|
|
|
from decimal import Decimal
|
2020-04-16 14:45:13 +02:00
|
|
|
from trytond.model import ModelView, ModelSQL, fields
|
|
|
|
from trytond.pyson import Eval, If
|
|
|
|
from trytond.transaction import Transaction
|
|
|
|
from trytond.pool import Pool
|
2022-03-20 01:11:41 +01:00
|
|
|
from .constants import PAYMENT_METHOD_CHANNEL
|
2020-04-16 14:45:13 +02:00
|
|
|
|
|
|
|
|
2022-05-18 00:34:42 +02:00
|
|
|
class ChannelCommission(ModelSQL, ModelView):
|
|
|
|
'Channel Commission Extra'
|
|
|
|
__name__ = 'hotel.channel.commission'
|
|
|
|
channel = fields.Many2One('hotel.channel', 'Sale Channel',
|
|
|
|
ondelete='CASCADE', select=True, required=True)
|
|
|
|
name = fields.Char('Name', required=True)
|
|
|
|
commission = fields.Float('Commission', required=True, digits=(4, 2))
|
|
|
|
|
|
|
|
|
2020-04-16 14:45:13 +02:00
|
|
|
class SaleChannel(ModelSQL, ModelView):
|
|
|
|
'Sale Channel'
|
|
|
|
__name__ = 'hotel.channel'
|
|
|
|
name = fields.Char('Name', required=True)
|
2022-07-22 17:36:13 +02:00
|
|
|
code = fields.Selection([
|
2022-07-24 17:02:51 +02:00
|
|
|
(None, ''),
|
2022-07-22 17:36:13 +02:00
|
|
|
('booking', 'Booking'),
|
|
|
|
('despegar', 'Despegar'),
|
|
|
|
('expedia', 'Expedia'),
|
|
|
|
], 'Code', required=False)
|
2021-11-24 22:49:39 +01:00
|
|
|
agent = fields.Many2One('commission.agent', 'Agent', required=True)
|
2020-04-16 14:45:13 +02:00
|
|
|
type_commission = fields.Selection([
|
|
|
|
('percentage', 'Percentage'),
|
|
|
|
('fixed', 'Fixed'),
|
2022-03-19 06:21:49 +01:00
|
|
|
], 'Type Commission', required=True)
|
2022-07-23 01:07:58 +02:00
|
|
|
invoice_to = fields.Selection([
|
|
|
|
('channel', 'Channel'),
|
|
|
|
('customer', 'Customer'),
|
|
|
|
], 'Invoice To', required=True)
|
2022-03-19 06:21:49 +01:00
|
|
|
# Remove this field
|
2020-04-16 14:45:13 +02:00
|
|
|
company = fields.Many2One('company.company', 'Company', required=True,
|
|
|
|
domain=[
|
|
|
|
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
|
|
|
Eval('context', {}).get('company', 0)),
|
2021-07-26 03:05:54 +02:00
|
|
|
], select=True)
|
2022-03-19 06:21:49 +01:00
|
|
|
commission = fields.Float('Commission', required=True, digits=(4, 2))
|
2020-04-16 14:45:13 +02:00
|
|
|
debit_account = fields.Many2One('account.account', 'Debit Account',
|
|
|
|
domain=[
|
|
|
|
('company', '=', Eval('company')),
|
2022-03-27 00:13:22 +01:00
|
|
|
('type', '!=', None),
|
2022-03-19 06:21:49 +01:00
|
|
|
],
|
2020-04-16 14:45:13 +02:00
|
|
|
depends=['company', 'type_commission'])
|
|
|
|
credit_account = fields.Many2One('account.account', 'Credit Account',
|
|
|
|
domain=[
|
|
|
|
('company', '=', Eval('company')),
|
2022-03-27 00:13:22 +01:00
|
|
|
('type', '!=', None),
|
2022-03-19 06:21:49 +01:00
|
|
|
],
|
2020-04-16 14:45:13 +02:00
|
|
|
depends=['company', 'type_commission'])
|
|
|
|
taxes = fields.Many2Many('hotel.channel-account.tax',
|
|
|
|
'channel', 'tax', 'Channel Taxes',
|
2021-11-25 04:52:03 +01:00
|
|
|
domain=[
|
|
|
|
('parent', '=', None), ['OR',
|
2020-04-16 14:45:13 +02:00
|
|
|
('group', '=', None),
|
|
|
|
('group.kind', 'in', ['purchase', 'both'])],
|
2021-11-25 04:52:03 +01:00
|
|
|
]
|
|
|
|
)
|
2020-04-16 14:45:13 +02:00
|
|
|
currency = fields.Many2One('currency.currency', 'Currency',
|
2022-05-18 00:34:42 +02:00
|
|
|
required=True)
|
2021-01-23 16:56:32 +01:00
|
|
|
price_list = fields.Many2One('product.price_list', 'Price List')
|
2022-07-22 17:36:13 +02:00
|
|
|
payment_mode = fields.Many2One('account.voucher.paymode',
|
|
|
|
'Receipt - Payment Mode', domain=[
|
|
|
|
('company', 'in', [Eval('company', -1), None]),
|
|
|
|
])
|
2022-05-18 00:34:42 +02:00
|
|
|
payment_method = fields.Selection(PAYMENT_METHOD_CHANNEL, 'Payment Method')
|
2022-03-20 01:11:41 +01:00
|
|
|
collection_mode = fields.Selection([
|
|
|
|
('', ''),
|
|
|
|
('anticipated', 'Anticipated'),
|
|
|
|
('after_sale', 'After-Sale'),
|
2022-05-18 00:34:42 +02:00
|
|
|
], 'Collection Mode', required=False,
|
|
|
|
help="Commission collection mode")
|
|
|
|
extra_commissions = fields.One2Many('hotel.channel.commission',
|
|
|
|
'channel', 'Extra Commissions')
|
2020-04-16 14:45:13 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def default_company():
|
|
|
|
return Transaction().context.get('company')
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def default_currency():
|
|
|
|
Company = Pool().get('company.company')
|
|
|
|
company = Transaction().context.get('company')
|
|
|
|
if company:
|
|
|
|
return Company(company).currency.id
|
|
|
|
|
2022-03-19 06:21:49 +01:00
|
|
|
def compute(self, amount):
|
|
|
|
res = Decimal(round(float(amount) * self.commission / 100, 2))
|
|
|
|
return res
|
|
|
|
|
2020-04-16 14:45:13 +02:00
|
|
|
|
|
|
|
class ChannelTax(ModelSQL):
|
|
|
|
'Channel - Tax'
|
|
|
|
__name__ = 'hotel.channel-account.tax'
|
|
|
|
_table = 'hotel_channel_taxes_rel'
|
|
|
|
channel = fields.Many2One('hotel.channel', 'Sale Channel',
|
|
|
|
ondelete='CASCADE', select=True, required=True)
|
|
|
|
tax = fields.Many2One('account.tax', 'Tax', ondelete='RESTRICT',
|
|
|
|
required=True)
|