# 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 from .constants import PAYMENT_METHOD_CHANNEL 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(PAYMENT_METHOD_CHANNEL, 'Payment Method') collection_mode = fields.Selection([ ('', ''), ('anticipated', 'Anticipated'), ('after_sale', 'After-Sale'), ], 'Collection Mode', required=False, help="Commission collection mode") @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 def compute(self, amount): print(self) 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)