当前位置: 首页>>代码示例>>Python>>正文


Python fields.one2many方法代码示例

本文整理汇总了Python中openerp.osv.fields.one2many方法的典型用法代码示例。如果您正苦于以下问题:Python fields.one2many方法的具体用法?Python fields.one2many怎么用?Python fields.one2many使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openerp.osv.fields的用法示例。


在下文中一共展示了fields.one2many方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_relationship_classes

# 需要导入模块: from openerp.osv import fields [as 别名]
# 或者: from openerp.osv.fields import one2many [as 别名]
def _get_relationship_classes(self, cr, uid, model, context=None):
        """Computes the *relationship classes* reachable from the given
           model. The 4 relationship classes are:
           - [obj0]: the given model itself (and its parents via _inherits, if any)
           - [obj1]: obj0 and all other models recursively accessible from
                     obj0 via one2many relationships
           - [obj2]: obj0 and all other models recursively accessible from
                     obj0 via one2many and many2many relationships
           - [obj3]: all models recursively accessible from obj1 via many2one
                     relationships

           Each class is returned as a list of pairs [(field,model_browse)], where
           ``model`` is the browse_record of a reachable ir.model, and ``field`` is
           the dot-notation reverse relationship path coming from that model to obj0,
           or None if there is no reverse path.
           
           :return: ([obj0], [obj1], [obj2], [obj3])
           """
        # obj0 class and its parents
        obj0 = [(None, model)]
        model_obj = self.pool[model.model]
        ir_model_obj = self.pool.get('ir.model')
        for parent in model_obj._inherits:
            parent_model_browse = ir_model_obj.browse(cr, UID_ROOT,
                    ir_model_obj.search(cr, UID_ROOT, [('model','=',parent)]))[0]
            obj0 += [(None, parent_model_browse)]

        obj1 = self._get_recursive_relations(cr, uid, model, ['one2many'], relation_fields=obj0, context=context)
        obj2 = self._get_recursive_relations(cr, uid, model, ['one2many', 'many2many'], relation_fields=obj0, context=context)
        obj3 = self._get_recursive_relations(cr, uid, model, ['many2one'], relation_fields=obj0, context=context)
        for dummy, model in obj1:
            obj3 += self._get_recursive_relations(cr, uid, model, ['many2one'], relation_fields=obj0, context=context)
        return obj0, obj1, obj2, obj3 
开发者ID:osbzr,项目名称:gooderp_org,代码行数:35,代码来源:share_wizard.py

示例2: _basecontact_check_context

# 需要导入模块: from openerp.osv import fields [as 别名]
# 或者: from openerp.osv.fields import one2many [as 别名]
def _basecontact_check_context(self, cr, user, mode, context=None):
        if context is None:
            context = {}
        # Remove 'search_show_all_positions' for non-search mode.
        # Keeping it in context can result in unexpected behaviour (ex: reading
        # one2many might return wrong result - i.e with "attached contact" removed
        # even if it's directly linked to a company).
        if mode != 'search':
            context = dict(context)
            context.pop('search_show_all_positions', None)
        return context 
开发者ID:philmervdm,项目名称:modules_cci_odoo8,代码行数:13,代码来源:base_contact.py

示例3: _get_recursive_relations

# 需要导入模块: from openerp.osv import fields [as 别名]
# 或者: from openerp.osv.fields import one2many [as 别名]
def _get_recursive_relations(self, cr, uid, model, ttypes, relation_fields=None, suffix=None, context=None):
        """Returns list of tuples representing recursive relationships of type ``ttypes`` starting from
           model with ID ``model_id``.

           :param model: browsable model to start loading relationships from
           :param ttypes: list of relationship types to follow (e.g: ['one2many','many2many'])
           :param relation_fields: list of previously followed relationship tuples - to avoid duplicates
                                   during recursion
           :param suffix: optional suffix to append to the field path to reach the main object
        """
        if relation_fields is None:
            relation_fields = []
        local_rel_fields = []
        models = [x[1].model for x in relation_fields]
        model_obj = self.pool.get('ir.model')
        model_osv = self.pool[model.model]
        for field in model_osv._fields.itervalues():
            ftype = field.type
            relation_field = None
            if ftype in ttypes and field.comodel_name not in models:
                relation_model_id = model_obj.search(cr, UID_ROOT, [('model','=',field.comodel_name)])[0]
                relation_model_browse = model_obj.browse(cr, UID_ROOT, relation_model_id, context=context)
                relation_osv = self.pool[field.comodel_name]
                #skip virtual one2many fields (related, ...) as there is no reverse relationship
                if ftype == 'one2many' and field.inverse_name:
                    # don't record reverse path if it's not a real m2o (that happens, but rarely)
                    dest_fields = relation_osv._fields
                    reverse_rel = field.inverse_name
                    if reverse_rel in dest_fields and dest_fields[reverse_rel].type == 'many2one':
                        relation_field = ('%s.%s'%(reverse_rel, suffix)) if suffix else reverse_rel
                local_rel_fields.append((relation_field, relation_model_browse))
                for parent in relation_osv._inherits:
                    if parent not in models:
                        parent_model = self.pool[parent]
                        parent_fields = parent_model._fields
                        parent_model_browse = model_obj.browse(cr, UID_ROOT,
                                                               model_obj.search(cr, UID_ROOT, [('model','=',parent)]))[0]
                        if relation_field and field.inverse_name in parent_fields:
                            # inverse relationship is available in the parent
                            local_rel_fields.append((relation_field, parent_model_browse))
                        else:
                            # TODO: can we setup a proper rule to restrict inherited models
                            # in case the parent does not contain the reverse m2o?
                            local_rel_fields.append((None, parent_model_browse))
                if relation_model_id != model.id and ftype in ['one2many', 'many2many']:
                    local_rel_fields += self._get_recursive_relations(cr, uid, relation_model_browse,
                        [ftype], relation_fields + local_rel_fields, suffix=relation_field, context=context)
        return local_rel_fields 
