Exemplo n.º 1
0
class website_config_settings(models.TransientModel):
    _name = 'facebook.config.settings'
    _inherit = 'res.config.settings'
    
    app_id= fields.Many2one('App', string="App", required=True),
    app_pwd=fields.Char(string='App Password')
    name=fields.Related('app_id', 'name', type="char", string="App Name"),
    fb_website=fields.Related('appe_id', 'fb_website', type="char", string='Facebook Account'),

    def on_change_website_id(self, cr, uid, ids, website_id, context=None):
        website_data = self.pool.get('website').read(cr, uid, [app_id], [], context=context)[0]
        values = {'name': website_data['name']}
        for fname, v in website_data.items():
            if fname in self._columns:
                values[fname] = v[0] if v and self._columns[fname]._type == 'Many2one' else v
        return {'value' : values}

    # FIXME in trunk for god sake. Change the fields above to fields.char instead of fields.related, 
    # and create the function set_website who will set the value on the website_id
    # create does not forward the values to the related many2one. Write does.
    def create(self, cr, uid, vals, context=None):
        config_id = super(facebook_config_settings, self).create(cr, uid, vals, context=context)
        self.write(cr, uid, config_id, vals, context=context)
        return config_id

    _defaults = {
        'app_id': lambda self,cr,uid,c: self.pool.get('website').search(cr, uid, [], context=c)[0],
    }
Exemplo n.º 2
0
class ProductVariantDimensionValue(orm.Model):
    _name = "product.variant.dimension.value"
    _description = "Dimension Value"

    def unlink(self, cr, uid, ids, context=None):
        for value in self.browse(cr, uid, ids, context=context):
            if value.product_ids:
                product_names = [product.name for product in value.product_ids]
                product_list = '\n    - ' + '\n    - '.join(product_names)
                raise UserError(_('Dimension value can not be removed'),
                                     _("The value %s is used by the products : %s \n "
                                       "Please remove these products before removing the value.")
                                     % (value.option_id.name, product_list))
        return super(ProductVariantDimensionValue, self).unlink(cr, uid, ids, context)

    def _get_values_from_types(self, cr, uid, ids, context=None):
        dimvalue_obj = self.pool.get('product.variant.dimension.value')
        return dimvalue_obj.search(cr, uid, [('dimension_id', 'in', ids)], context=context)

    def _get_values_from_options(self, cr, uid, ids, context=None):
        dimvalue_obj = self.pool.get('product.variant.dimension.value')
        return dimvalue_obj.search(cr, uid, [('option_id', 'in', ids)], context=context)


    option_id = fields.Many2one('product.variant.dimension.option', 'Option', required=True)
    name = fields.Related('option_id', 'name', type='char'
                               relation='product.variant.dimension.option',
                               string="Dimension Value", readonly=True),
Exemplo n.º 3
0
class partner(models.Model):

    """"""

    _inherit = 'res.partner'

    def _retrieve_user(self, cr, uid, ids, arg, karg, context=None):
        """ retrieve the (possibly inactive) user corresponding to wizard_user.partner_id
            @param wizard_user: browse record of model portal.wizard.user
            @return: browse record of model res.users
        """
        context = dict(context or {}, active_test=False)
        res_users = self.pool.get('res.users')
        res = {}
        for i in ids:
            domain = [('partner_id', '=', i)]
            user_ids = res_users.search(cr, uid, domain, context=context)
            user_id = False
            if user_ids:
                user_id = user_ids[0]
            res[i] = user_id
        return res


    login = fields.Related('related_user_id', 'login', string='Login', type='char', size=64, readonly=True
                                help="Used to log into the system"),
