trytonpsk-hotel/channel.py

79 lines
2.9 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 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)
party = fields.Many2One('party.party', 'Party', required=True)
type_commission = fields.Selection([
('percentage', 'Percentage'),
('fixed', 'Fixed'),
], 'Type Commission', required=True)
company = fields.Many2One('company.company', 'Company', required=True,
domain=[
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', 0)),
], select=True)
commission = fields.Numeric('Commission', required=True, digits=(16, 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
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)