开发者ID:osbzr,项目名称:gooderp_org,代码行数:50,代码来源:share_wizard.py

示例4: _compute_calculo_dias

# 需要导入模块: from openerp.osv import fields [as 别名]
# 或者: from openerp.osv.fields import one2many [as 别名]
def _compute_calculo_dias(self):
        carga = datetime.strptime(self.fecha_actual,'%Y-%m-%d')
        dias = datetime.today() - carga
        self.retraso = dias.days
        return True
    #FIN CALCULOS DE DIAS TRANSCURRIDOS




#class tools_helpdesk_solicitante(models.Model):
#    """Debería ser una Extensión de la clase hr.employee. Esta clase debe ir en tools.base"""
#    _name = 'tools.helpdesk.solicitante'
#    _rec_name = 'cedula'
#    _columns = {
#        'cedula': fields.integer(string="Cédula", help='Cedula de Identidad del Solicitante'),
#        'nombres': fields.char(string="Nombres", size=60, help='Nombres del Solicitante'),
#        'apellidos': fields.char(string="Apellidos", size=60, help='Apellidos del Solicitante'),
#        'estado_id': fields.Many2one('estado', string="Estados", help='Estado donde trabaja el solicitante'),
#        'regional': fields.boolean("Inces Regional"),
#        'rector': fields.boolean("Inces Rector"),
#        'cargo': fields.many2one('tools.base.hr_cargo', string="Cargo", help='Cargo del Solicitante'),
#        'dependencia_direccion_id': fields.many2one('tools.base.dependencia_direccion', string="Dirección"),
#        'dependencia_gerencia_id': fields.many2one('tools.base.dependencia_gerencia', string="Gerencia", help='Gerencia General o Regional a la que pertenece el solicitante'),
#        'dependencia_gerencia_linea_id': fields.many2one('tools.base.dependencia_gerencia_linea', string="Gerencia de Línea", help='Gerencia de Línea a la que pertenece el solicitante (En caso de Gerencia General)'),
#        'dependencia_cfs_id': fields.many2one('tools.base.dependencia_cfs', string="C.F.S.", help='C.F.S al que pertenece el solicitante (En caso de Gerencia Regional)'),
#        'dependencia_division_id': fields.many2one('tools.base.dependencia_division', string="División", help='División a la que pertenece el solicitante'),
#        'dependencia_coordinacion_id': fields.many2one('tools.base.dependencia_coordinacion', string="Coordinación", help='Coordinación a la que pertenece el solicitante'),
#        'email': fields.char(string="Correo Institucional", size=100, help='Correo Electrónico Institucional del solicitante'),
#        'ext_telefono1': fields.char(string="Extensión 1", size=5, help='Extensión Telefónica del Solicitante: Ej: 2066'),
#        'ext_telefono2': fields.char(string="Extensión 2", size=5, help='Extensión Telefónica del Solicitante: Ej: 2066'),
#        'telefono_personal': fields.char(string="Teléfono Personal", size=11, help='Telefóno Personal del Solicitante. Ej: 04261231234'),
#        'incidencia_ids': fields.one2many('tools.helpdesk.incidencia', 'solicitante_id', 'Incidencias Asociadas'),
#    }
#
#    _sql_constraints = [('cedula_solicitante_uniq', 'unique(cedula)', 'Este solicitante ya ha sido registrado en el sistema (cedula repetida)')]
#
#
#
#    @api.constrains('ext_telefono1','telefono_personal')
#    def validar_numerico(self):
#        if not self.ext_telefono1.isdigit():
#            raise osv.except_osv(('Error'),('La extensión debe contender solo numeros'))
#
#        if not self.telefono_personal.isdigit():
#            raise osv.except_osv(('Error'),('El teléfono debe contender solo numeros'))
#    
#    def name_get(self, cr, uid, ids, context=None):
#        res = []
#        solicitantes = self.browse(cr, uid, ids, context)
#        for solicitante in solicitantes:
#            res.append((solicitante.id, str(solicitante.cedula) + ' - ' + solicitante.nombres + ' ' + solicitante.apellidos))
#        return res
#
#    def create(self, cr, uid, vals, context=None):   #esta campo actualiza el registro
#        vals['cedula'] = uid
#        vals['nombres'] = uid
#        vals['apellidos'] = uid
#        result = super(tools.helpdesk.solicitante, self).create(cr, uid, vals, context=context)
#        return result
#tools_helpdesk_solicitante() 
开发者ID:BachacoVE,项目名称:tools_helpdesk,代码行数:63,代码来源:tools_helpdesk.py


注:本文中的openerp.osv.fields.one2many方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。