mirror of
https://bitbucket.org/presik/trytonpsk-hotel.git
synced 2023-12-14 07:52:52 +01:00
86 lines
3.1 KiB
Python
86 lines
3.1 KiB
Python
# This file is part of Presik. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
from decimal import Decimal
|
|
from trytond.model import ModelView, ModelSQL, fields
|
|
from trytond.pyson import Eval, If
|
|
from trytond.transaction import Transaction
|
|
from trytond.pool import Pool
|
|
|
|
|
|
class SaleChannel(ModelSQL, ModelView):
|
|
'Sale Channel'
|
|
__name__ = 'hotel.channel'
|
|
name = fields.Char('Name', required=True)
|
|
agent = fields.Many2One('commission.agent', 'Agent', required=True)
|
|
type_commission = fields.Selection([
|
|
('percentage', 'Percentage'),
|
|
('fixed', 'Fixed'),
|
|
], 'Type Commission', required=True)
|
|
# Remove this field
|
|
company = fields.Many2One('company.company', 'Company', required=True,
|
|
domain=[
|
|
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
|
Eval('context', {}).get('company', 0)),
|
|
], select=True)
|
|
commission = fields.Float('Commission', required=True, digits=(4, 2))
|
|
debit_account = fields.Many2One('account.account', 'Debit Account',
|
|
domain=[
|
|
('company', '=', Eval('company')),
|
|
('kind', 'not in', ['view']),
|
|
],
|
|
depends=['company', 'type_commission'])
|
|
credit_account = fields.Many2One('account.account', 'Credit Account',
|
|
domain=[
|
|
('company', '=', Eval('company')),
|
|
('kind', 'not in', ['view']),
|
|
],
|
|
depends=['company', 'type_commission'])
|
|
taxes = fields.Many2Many('hotel.channel-account.tax',
|
|
'channel', 'tax', 'Channel Taxes',
|
|
domain=[
|
|
('parent', '=', None), ['OR',
|
|
('group', '=', None),
|
|
('group.kind', 'in', ['purchase', 'both'])],
|
|
]
|
|
)
|
|
currency = fields.Many2One('currency.currency', 'Currency',
|
|
required=True)
|
|
price_list = fields.Many2One('product.price_list', 'Price List')
|
|
payment_method = fields.Selection([
|
|
('', ''),
|
|
('on_booking', 'On Booking'),
|
|
('on_check_out', 'On Check Out'),
|
|
], 'Payment Method', required=True)
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(SaleChannel, cls).__setup__()
|
|
|
|
@staticmethod
|
|
def default_company():
|
|
return Transaction().context.get('company')
|
|
|
|
@staticmethod
|
|
def default_payment_method():
|
|
return 'on_check_out'
|
|
|
|
@staticmethod
|
|
def default_currency():
|
|
Company = Pool().get('company.company')
|
|
company = Transaction().context.get('company')
|
|
if company:
|
|
return Company(company).currency.id
|
|
|
|
def compute(self, amount):
|
|
res = Decimal(round(float(amount) * self.commission / 100, 2))
|
|
return res
|
|
|
|
|
|
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)
|