def _add_range(cls, name, type_, string): low_name = '%s_low' % name high_name = '%s_high' % name setattr( cls, low_name, type_("%s Low" % string, domain=[ If(Eval(high_name), [ 'OR', (low_name, '=', None), (low_name, '<=', Eval(high_name)), ], []) ], states={ 'invisible': Eval('key_type') != name, }, depends=['key_type', high_name])) setattr( cls, high_name, type_("%s High" % string, domain=[ If(Eval(low_name), [ 'OR', (high_name, '=', None), (high_name, '<=', Eval(low_name)), ], []) ], states={ 'invisible': Eval('key_type') != name, }, depends=['key_type', low_name]))
class CreateInvoiceAsk(ModelView): 'Create Commission Invoice' __name__ = 'commission.create_invoice.ask' from_ = fields.Date('From', domain=[ If( Eval('to') & Eval('from_'), [('from_', '<=', Eval('to'))], []), ], depends=['to']) to = fields.Date('To', domain=[ If( Eval('from_') & Eval('to'), [('to', '>=', Eval('from_'))], []), ], depends=['from_']) type_ = fields.Selection([ ('in', 'Incoming'), ('out', 'Outgoing'), ('both', 'Both'), ], 'Type') @staticmethod def default_type_(): return 'both'
def __setup__(cls): super(Location, cls).__setup__() cls._order.insert(0, ('name', 'ASC')) cls._error_messages.update({ 'invalid_type_for_moves': ('Location "%s" with existing moves ' 'cannot be changed to a type that does not support moves.'), 'child_of_warehouse': ('Location "%(location)s" must be a ' 'child of warehouse "%(warehouse)s".'), 'inactive_location_with_moves': ("The location '%(location)s' must be empty " "to be deactivated."), }) parent_domain = [[ 'OR', ('parent.flat_childs', '=', False), ('parent', '=', None), ]] childs_domain = [ If(Eval('flat_childs', False), ('childs', '=', None), ()), ] childs_mapping = cls._childs_domain() for type_, allowed_parents in cls._parent_domain().items(): parent_domain.append( If(Eval('type') == type_, ('type', 'in', allowed_parents), ())) childs_domain.append( If( Eval('type') == type_, ('type', 'in', childs_mapping[type_]), ())) cls.parent.domain = parent_domain cls.childs.domain = childs_domain cls.childs.depends.extend(['flat_childs', 'type'])
class SamplesPendingPlanningContext(ModelView): 'Samples Pending Planning Context' __name__ = 'lims.sample_pending_planning.context' laboratory = fields.Many2One('lims.laboratory', 'Laboratory') department = fields.Many2One('company.department', 'Department') date_from = fields.Date("From Date", domain=[ If(Eval('date_to') & Eval('date_from'), ('date_from', '<=', Eval('date_to')), ()), ], depends=['date_to']) date_to = fields.Date("To Date", domain=[ If(Eval('date_from') & Eval('date_to'), ('date_to', '>=', Eval('date_from')), ()), ], depends=['date_from']) @classmethod def default_laboratory(cls): return Transaction().context.get('laboratory') @classmethod def default_date_from(cls): return Transaction().context.get('date_from') @classmethod def default_date_to(cls): return Transaction().context.get('date_to')
class PriceListLine: __metaclass__ = PoolMeta __name__ = 'product.price_list.line' start_date = fields.Date("Start Date", domain=[ If( Eval('start_date') & Eval('end_date'), ('start_date', '<=', Eval('end_date')), ()), ], depends=['end_date']) end_date = fields.Date("End Date", domain=[ If( Eval('start_date') & Eval('end_date'), ('end_date', '>=', Eval('start_date')), ()), ], depends=['start_date']) def match(self, pattern): pool = Pool() Date = pool.get('ir.date') pattern = pattern.copy() date = pattern.pop('date', None) or Date.today() if self.start_date and self.start_date > date: return False if self.end_date and self.end_date < date: return False return super(PriceListLine, self).match(pattern)
def view_attributes(cls): return super().view_attributes() + [ ('/tree/field[@name="profit"]', 'visual', If(Eval('profit', 0) < 0, 'danger', '')), ('/tree/field[@name="margin"]', 'visual', If(Eval('margin', 0) < 0, 'danger', '')), ]
def view_attributes(cls): return [ ('/tree/field[@name="receivable_today"]', 'visual', If(Eval('receivable_today', 0) > 0, 'danger', '')), ('/tree/field[@name="payable_today"]', 'visual', If(Eval('payable_today', 0) < 0, 'warning', '')), ]
def __setup__(cls): super(Complaint, cls).__setup__() cls._order.insert(0, ('date', 'DESC')) cls._error_messages.update({ 'delete_draft': ('Complaint "%s" must be in draft ' 'to be deleted.'), }) cls._transitions |= set(( ('draft', 'waiting'), ('waiting', 'draft'), ('waiting', 'approved'), ('waiting', 'rejected'), ('approved', 'done'), ('draft', 'cancelled'), ('waiting', 'cancelled'), ('done', 'draft'), ('cancelled', 'draft'), )) cls._buttons.update({ 'cancel': { 'invisible': ~Eval('state').in_(['draft', 'waiting']), 'depends': ['state'], }, 'draft': { 'invisible': ~Eval('state').in_( ['waiting', 'done', 'cancelled']), 'icon': If(Eval('state').in_(['done', 'cancelled']), 'tryton-undo', 'tryton-back'), 'depends': ['state'], }, 'wait': { 'invisible': ~Eval('state').in_(['draft']), 'depends': ['state'], }, 'approve': { 'invisible': ~Eval('state').in_(['waiting']), 'depends': ['state'], }, 'reject': { 'invisible': ~Eval('state').in_(['waiting']), 'depends': ['state'], }, 'process': { 'invisible': ~Eval('state').in_(['approved']), 'depends': ['state'], }, }) origin_domain = [] for model, domain in cls._origin_domains().items(): origin_domain = If(Eval('origin_model') == model, domain, origin_domain) cls.origin.domain = [origin_domain] actions_domains = cls._actions_domains() actions_domain = [('action', 'in', actions_domains.pop(None))] for model, actions in actions_domains.items(): actions_domain = If(Eval('origin_model') == model, [('action', 'in', actions)], actions_domain) cls.actions.domain = [actions_domain]
class Sale(metaclass=PoolMeta): __name__ = 'sale.sale' payments = fields.One2Many('account.payment', 'origin', "Payments", domain=[ ('company', '=', Eval('company', -1)), If( Eval('total_amount', 0) >= 0, ('kind', '=', 'receivable'), ('kind', '=', 'payable'), ), ('party', '=', If(Bool(Eval('invoice_party')), Eval('invoice_party'), Eval('party'))), ('currency', '=', Eval('currency')), ], states={ 'readonly': Eval('state') != 'quotation', }, depends=[ 'company', 'total_amount', 'party', 'invoice_party', 'currency', 'state' ]) @classmethod @ModelView.button @Workflow.transition('cancelled') @no_payment('sale_payment.msg_sale_cancel_payment') def cancel(cls, sales): super(Sale, cls).cancel(sales) @classmethod @ModelView.button @Workflow.transition('draft') @no_payment('sale_payment.msg_sale_draft_payment') def draft(cls, sales): super(Sale, cls).draft(sales) @classmethod def copy(cls, sales, default=None): if default is None: default = {} else: default = default.copy() default.setdefault('payments', None) return super(Sale, cls).copy(sales, default=default) @classmethod def payment_confirm(cls, sales): "Confirm the sale based on payment authorization" to_confirm = [] for sale in sales: payment_amount = sum(p.amount for p in sale.payments if p.is_authorized) if payment_amount >= sale.total_amount: to_confirm.append(sale) if to_confirm: to_confirm = cls.browse(to_confirm) # optimize cache cls.confirm(to_confirm)
def view_attributes(cls): return [ ('/tree/field[@name="name"]', 'visual', If(And(Eval('limit_state', 0) > 0, Eval('state', '') == 'open'), If(Eval('limit_state', 0) > 1, 'danger', 'warning'), '')), ]
def __setup__(cls): super().__setup__() if (hasattr(cls, 'parent') and hasattr(cls, 'childs') and hasattr(cls, 'company')): cls.parent.domain = [ ('company', '=', Eval('company', 0)), [ 'OR', If(Bool(Eval('start_date')), ('start_date', '>=', Eval('start_date', None)), ()), ('start_date', '=', None), ], [ 'OR', If(Bool(Eval('end_date')), ('end_date', '<=', Eval('end_date', None)), ()), ('end_date', '=', None), ], ] cls.parent.depends.update({'company', 'start_date', 'end_date'}) cls.childs.domain = [ ('company', '=', Eval('company', 0)), If(Bool(Eval('start_date')), ('start_date', '>=', Eval('start_date', None)), ()), If(Bool(Eval('end_date')), ('end_date', '<=', Eval('end_date', None)), ()), ] cls.childs.depends.update({'company', 'start_date', 'end_date'})
class PlanificationProfessionalContext(ModelView): 'Planification Professional Context' __name__ = 'lims.planification.professional.context' laboratory = fields.Many2One('lims.laboratory', 'Laboratory') from_date = fields.Date("From Date", domain=[ If(Eval('to_date') & Eval('from_date'), ('from_date', '<=', Eval('to_date')), ()), ], depends=['to_date']) to_date = fields.Date("To Date", domain=[ If(Eval('from_date') & Eval('to_date'), ('to_date', '>=', Eval('from_date')), ()), ], depends=['from_date']) @classmethod def default_laboratory(cls): return Transaction().context.get('laboratory') @classmethod def default_from_date(cls): return Transaction().context.get('from_date') @classmethod def default_to_date(cls): return Transaction().context.get('to_date')
class Employee(ModelSQL, ModelView): 'Employee' __name__ = 'company.employee' party = fields.Many2One('party.party', 'Party', required=True, help="The party which represents the employee.") company = fields.Many2One('company.company', 'Company', required=True, help="The company to which the employee belongs.") start_date = fields.Date('Start Date', domain=[If((Eval('start_date')) & (Eval('end_date')), ('start_date', '<=', Eval('end_date')), (), ) ], depends=['end_date'], help="When the employee joins the company.") end_date = fields.Date('End Date', domain=[If((Eval('start_date')) & (Eval('end_date')), ('end_date', '>=', Eval('start_date')), (), ) ], depends=['start_date'], help="When the employee leaves the company.") @staticmethod def default_company(): return Transaction().context.get('company') def get_rec_name(self, name): return self.party.rec_name @classmethod def search_rec_name(cls, name, clause): return [('party.rec_name',) + tuple(clause[1:])]
def __setup__(cls): super().__setup__() if (hasattr(cls, 'parent') and hasattr(cls, 'childs')): cls.parent.domain = [ [ 'OR', If(Bool(Eval('start_date')), ('start_date', '>=', Eval('start_date', None)), ()), ('start_date', '=', None), ], [ 'OR', If(Bool(Eval('end_date')), ('end_date', '<=', Eval('end_date', None)), ()), ('end_date', '=', None), ], ] cls.parent.depends.extend(['start_date', 'end_date']) cls.childs.domain = [ If(Bool(Eval('start_date')), ('start_date', '>=', Eval('start_date', None)), ()), If(Bool(Eval('end_date')), ('end_date', '<=', Eval('end_date', None)), ()), ] cls.childs.depends.extend(['start_date', 'end_date'])
class UserRole(ModelSQL, ModelView): "User Role" __name__ = 'res.user.role' user = fields.Many2One( 'res.user', "User", ondelete='CASCADE', select=True, required=True) role = fields.Many2One('res.role', "Role", required=True) from_date = fields.Date( "From Date", domain=[ If(Eval('from_date') & Eval('to_date'), ('from_date', '<=', Eval('to_date', None)), ()), ], depends=['to_date']) to_date = fields.Date( "To Date", domain=[ If(Eval('from_date') & Eval('to_date'), ('to_date', '>=', Eval('from_date', None)), ()), ], depends=['from_date']) @classmethod def __setup__(cls): super().__setup__() cls._order.insert(0, ('from_date', 'DESC NULLS FIRST')) cls._order.insert(1, ('to_date', 'ASC NULLS FIRST')) def valid(self, date): from_date = self.from_date or datetime.date.min to_date = self.to_date or datetime.date.max return from_date <= date <= to_date
def view_attributes(cls): return super().view_attributes() + [ ('/tree/field[@name="quantity"]', 'visual', If(Eval('quantity', 0) < 0, 'danger', '')), ('/tree/field[@name="forecast_quantity"]', 'visual', If(Eval('forecast_quantity', 0) < 0, 'warning', '')), ]
class Department(ModelSQL, ModelView): 'Company Department' __name__ = 'rrhh.department' company = fields.Many2One('company.company', 'Company', required=True, states={ 'readonly': True, }, domain=[ ('id', If(Eval('context', {}).contains('company'), '=', '!='), Eval('context', {}).get('company', -1)), ], select=True) name = fields.Char('Name', required=True, translate=True) parent = fields.Many2One('rrhh.department', 'Parent', domain=[ If(Bool(Eval('company')), ('company', '=', Eval('company')), ('company', '=', None)) ], depends=['company']) childs = fields.One2Many('rrhh.department', 'parent', 'Children', readonly=True) positions = fields.One2Many('rrhh.position', 'department', 'Positions', readonly=True) active = fields.Boolean('Active') @staticmethod def default_active(): return True @staticmethod def default_company(): return Transaction().context.get('company')
class ECOperationListContext(ECSalesListContext): "EC Operation List Context" __name__ = 'account.reporting.es_ec_operation_list.context' start_date = fields.Date("Start Date", domain=[ If(Eval('end_date'), ('start_date', '<=', Eval('end_date')), (), ), ]) end_date = fields.Date("End Date", domain=[ If(Eval('start_date'), ('end_date', '>=', Eval('start_date')), (), ), ]) @classmethod def default_start_date(cls): pool = Pool() Date = pool.get('ir.date') return Date.today() - relativedelta(months=1, day=1) @classmethod def default_end_date(cls): pool = Pool() Date = pool.get('ir.date') return Date.today() - relativedelta(months=1, day=31)
class BankAccount(metaclass=PoolMeta): __name__ = 'bank.account' journal = fields.Many2One('account.journal', 'Account Journal', states={ 'required': If( In(Eval('party_company'), Eval('owners', [])), True, False), }, depends=['owners', 'party_company']) credit_account = fields.Many2One( 'account.account', 'Credit Account', states={ 'required': If(In(Eval('party_company'), Eval('owners', [])), True, False), }, domain=[ ('kind', '!=', 'view'), ('company', '=', Eval('context', {}).get('company', -1)), ], depends=['owners', 'party_company']) debit_account = fields.Many2One( 'account.account', 'Debit Account', states={ 'required': If(In(Eval('party_company'), Eval('owners', [])), True, False), }, domain=[ ('kind', '!=', 'view'), ('company', '=', Eval('context', {}).get('company', -1)), ], depends=['owners', 'party_company']) party_company = fields.Function( fields.Many2One('party.party', 'party_company'), 'on_change_with_party_company') @staticmethod def default_party_company(): Company = Pool().get('company.company') if Transaction().context.get('company'): company = Company(Transaction().context['company']) return company.party.id def on_change_with_party_company(self, name=None): Company = Pool().get('company.company') if Transaction().context.get('company'): company = Company(Transaction().context['company']) return company.party.id def get_cbu_number(self): ''' Return cbu number ''' for account_number in self.numbers: if account_number.type == 'cbu': return account_number.number_compact
class Context(ModelView): "Sale Reporting Context" __name__ = 'sale.reporting.context' company = fields.Many2One('company.company', "Company", required=True) from_date = fields.Date("From Date", domain=[ If( Eval('to_date') & Eval('from_date'), ('from_date', '<=', Eval('to_date')), ()), ]) to_date = fields.Date("To Date", domain=[ If( Eval('from_date') & Eval('to_date'), ('to_date', '>=', Eval('from_date')), ()), ]) period = fields.Selection([ ('year', "Year"), ('month', "Month"), ('day', "Day"), ], "Period", required=True) warehouse = fields.Many2One('stock.location', "Warehouse", domain=[ ('type', '=', 'warehouse'), ]) @classmethod def default_company(cls): return Transaction().context.get('company') @classmethod def default_from_date(cls): pool = Pool() Date = pool.get('ir.date') context = Transaction().context if 'from_date' in context: return context['from_date'] return Date.today() - relativedelta(years=1) @classmethod def default_to_date(cls): pool = Pool() Date = pool.get('ir.date') context = Transaction().context if 'to_date' in context: return context['to_date'] return Date.today() @classmethod def default_period(cls): return Transaction().context.get('period', 'month') @classmethod def default_warehouse(cls): return Transaction().context.get('warehouse')
class Component(ComponentMixin, ModelSQL, ModelView): "Product Component" __name__ = "product.component" parent_template = fields.Many2One( 'product.template', "Parent Product", required=True, ondelete='CASCADE', select=True, domain=[ If(Bool(Eval('parent_product')), ('products', '=', Eval('parent_product')), ()), ]) parent_product = fields.Many2One( 'product.product', "Parent Variant", ondelete='CASCADE', select=True, domain=[ If(Bool(Eval('parent_template')), ('template', '=', Eval('parent_template')), ()), ]) @classmethod def __setup__(cls): super().__setup__() cls.__access__.update(['parent_template', 'parent_product']) @fields.depends( 'parent_product', '_parent_parent_product.template') def on_change_parent_product(self): if self.parent_product: self.parent_template = self.parent_product.template @fields.depends( 'parent_template', '_parent_parent_template.type', 'parent_product', '_parent_parent_product.type') def on_change_with_parent_type(self, name=None): if self.parent_product: return self.parent_product.type elif self.parent_template: return self.parent_template.type @property def parent_uom(self): if self.parent_product: return self.parent_product.default_uom elif self.parent_template: return self.parent_template.default_uom def get_rec_name(self, name): return super().get_rec_name(name) + ( ' @ %s' % ( self.parent_product.rec_name if self.parent_product else self.parent_template.rec_name)) @classmethod def search_rec_name(cls, name, clause): return super().search_rec_name(name, clause) + [ ('parent_product.rec_name',) + tuple(clause[1:]), ('parent_template.rec_name',) + tuple(clause[1:]), ]
class PrintConsolidatedFinancialIndicatorStart(ModelView): 'Consolidated Financial Indicator Start' __name__ = 'print.consolidated_financial_indicator.start' company = fields.Many2One( 'company.company', "Company", readonly=True, domain=[ ('id', If(Eval('context', {}).contains('company'), '=', '!='), Eval('context', {}).get('company', -1)), ]) companies = fields.One2Many('company.company', 'parent', 'Companies', domain=([('parent', 'child_of', Eval('company')), ('type', '=', 'normal')]), required=True, depends=['company']) fiscalyear = fields.Many2One( 'account.fiscalyear', 'Fiscal Year', help="The fiscalyear on which the new created budget will apply.", required=False, domain=[ ('company', '=', Eval('company')), ], depends=['company']) from_date = fields.Date("From Date", required=False, domain=[ If( Eval('to_date') & Eval('from_date'), ('from_date', '<=', Eval('to_date')), ()), ], depends=['to_date']) to_date = fields.Date("To Date", required=True, domain=[ If( Eval('from_date') & Eval('to_date'), ('to_date', '>=', Eval('from_date')), ()), ], depends=['from_date']) @classmethod def default_from_date(cls): return datetime.today().replace(day=1, month=1) @classmethod def default_to_date(cls): Date = Pool().get('ir.date') return Date.today() @classmethod def default_company(cls): return Transaction().context.get('company')
class Context(ModelView): "Stock Reporting Margin Context" __name__ = 'stock.reporting.margin.context' company = fields.Many2One('company.company', "Company", required=True) from_date = fields.Date("From Date", domain=[ If( Eval('to_date') & Eval('from_date'), ('from_date', '<=', Eval('to_date')), ()), ]) to_date = fields.Date("To Date", domain=[ If( Eval('from_date') & Eval('to_date'), ('to_date', '>=', Eval('from_date')), ()), ]) period = fields.Selection([ ('year', "Year"), ('month', "Month"), ('day', "Day"), ], "Period", required=True) include_lost = fields.Boolean("Include Lost", help="If checked, the cost of product moved " "to a lost and found location is included.") @classmethod def default_company(cls): return Transaction().context.get('company') @classmethod def default_from_date(cls): pool = Pool() Date = pool.get('ir.date') context = Transaction().context if 'from_date' in context: return context['from_date'] return Date.today() - relativedelta(years=1) @classmethod def default_to_date(cls): pool = Pool() Date = pool.get('ir.date') context = Transaction().context if 'to_date' in context: return context['to_date'] return Date.today() @classmethod def default_period(cls): return Transaction().context.get('period', 'month') @classmethod def default_include_lost(cls): return Transaction().context.get('include_lost', False)
def view_attributes(cls): storage_types = Eval('type').in_(['storage', 'warehouse', 'view']) return super().view_attributes() + [ ('/tree/field[@name="quantity"]', 'visual', If(storage_types & (Eval('quantity', 0) < 0), 'danger', ''), ['type']), ('/tree/field[@name="forecast_quantity"]', 'visual', If(storage_types & (Eval('forecast_quantity', 0) < 0), 'warning', ''), ['type']), ]
def __setup__(cls): super(PurchaseRequisition, cls).__setup__() cls._transitions |= set(( ('cancelled', 'draft'), ('rejected', 'draft'), ('draft', 'cancelled'), ('draft', 'waiting'), ('waiting', 'draft'), ('waiting', 'rejected'), ('waiting', 'approved'), ('approved', 'processing'), ('approved', 'draft'), ('processing', 'done'), ('done', 'processing'), )) cls._buttons.update({ 'cancel': { 'invisible': Eval('state') != 'draft', 'depends': ['state'], }, 'draft': { 'invisible': ~Eval('state').in_( ['cancelled', 'waiting', 'approved', 'rejected']), 'icon': If(Eval('state').in_(['cancelled', 'rejected']), 'tryton-undo', 'tryton-back'), 'depends': ['state'], }, 'wait': { 'pre_validate': [('supply_date', '!=', None)], 'invisible': ((Eval('state') != 'draft') | ~Eval('lines', [])), 'readonly': ~Eval('lines', []), 'depends': ['state'], }, 'approve': { 'invisible': Eval('state') != 'waiting', 'depends': ['state'], }, 'process': { 'invisible': ~Eval('state').in_( ['approved', 'processing']), 'icon': If(Eval('state') == 'approved', 'tryton-forward', 'tryton-refresh'), 'depends': ['state'], }, 'reject': { 'invisible': Eval('state') != 'waiting', 'depends': ['state'], }, }) # The states where amounts are cached cls._states_cached = ['approved', 'done', 'rejected', 'processing', 'cancelled']
class Cashier(ModelSQL, ModelView): 'Cashier' __name__ = 'cashier.cashier' company = fields.Many2One('company.company', 'Company', required=True, states={ 'readonly': True, }, domain=[ ('id', If(Eval('context', {}).contains('company'), '=', '!='), Eval('context', {}).get('company', -1)), ], select=True) name = fields.Char('Name', required=True, translate=True) ccterminals = fields.One2Many('cashier.ccterminal', 'cashier', 'Credit Card Terminals', domain=[ ('company', '=', Eval('company')), ['OR', ('cashier', '=', None), ('cashier', '=', Eval('id')) ] ], depends=['company', 'id']) cash_bank_cash = fields.Many2One('cash_bank.cash_bank', 'Cash', required=True, domain=[ ('company', '=', Eval('company')), ('type', '=', 'cash') ], depends=['company']) receipt_type_cash = fields.Many2One('cash_bank.receipt_type', 'Receipt Type for Cash', required=True, domain=[ If( Bool(Eval('cash_bank_cash')), [('cash_bank', '=', Eval('cash_bank_cash'))], [('cash_bank', '=', -1)] ), ('type', '=', 'in') ], depends=['cash_bank_cash']) #TODO sale action #TODO diff action active = fields.Boolean('Active') @staticmethod def default_company(): return Transaction().context.get('company') @staticmethod def default_active(): return True @fields.depends('receipt_type_cash') def on_change_cash_bank_cash(self): self.receipt_type_cash = None
class ContextAnalyticAccount(ModelView): 'Context Analytic Account' __name__ = 'analytic_account.account.context' from_date = fields.Date("From Date", domain=[ If( Eval('to_date') & Eval('from_date'), ('from_date', '<=', Eval('to_date')), ()), ], depends=['to_date']) to_date = fields.Date("To Date", domain=[ If( Eval('from_date') & Eval('to_date'), ('to_date', '>=', Eval('from_date')), ()), ], depends=['from_date']) company = fields.Many2One( 'company.company', "Company", readonly=True, domain=[ ('id', If(Eval('context', {}).contains('company'), '=', '!='), Eval('context', {}).get('company', -1)), ]) fiscalyear = fields.Many2One( 'account.fiscalyear', 'Fiscal Year', domain=[ ('company', '=', Eval('context', {}).get('company', -1)), ], ) @classmethod def default_company(cls): return Transaction().context.get('company') @classmethod def default_from_date(cls): return datetime.today().replace(day=1, month=1) @classmethod def default_to_date(cls): Date = Pool().get('ir.date') return Date.today() @fields.depends('from_date', 'to_date', 'fiscalyear') def on_change_fiscalyear(self): if self.fiscalyear: self.from_date = self.fiscalyear.start_date self.to_date = self.fiscalyear.end_date
class PrintProductionMassBalanceStart(ModelView): 'Print Production Mass Balance Start' __name__ = 'production.mass_balance.start' product = fields.Many2One('product.product', 'Product', required=True) from_date = fields.Date( 'From Date', domain=[ If( Bool(Eval('from_date')) & Bool(Eval('to_date')), ('from_date', '<=', Eval('to_date')), ()) ], states={ 'required': Bool(Eval('to_date', False)), }, depends=['to_date']) to_date = fields.Date( 'To Date', domain=[ If( Bool(Eval('from_date')) & Bool(Eval('to_date')), ('from_date', '<=', Eval('to_date')), ()) ], states={ 'required': Bool(Eval('from_date', False)), }, depends=['from_date']) direction = fields.Selection([ ('backward', 'Backward'), ('forward', 'Forward'), ], 'Direction', required=True) @classmethod def __setup__(cls): super(PrintProductionMassBalanceStart, cls).__setup__() try: Lot = Pool().get('stock.lot') except: Lot = None if Lot: cls.lot = fields.Many2One('stock.lot', 'Lot', domain=[ ('product', '=', Eval('product')), ], depends=['product']) @staticmethod def default_direction(): return 'backward'
def __setup__(cls): super(SaleOpportunity, cls).__setup__() cls._order.insert(0, ('start_date', 'DESC')) cls._transitions |= set(( ('lead', 'opportunity'), ('lead', 'lost'), ('lead', 'cancelled'), ('lead', 'converted'), ('opportunity', 'converted'), ('opportunity', 'lead'), ('opportunity', 'lost'), ('opportunity', 'cancelled'), ('converted', 'won'), ('converted', 'lost'), ('won', 'converted'), ('lost', 'converted'), ('lost', 'lead'), ('cancelled', 'lead'), )) cls._buttons.update({ 'lead': { 'invisible': ~Eval('state').in_(['cancelled', 'lost', 'opportunity']), 'icon': If( Eval('state').in_(['cancelled', 'lost']), 'tryton-undo', 'tryton-back'), 'depends': ['state'], }, 'opportunity': { 'pre_validate': [ If(~Eval('party'), ('party', '!=', None), ()), If(~Eval('employee'), ('employee', '!=', None), ()), ], 'invisible': ~Eval('state').in_(['lead']), 'depends': ['state'], }, 'convert': { 'invisible': ~Eval('state').in_(['opportunity']), 'depends': ['state'], }, 'lost': { 'invisible': ~Eval('state').in_(['lead', 'opportunity']), 'depends': ['state'], }, 'cancel': { 'invisible': ~Eval('state').in_(['lead', 'opportunity']), 'depends': ['state'], }, })
def view_attributes(cls): return super(PaymentTransaction, cls).view_attributes() + [( '/tree', 'colors', If( In( Eval('state', ''), ['in-progress', 'authorized', 'completed'] ), 'blue', If( In(Eval('state', ''), ['failed', 'cancel']), 'red', If(Equal(Eval('state', ''), 'posted'), 'green', 'black') ) ) )]