def __setup__(cls): super(Sale, cls).__setup__() for fname in ('invoice_method', 'invoice_address', 'shipment_method', 'shipment_address'): fstates = getattr(cls, fname).states if fstates.get('readonly'): fstates['readonly'] = Or(fstates['readonly'], Eval('self_pick_up', False)) else: fstates['readonly'] = Eval('self_pick_up', False) getattr(cls, fname).depends.append('self_pick_up') if hasattr(cls, 'carrier'): if 'invisible' not in cls.carrier.states: cls.carrier.states['invisible'] = Bool(Eval('self_pick_up')) else: invisible = cls.carrier.states['invisible'] cls.carrier.states['invisible'] = Or( invisible, Bool(Eval('self_pick_up'))) cls._buttons.update({ 'add_sum': { 'invisible': Eval('state') != 'draft' }, 'wizard_add_product': { 'invisible': Eval('state') != 'draft' }, 'print_ticket': {} }) for fname in ('self_pick_up', 'currency', 'party'): if fname not in cls.lines.on_change: cls.lines.on_change.add(fname)
def __setup__(cls): super(ReceiptLine, cls).__setup__() cls.type.selection += [ ('advance_in_apply', 'Apply Collected in Advanced from Customer'), ('advance_in_create', 'Create Collected in Advance from Customer'), ('advance_out_apply', 'Apply Paid in Advanced to Supplier'), ('advance_out_create', 'Create Paid in Advance to Supplier'), ] cls.party.states['readonly'] = Or( Eval('receipt_state') != 'draft', Bool(Eval('invoice')), Bool(Eval('advance')), ) cls.party.depends += ['advance'] cls.account.states['readonly'] = Or( Eval('receipt_state') != 'draft', Not( In(Eval('type'), ['move_line', 'advance_in_create', 'advance_out_create'])), ) cls.account.domain.append( If(In(Eval('type'), ['advance_in_create', 'advance_out_create']), [('reconcile', '=', True), ('party_required', '=', True)], []))
class Template(ModelSQL, ModelView): _name = "product.template" account_category = fields.Boolean( 'Use Category\'s accounts', help='Use the accounts defined on the category') account_income = fields.Many2One('ekd.account', 'Account Income', states={ 'invisible': Or(Not(Bool(Eval('company'))), Bool(Eval('account_category'))), }, help='This account will be used instead of the one defined ' \ 'on the category.', depends=['account_category']) account_expense = fields.Many2One('ekd.account', 'Account Expense', states={ 'invisible': Or(Not(Bool(Eval('company'))), Bool(Eval('account_category'))), }, help='This account will be used instead of the one defined ' \ 'on the category.', depends=['account_category']) account_taxes_category = fields.Boolean( 'Use Category\'s accounts', help='Use the accounts defined on the category') account_tax_input = fields.Many2One('ekd.account', 'Account Tax Input', states={ 'invisible': Or(Not(Bool(Eval('company'))), Bool(Eval('taxes_category'))), }, help='This account will be used instead of the one defined ' \ 'on the category.', depends=['taxes_category']) account_tax_output = fields.Many2One('ekd.account', 'Account Tax Output', states={ 'invisible': Or(Not(Bool(Eval('company'))), Bool(Eval('taxes_category'))), }, help='This account will be used instead of the one defined ' \ 'on the category.', depends=['taxes_category']) taxes_category = fields.Boolean('Use Category\'s Taxes', help='Use the taxes '\ 'defined on the category') taxes = fields.Many2Many('product.template-ekd.account.tax', 'product', 'tax', 'Taxes', domain=[('parent', '=', False)], states={ 'invisible': Or(Not(Bool(Eval('company'))), Bool(Eval('taxes_category'))), }, depends=['taxes_category'])
def __setup__(cls): super(ShipmentOut, cls).__setup__() cls._buttons.update({ 'label_wizard': { 'invisible': Or((~Eval('state').in_(['packed', 'done'])), (Eval('tracking_number') != '')), 'icon': 'tryton-executable', }, }) cls._error_messages.update({ 'no_shipments': 'There must be atleast one shipment.', 'too_many_shipments': 'The wizard can be called on only one shipment', 'tracking_number_already_present': 'Tracking Number is already present for this shipment.', 'invalid_state': 'Labels can only be generated when the ' 'shipment is in Packed or Done states only', 'wrong_carrier': 'Carrier for selected shipment is not of %s', 'no_packages': 'Shipment %s has no packages', 'warehouse_address_missing': 'Warehouse address is missing', })
def __setup__(cls): super(AddSalePaymentView, cls).__setup__() INV = Or( Eval('method') == 'manual', And( Eval('method') == 'credit_card', Bool(Eval('use_existing_card')))) STATE1 = { 'required': And(~Bool(Eval('use_existing_card')), Eval('method') == 'credit_card'), 'invisible': INV } DEPENDS = ['use_existing_card', 'method'] cls.owner.states.update(STATE1) cls.owner.depends.extend(DEPENDS) cls.number.states.update(STATE1) cls.number.depends.extend(DEPENDS) cls.expiry_month.states.update(STATE1) cls.expiry_month.depends.extend(DEPENDS) cls.expiry_year.states.update(STATE1) cls.expiry_year.depends.extend(DEPENDS) cls.csc.states.update(STATE1) cls.csc.depends.extend(DEPENDS) cls.swipe_data.states = {'invisible': INV} cls.swipe_data.depends = ['method']
def __setup__(cls): super(InpatientRegistration, cls).__setup__() # Make readonly for bed depends on a person being hospitalised or # discharged from the hospital cls.bed.states = {'required': True, 'readonly': Or(Equal(Eval('state'), 'hospitalized'), Equal(Eval('state'), 'confirmed'), Equal(Eval('state'), 'done'))} # Changed depends to accommodate state cls.bed.depends = ['name', 'state'] # make discharge_date not required cls.discharge_date.required = False if not cls.discharge_date.states: cls.discharge_date.states = {} cls.discharge_date.states['invisible'] = Not( In(Eval('state'), ['done', 'hospitalized'])) # rename the set of states cls.state.selection = [ ('free', 'Pending'), ('cancelled', 'Cancelled'), ('confirmed', 'Confirmed'), ('hospitalized', 'Admitted'), ('done', 'Discharged/Done') ] # discharge_date is the real thing cls.discharge_date.string = 'Discharged'
class Sale(metaclass=PoolMeta): __name__ = 'sale.sale' price_list = fields.Many2One( 'product.price_list', 'Price List', help="Use to compute the unit price of lines.", domain=[('company', '=', Eval('company'))], states={ 'readonly': Or(Not(Equal(Eval('state'), 'draft')), Bool(Eval('lines', [0]))), }, depends=['state', 'company']) @classmethod def __setup__(cls): super(Sale, cls).__setup__() cls.party.states['readonly'] = (cls.party.states['readonly'] | Eval('lines', [0])) cls.lines.states['readonly'] = (cls.lines.states['readonly'] | ~Eval('party')) if 'party' not in cls.lines.depends: cls.lines.depends.append('party') def on_change_party(self): pool = Pool() Configuration = pool.get('sale.configuration') super(Sale, self).on_change_party() if self.party and self.party.sale_price_list: self.price_list = self.party.sale_price_list else: config = Configuration(1) self.price_list = config.sale_price_list
def __setup__(cls): super(Category, cls).__setup__() cls.parent.domain = [('customs', '=', Eval('customs', False)), cls.parent.domain or []] cls.parent.states['required'] = Or( cls.parent.states.get('required', False), Eval('tariff_codes_parent', False))
class Sale: __name__ = 'sale.sale' price_list = fields.Many2One('product.price_list', 'Price List', domain=[('company', '=', Eval('company'))], states={ 'readonly': Or(Not(Equal(Eval('state'), 'draft')), Bool(Eval('lines', [0]))), }, depends=['state', 'company']) @classmethod def __setup__(cls): super(Sale, cls).__setup__() cls.party.states['readonly'] = (cls.party.states['readonly'] | Eval('lines', [0])) cls.lines.states['readonly'] = (cls.lines.states['readonly'] | ~Eval('party')) if 'party' not in cls.lines.depends: cls.lines.depends.append('party') def on_change_party(self): super(Sale, self).on_change_party() self.price_list = None if self.party and self.party.sale_price_list: self.price_list = self.party.sale_price_list
def __setup__(cls): super(InpatientMealOrder, cls).__setup__() cls._buttons.update( {'cancel': { 'invisible': Not(Equal(Eval('state'), 'ordered')) }}) cls._buttons.update({ 'generate': { 'invisible': Or(Equal(Eval('state'), 'ordered'), Equal(Eval('state'), 'done')) }, }) cls._buttons.update( {'done': { 'invisible': Not(Equal(Eval('state'), 'ordered')) }}) cls._error_messages.update({ 'meal_order_warning': '===== MEAL WARNING ! =====\n\n\n' 'This patient has special meal needs \n\n' 'Check and acknowledge that\n' 'the meal items in this order are correct \n\n', 'health_professional_warning': 'No health professional associated to this user', }) t = cls.__table__() cls._sql_constraints = [ ('meal_order_uniq', Unique(t, t.meal_order), 'The Meal Order code already exists'), ]
class Party(metaclass=PoolMeta): __name__ = 'party.party' pyafipws_fce = fields.Boolean('MiPyme FCE', states={ 'readonly': ~Eval('active', True), }, depends=['active']) pyafipws_fce_amount = fields.Numeric( 'MiPyme FCE Amount', digits=(16, Eval('pyafipws_fce_amount_digits', 2)), states={ 'readonly': Or(~Eval('pyafipws_fce', False), ~Eval('active', True)), }, depends=['active', 'pyafipws_fce_amount_digits']) pyafipws_fce_amount_digits = fields.Function( fields.Integer('Currency Digits'), 'get_pyafipws_fce_amount_digits') @staticmethod def default_pyafipws_fce_amount(): return Decimal('0') def get_pyafipws_fce_amount_digits(self, name): pool = Pool() Company = pool.get('company.company') company_id = Transaction().context.get('company') if company_id: company = Company(company_id) return company.currency.digits
class BoxType(ModelSQL, ModelView): "Carrier Box Type" __name__ = 'carrier.box_type' #: Name of the box. name = fields.Char('Name', required=True) #: Same as `carrier.carrier_cost_method`. carrier_cost_method = fields.Selection([(None, '')], 'Carrier Cost Method') #: Code of the box. code = fields.Char('Code') #: Length of the box. length = fields.Float('Length') #: Width of the box. width = fields.Float('Width') #: Height of the box. height = fields.Float('Height') #: Measuring unit of length, height and width. distance_unit = fields.Many2One('product.uom', 'Distance Unit', states={ 'required': Or(Bool(Eval('length')), Bool(Eval('width')), Bool(Eval('height'))) }, domain=[('category', '=', Id('product', 'uom_cat_length'))], depends=['length', 'width', 'height'])
def __setup__(cls): super(Category, cls).__setup__() cls.parent.states['required'] = Or( cls.parent.states.get('required', False), Eval('iva_parent', False)) cls.parent.depends.extend(['iva_parent'])
def __setup__(cls): super().__setup__() cls._error_messages.update({ 'officer_missing': ( 'Please fill Reporting Officer and Reviewing Officer.'), 'missing_sign': ( 'Please sign the document before forwarding.'), 'blank_grades': ( 'It seems that you have not filled any grade for some questions. ' \ 'Please fill in all the grades before forwarding.') }) cls._buttons.update({ "forward_to_employee": { 'invisible': ~Eval('state').in_(['draft']), 'depends': ['state'] }, "submit_to_reporting": { 'invisible': ~Eval('state').in_(['self_appraisal']), 'depends': ['state'] }, "submit_to_reviewing": { 'invisible': ~Eval('state').in_(['reporting_officer']), 'depends': ['state'] }, "submit_to_accepting": { 'invisible': ~Eval('state').in_(['reviewing_officer']) | ~Eval('acceptance_authority'), 'depends': ['state'] }, "disclose": { 'invisible': If( Bool(Eval('acceptance_authority')), ~Eval('state').in_(['accepting_authority']), ~Eval('state').in_(['reviewing_officer']), ), 'depends': ['state'] }, "sign_and_submit": { 'invisible': ~Eval('state').in_(['disclose']), 'depends': ['state'] }, "raise_representation": { 'invisible': Or(~Eval('state').in_(['disclose', 'signed']), Bool(~Eval('allow_representation'))), 'depends': ['state', 'allow_representation'] } }) cls._transitions |= set( (('draft', 'self_appraisal'), ('draft', 'no_initiation'), ('self_appraisal', 'reporting_officer'), ('reporting_officer', 'reviewing_officer'), ('reviewing_officer', 'accepting_authority'), ('reviewing_officer', 'disclose'), ('accepting_authority', 'disclose'), ('disclose', 'signed'), ('disclose', 'representation'), ('signed', 'representation')))
def __setup__(cls): super(Category, cls).__setup__() cls.parent.domain = [ ('accounting', '=', Eval('accounting', False)), cls.parent.domain or []] cls.parent.states['required'] = Or( cls.parent.states.get('required', False), Eval('account_parent', False) | Eval('taxes_parent', False))
class ReceiptType(ModelSQL, ModelView): "Cash/Bank Receipt Type" __name__ = "cash_bank.receipt_type" cash_bank = fields.Many2One('cash_bank.cash_bank', 'Cash/Bank', required=True, domain=[('company', 'in', [ Eval('context', {}).get('company', -1), None ])]) cash_bank_type = fields.Function(fields.Char('Cash/Bank type'), 'on_change_with_cash_bank_type') name = fields.Char('Name', required=True, translate=True) type = fields.Selection([('in', 'IN'), ('out', 'OUT')], 'Type', required=True) sequence = fields.Many2One( 'ir.sequence', "Receipt Sequence", required=True, domain=[ ('company', 'in', [Eval('context', {}).get('company', -1), None]), ('code', '=', 'cash_bank.receipt'), ]) default_receipt_line_type = fields.Selection('get_receipt_line_type', 'Default Receipt Line Type') party_required = fields.Boolean('Party Required') bank_account = fields.Boolean( 'Bank Account', states={ 'invisible': Or(Bool(Eval('cash_bank_type') != 'bank'), Not(Bool(Eval('party_required')))) }, depends=['party_required', 'cash_bank_type']) bank_account_required = fields.Boolean('Bank Account Required', states={ 'invisible': Not(Bool(Eval('bank_account'))), }, depends=['bank_account']) active = fields.Boolean('Active') @staticmethod def default_active(): return True @classmethod def get_receipt_line_type(cls): pool = Pool() Line = pool.get('cash_bank.receipt.line') return Line.fields_get(['type'])['type']['selection'] @fields.depends('cash_bank', '_parent_cash_bank.type') def on_change_with_cash_bank_type(self, name=None): if self.cash_bank: return self.cash_bank.type
def __setup__(cls): super().__setup__() cls.address.states['invisible'] = And( cls.address.states.get('invisible', True), ~Eval('is_visit_location', False)) cls.address.states['required'] = Or( cls.address.states.get('required', False), Eval('is_visit_location', False)) cls.address.depends.append('is_visit_location')
class SurgeryMainProcedure(ModelSQL, ModelView): __name__ = 'gnuhealth.surgery' main_procedure = fields.Many2One( 'gnuhealth.operation', 'Main Proc', domain=[('name', '=', Eval('active_id'))], states={'readonly': Or(~Eval('procedures'), Eval('id', 0) < 0)}, depends=['procedures'])
def __setup__(cls): super(Template, cls).__setup__() cls.cost_price.states['required'] = Or( cls.cost_price.states.get('required', True), Eval('type').in_(['goods', 'assets'])) cls.cost_price.depends.append('type') cls._modify_no_move = [ ('default_uom', 'stock.msg_product_change_default_uom'), ('type', 'stock.msg_product_change_type'), ]
def view_attributes(cls): return super().view_attributes() + [ ('//page[@name="trend_charts"]', 'states', { 'invisible': Or( Eval('type') != 'base', Eval('report_name') != 'lims.result_report', ) }), ]
def __setup__(cls): super(Category, cls).__setup__() cls._error_messages.update({ 'missing_account': ('There is no account ' 'expense/revenue defined on the category ' '%s (%d)'), }) cls.parent.states['required'] = Or( cls.parent.states.get('required', False), Eval('account_parent', False) | Eval('taxes_parent', False)) cls.parent.depends.extend(['account_parent', 'taxes_parent'])
def __setup__(cls): super(Template, cls).__setup__() cls._error_messages.update({ 'missing_account': ('There is no account ' 'expense/revenue defined on the product %s (%d)'), }) cls.category.states['required'] = Or( cls.category.states.get('required', False), Eval('account_category', False) | Eval('taxes_category', False)) cls.category.depends.extend(['account_category', 'taxes_category'])
def __setup__(cls): super(QueueEntry, cls).__setup__() cls.write_date.string = 'Last Modified' cls._order = [('priority', 'ASC'), ('last_call', 'ASC'), ('create_date', 'ASC')] cls._buttons.update( btn_inspect={}, btn_call={'readonly': Or(Eval('busy', False), Equal('99', Eval('entry_state', '0')))}, btn_dismiss={'readonly': Not(Eval('busy', False)), 'invisible': Not(Eval('called_by_me', False))}, btn_setup_appointment={ 'invisible': Or(Bool(Eval('appointment')), ~Equal('20', Eval('entry_state', '0'))) }) cls._sql_constraints += [ ('triage_uniq', 'UNIQUE(triage_entry)', 'Triage entry already in the queue'), ('appointment_uniq', 'UNIQUE(appointment)', 'Appointment already in the queue')]
def __setup__(cls): super(PatientEncounter, cls).__setup__() cls._error_messages.update({ 'health_professional_warning': 'No health professional ' 'associated with this user', 'end_date_before_start': 'End time cannot be before' 'Start time\n"%(start_time)s"', 'end_date_required': 'End time is required for finishing', 'unsigned_components': 'There are unsigned components.' # 'This encounter cannot be signed' }) cls._buttons.update({ 'set_done': { 'invisible': Not(Equal(Eval('state'), 'in_progress')), 'readonly': Or(Greater(0, Eval('id', -1)), Greater(1, Len(Eval('components')))) }, 'sign_finish': { 'invisible': Not(Equal(Eval('state'), 'done')) }, 'add_component': { 'readonly': Or(Greater(0, Eval('id', -1)), In(Eval('state'), ['done', 'signed', 'invalid'])), 'invisible': Equal(Eval('state'), 'signed') }, 'add_extra_component': { 'invisible': In(Eval('state'), ['signed', 'in_progress', 'invalid']) } })
def view_attributes(cls): return super(Template, cls).view_attributes() + [ ('//page[@id="esale"]', 'states', { 'invisible': Or( Not(Bool(Eval('salable', False))), ~Eval('context', {}).get('groups', []).contains( Id('esale', 'group_esale'))), }), ('//page[@id="esale"]/notebook/page[@id="general"]', 'states', { 'invisible': Not(Bool(Eval('esale_available'))), }), ]
def __setup__(cls): super().__setup__() cls.origin.states['readonly'] = True cls.party.domain = [ 'OR', ('id', '=', Eval('party')), If(Bool(Eval('party_domain')), ('id', 'in', Eval('party_domain')), ('id', '!=', -1)) ] if 'party_domain' not in cls.party.depends: cls.party.depends.append('party_domain') cls.product.states['readonly'] = Or( Eval('invoice_state') != 'draft', Bool(Eval('lims_service_sample'))) cls.product.depends.append('lims_service_sample')
def __setup__(cls): super(Category, cls).__setup__() cls._error_messages.update({ 'missing_account': ('There is no ' '"%(field)s" defined on the category "%(name)s"'), }) cls.parent.domain = [ ('accounting', '=', Eval('accounting', False)), cls.parent.domain or []] cls.parent.depends.append('accounting') cls.parent.states['required'] = Or( cls.parent.states.get('required', False), Eval('account_parent', False) | Eval('taxes_parent', False)) cls.parent.depends.extend(['account_parent', 'taxes_parent'])
def __setup__(cls): super(TriageEntry, cls).__setup__() cls._buttons.update({ 'set_done': { 'readonly': ~Eval('can_do_details', False), 'invisible': Or(In(Eval('status'), ['pending', 'triage']), Eval('done', False)) }, 'go_referral': { 'readonly': ~Eval('can_do_details', False), 'invisible': ~In(Eval('status'), ['refer', 'referin']) } })
def __setup__(cls): cls._buttons.update({ 'generate_prescription': { 'invisible': Equal(Eval('state'), 'validated'), }, 'create_prescription': { 'invisible': Or(Equal(Eval('state'), 'done'), Equal(Eval('state'), 'validated')) }, }) ''' Allow calling the set_signature method via RPC ''' cls.__rpc__.update({ 'set_signature': RPC(readonly=False), })
def __setup__(cls): super(Template, cls).__setup__() cls._error_messages.update({ 'change_default_uom': ('You cannot change the default uom for ' 'a product which is associated to stock moves.'), 'change_type': ('You cannot change the type for a product ' 'which is associated to stock moves.'), }) cls.cost_price.states['required'] = Or( cls.cost_price.states.get('required', True), Eval('type').in_(['goods', 'assets'])) cls.cost_price.depends.append('type') cls._modify_no_move = [ ('default_uom', 'change_default_uom'), ('type', 'change_type'), ]