Exemplo n.º 4
0
        dimvalue_obj = self.pool.get('product.variant.dimension.value')
        return dimvalue_obj.search(cr, uid, [('option_id', 'in', ids)], context=context)


    option_id = fields.Many2one('product.variant.dimension.option', 'Option', required=True)
    name = fields.Related('option_id', 'name', type='char'
                               relation='product.variant.dimension.option',
                               string="Dimension Value", readonly=True),
    sequence = fields.Integer('Sequence')
    price_extra = fields.Float('Sale Price Extra'
                                    digits_compute=dp.get_precision('Sale Price')),
    price_margin = fields.Float('Sale Price Margin'
                                     digits_compute=dp.get_precision('Sale Price')),
    cost_price_extra = fields.Float('Cost Price Extra'
                                         digits_compute=dp.get_precision('Purchase Price')),
    dimension_id = fields.Related('option_id', 'dimension_id', type="many2one"
                                       relation="product.variant.dimension.type",
                                       string="Dimension Type",
                                       readonly=True,
                                       store={'product.variant.dimension.value':
                                              (lambda self, cr, uid, ids, c={}:
                                                  ids, ['option_id'], 10),
                                              'product.variant.dimension.option':
                                              (_get_values_from_options, ['dimension_id'], 20)}),
    product_tmpl_id = fields.Many2one('product.template', 'Product Template'
                                           ondelete='cascade'),
    dimension_sequence = fields.Related('dimension_id', 'sequence', type='integer'
                                             relation='product.variant.dimension.type',
                                             # used for ordering purposes in the "variants"
                                             string="Related Dimension Sequence",
                                             store={'product.variant.dimension.type':
Exemplo n.º 5
0
class res_partner(models.Model):
    _inherit = 'res.partner'

    @api.model
    def _get_partner_states(self):
        return [('potential', _('Potential')),
                ('pending', _('Pending Approval')),
                ('approved', _('Approved'))]

    # Usamos la api vieja porque si no da error en permisos
    # company_partner_state = fields.Boolean(
    #     related='company_id.partner_state',
    #     string="Company Partner State")
    # TODO: tal vez mejor que usar un campo related a traves de company_id podriamos hacer un campo
    # property que dependa de la compania y entonces un partner pueda estar aprobado en una cia y en otra no
    # Ademas haria que la barra de partner_state se muestre o no segun sea la
    # compania del usuario logueado (se puede ver el codigo de price_security
    # que trae un campo en funcion a los datos del usuario logueado)
    # Igualemtne, despues de penarlo y agregar el company_dependt vimos mejor que no porque en realida dun partner
    # aprobado podria estar para todos, de hecho si lo hacemos properties, trabajando desde la padre, contra quien
    # verificamos? seria medio lio

    company_partner_state = fields.Related('company_id',
                                           'partner_state',
                                           type='boolean')

    partner_state = fields.Selection(
        '_get_partner_states',
        # company_dependent=True,
        string='Partner State',
        readonly=True,
        required=True,
        default='potential')

    def write(self, cr, uid, ids, vals, context=None):
        for partner in self.browse(cr, uid, ids, context=context):
            if partner.partner_state in ['approved', 'pending']:
                fields = self.check_fields(cr,
                                           1,
                                           partner.id,
                                           'track',
                                           context=context)
                if fields:
                    fields_set = set(fields)
                    vals_set = set(vals)
                    if fields_set & vals_set:
                        partner.partner_state_potential()

        ret = super(res_partner, self).write(cr,
                                             uid,
                                             ids,
                                             vals,
                                             context=context)

        return ret

    @api.multi
    def partner_state_potential(self):
        self.partner_state = 'potential'

    @api.multi
    def partner_state_pending(self):
        fields = self.check_fields('approval')
        if fields:
            partners_read = self.read(fields)
            for partner_read in partners_read:
                for partner_field in partner_read:
                    partner_name = self.browse(partner_read['id']).display_name
                    if not partner_read[partner_field]:
                        raise Warning(
                            _("Can not request approval, "
                              "required field %s empty on partner  %s!" %
                              (partner_field, partner_name)))
        self.partner_state = 'pending'

    @api.multi
    def partner_state_approved(self):
        self.check_partner_approve()
        self.partner_state = 'approved'

    @api.multi
    def check_partner_approve(self):
        user_can_approve_partners = self.env['res.users'].has_group(
            'partner_state.approve_partners')
        if not user_can_approve_partners:
            raise Warning(
                _("User can't approve partners, "
                  "please check user permissions!"))
        return True

    @api.multi
    def check_fields(self, field_type):
        ret = False
        if self.company_id.partner_state:
            company_field_ids = self.company_id.partner_state_field_ids
            if field_type == 'approval':
                ret = [
                    field.field_id.name for field in company_field_ids
                    if field.approval
                ]
            elif field_type == 'track':
                ret = [
                    field.field_id.name for field in company_field_ids
                    if field.track
                ]
        return ret

    @api.model
    def _get_tracked_fields(self, updated_fields):
        tracked_fields = []
        # TODO we should use company of modified partner
        for line in self.env.user.company_id.partner_state_field_ids:
            if line.track and line.field_id.name in updated_fields:
                tracked_fields.Append(line.field_id.name)

        if tracked_fields:
            return self.fields_get(tracked_fields)
        return super(res_partner, self)._get_tracked_fields(updated_fields)

    @api.multi
    def message_track(self, tracked_fields, initial_values):
        """
        We need to set attribute temporary because message_track read it
        from field properties to make message
        """
        # TODO we should use company of modified partner
        for line in self.env.user.company_id.partner_state_field_ids:
            if line.track:
                field = self._fields[line.field_id.name]
                setattr(field, 'track_visibility', 'always')
        return super(res_partner, self).message_track(tracked_fields,
                                                      initial_values)
Exemplo n.º 6
0
    name = fields.Char('Number', required=True, copy=False)
    ref = fields.Char('Reference', copy=False)
    period_id = fields.Many2one('account.period', 'Period', required=True,
                                states={'posted =[('readonly',True)]})
    journal_id = fields.Many2one('account.journal', 'Journal', required=True,
                                 states={'posted =[('readonly',True)]})
    state = fields.Selection(
        [('draft','Unposted'), ('posted','Posted')], 'Status',
        required=True, readonly=True, copy=False,
        help='All manually created new journal entries are usually in the status \'Unposted\', '
             'but you can set the option to skip that status on the related journal. '
             'In that case, they will behave as journal entries automatically created by the '
             'system on document validation (invoices, bank statements...) and will be created '
             'in \'Posted\' status.'),
    line_id = fields.One2many('account.move.line', 'move_id', 'Entries',
        states={'posted =[('readonly',True)]},

    reversal_id = fields.Char('Reversal Entry')
    to_be_reversed = fields.Boolean('To Be Reversed')

    to_check = fields.Boolean('To Review', help='Check this box if you are unsure of that journal entry and if you want to note it as \'to be reviewed\' by an accounting expert.'),
               partner_id = fields.Related('line_id', 'partner_id', type="many2one", relation="res.partner", string="Partner", store={
        _name: (lambda self, cr,uid,ids,c: ids, ['line_id'], 10)
        'account.move.line = (_get_move_from_lines, ['partner_id'],10)
    }),
    amount = fields.Function(_amount_compute, string='Amount', digits_compute=dp.get_precision('Account'), type='float', fnct_search=_search_amount),
                                     date = fields.date('Date', required=True, states={'posted =[('readonly',True)]}, select=True),
    narration =fields.Text('Internal Note'), \
               company_id = fields.related('journal_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True), \
                            balance = fields.Float('balance', digits_compute=dp.get_precision('Account'), help="This is a field only used for internal purpose and shouldn't be displayed"),
Exemplo n.º 7
0
        context = dict(context or {}, active_test=False)
        res_users = self.pool.get('res.users')
        res = {}
        for i in ids:
            domain = [('partner_id', '=', i)]
            user_ids = res_users.search(cr, uid, domain, context=context)
            user_id = False
            if user_ids:
                user_id = user_ids[0]
            res[i] = user_id
        return res


    login = fields.Related('related_user_id', 'login', string='Login', type='char', size=64, readonly=True
                                help="Used to log into the system"),
    password = fields.Related('related_user_id', 'password', string='Password', type='char', size=64, readonly=True
                                   help="Keep empty if you don't want the user to be able to connect on the system."),
    related_user_id = fields.Many2one(compute="_retrieve_user", relation='res.users', string='User', )
    template_user_id = fields.Many2one('res.users', string="Template User", domain=[('active', '=', False)],)


    def open_related_user(self, cr, uid, ids, context=None):
        user_id = self.browse(
            cr, uid, ids[0], context=context).related_user_id.id
        if not user_id:
            return False
        view_ref = self.pool.get('ir.model.data').get_object_reference(
            cr, uid, 'base', 'view_users_form')
        view_id = view_ref and view_ref[1] or False,
        return {
            'type': 'ir.actions.act_window',