trytonpsk-hotel/channel.py

83 lines
3.1 KiB
Python
Raw Normal View History

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
class SaleChannel(ModelSQL, ModelView):
'Sale Channel'
__name__ = 'hotel.channel'
name = fields.Char('Name', required=True)
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)
# 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')),
('kind', 'not in', ['view']),
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')),
('kind', 'not in', ['view']),
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',
required=True)
2021-01-23 16:56:32 +01:00
price_list = fields.Many2One('product.price_list', 'Price List')
2022-03-20 14:46:25 +01: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'),
], 'Collection Mode', required=False, help="Commission collection mode")
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):
2022-03-20 01:11:41 +01:00
print(self)
2022-03-19 06:21:49 +01:00
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)