2019-09-13 Today is the Mid-Autumn Festival, Friday
#自定义显示名称 def name_get(self): result = [] for order in self: rec_name = "%s(%s)"%(record.name,record.date_done) result.append((record.id, rec_name)) return result # 新添加函数name_search @api.model def name_search(self, name='', args=None, operator='ilike', limit=100): if not args: args = [] products = [] if name: positive_operators = ['=', 'ilike', '=ilike', 'like', '=like'] products = self.env['product.product'] if operator in positive_operators: products = self.search([('name', 'ilike', name)] + args, limit=limit) if not products: products = self.search([('size', 'ilike', name)] + args, limit=limit) if not products: products = self.search([('material', 'ilike', name)] + args, limit=limit) else: products = self.search(args, limit=limit) return products.name_get() #添加约束 from odoo.exceptions import ValidationError @api.constrains('age') def _check_something(self): for record in self: if record.age > 20: raise ValidationError("Your record is too old: %s" % record.age) # all records passed the test, don't return anything #更新时间 @api.multi def change_updatetime(self): for order in self: order.update_time=fields.Datetime.now () in an SQL statement or record set in ORM can not use the tuple List Search ([( ' the above mentioned id ' , ' in ' , tuple (IDS)]) calls mapped to obtain the names of employees return employee_ids.mapped ( ' name ' ) # Get user group: self.user_has_groups ( 'base.group_no_one') Kanban default packet type when no such default values can also occur when there kanban # for odoo12 is group_expand = '' for type selection state = fields .Selection ([( ' A ' , " A " ), ( ' B ' , " B " ),('c', "C"), ('d', "D")], group_expand='_expand_states') def _expand_states(self, states, domain, order): # return all possible states, in order return [key for key, val in type(self).state.selection] #对于odoo12来说 group_expand='' 对于many2one类型 stage_id = fields.Many2one('crm.stage', string='Stage', ondelete='restrict', track_visibility='onchange', index=True, domain="['|', ('team_id', '=', False), ('team_id', '=', team_id)]", group_expand='_read_group_stage_ids', default=lambda self: self._default_stage_id()) @api.model def _read_group_stage_ids(self, stages, domain, order): """ Read group customization in order to display all the stages in the kanban view, even if they are empty """ stage_ids Stages._search = ([], the Order = the Order, access_rights_uid = SUPERUSER_ID) return stages.browse (stage_ids) # create records superuser rent_as_superuser = self.env [ ' library.book ' ] .sudo () rent_as_superuser.create ( Vals) # Get the current user for employees employee = self.env.user.employee_ids [0] # objects employee.id employee.name
<field name="discount" groups="base.group_no_one" string="Disc (%)"/> <field name="invoice_line_tax_ids" widget="many2many_tags" options="{'no_create': True}" context="{'type':parent.type, 'tree_view_ref': 'account.account_tax_view_tree', 'search_view_ref': 'account.account_tax_view_search'}" domain="[('type_tax_use','=','sale'),('company_id', '=', parent.company_id)]"/> <field name="price_subtotal" string="Subtotal" groups="account.group_show_line_subtotals_tax_excluded"/>
动作
<record id="sale_order_line_action" model="ir.actions.act_window">
<field name="name">search_sale_order_line</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order.line</field>
<field name="view_mode">tree,form</field>
<field name="context">{'tree_view_ref':'sale_order_line_tree',
'form_view_ref':'sale_order_line_form'}
</field>
</record>
继承
<xpath expr="//header" position="inside">
<button name="btn_7" string="" type="object" class="oe_highlight oe_read_only" />
</xpath>
<xpath expr="//header/field[@name='order_id']" position="attributes">
<attribute name="readonly">1</attribute>
</xpath>
查看附件
<div class="o_attachment_preview" attrs="{'invisible': ['|',('type', '!=', 'in_invoice'),('state', '!=', 'draft')]}" />
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="activity_ids" widget="mail_activity"/>
<field name="message_ids" widget="mail_thread"/>
</div>