def _value_pickle(self, cursor, user, id, name, value, arg, context=None):
     if context is None:
         context = {}
     ctx = context.copy()
     if self.CONCURRENCY_CHECK_FIELD in ctx:
         del ctx[self.CONCURRENCY_CHECK_FIELD]
     record = self.browse(cursor, user, id, context=context)
     if record.key == 'default':
         # default values are pickled on the fly
         if isinstance(value, (str, unicode)):
             try:
                 value = pickle.dumps(eval(value))
             except Exception:
                 value = pickle.dumps(value)
         else:
             value = pickle.dumps(value)
     self.write(cursor, user, id, {name[:-9]: value}, context=ctx)
Exemple #2
0
 def _value_pickle(self, cursor, user, id, name, value, arg, context=None):
     if context is None:
         context = {}
     ctx = context.copy()
     if self.CONCURRENCY_CHECK_FIELD in ctx:
         del ctx[self.CONCURRENCY_CHECK_FIELD]
     record = self.browse(cursor, user, id, context=context)
     if record.key == 'default':
         # default values are pickled on the fly
         if isinstance(value, (str, unicode)):
             try:
                 value = pickle.dumps(eval(value))
             except Exception:
                 value = pickle.dumps(value)
         else:
             value = pickle.dumps(value)
     self.write(cursor, user, id, {name[:-9]: value}, context=ctx)
Exemple #3
0
 def _value_pickle(self, cursor, user, id, name, value, arg, context=None):
     if context is None:
         context = {}
     ctx = context.copy()
     if self.CONCURRENCY_CHECK_FIELD in ctx:
         del ctx[self.CONCURRENCY_CHECK_FIELD]
     record = self.browse(cursor, user, id, context=context)
     if record.key == 'default':
         # default values are pickled on the fly
         value = pickle.dumps(value)
     self.write(cursor, user, id, {name[:-9]: value}, context=ctx)
Exemple #4
0
    def refresh_cache(self):
        products = self.env['product.product'].search(self.get_product_domain())
        prod_ctx = products.with_context(pricelist=self.config_id.pricelist_id.id, display_default_code=False,
                                         lang=self.compute_user_id.lang)
        prod_ctx = prod_ctx.sudo(self.compute_user_id.id)
        res = prod_ctx.read(self.get_product_fields())
        datas = {
            'cache': cPickle.dumps(res),
        }

        self.write(datas)
Exemple #5
0
 def _value_pickle(self, cursor, user, id, name, value, arg, context=None):
     if context is None:
         context = {}
     ctx = context.copy()
     if self.CONCURRENCY_CHECK_FIELD in ctx:
         del ctx[self.CONCURRENCY_CHECK_FIELD]
     record = self.browse(cursor, user, id, context=context)
     if record.key == 'default':
         # default values are pickled on the fly
         value = pickle.dumps(value)
     self.write(cursor, user, id, {name[:-9]: value}, context=ctx)
Exemple #6
0
    def refresh_cache(self):
        products = self.env['product.product'].search(
            self.get_product_domain())
        prod_ctx = products.with_context(
            pricelist=self.config_id.pricelist_id.id,
            display_default_code=False,
            lang=self.compute_user_id.lang)
        prod_ctx = prod_ctx.sudo(self.compute_user_id.id)
        res = prod_ctx.read(self.get_product_fields())
        datas = {
            'cache': cPickle.dumps(res),
        }

        self.write(datas)
Exemple #7
0
    def set_default(self,
                    cr,
                    uid,
                    model,
                    field_name,
                    value,
                    for_all_users=True,
                    company_id=False,
                    condition=False):
        """Defines a default value for the given model and field_name. Any previous
           default for the same scope (model, field_name, value, for_all_users, company_id, condition)
           will be replaced and lost in the process.

           Defaults can be later retrieved via :meth:`~.get_defaults`, which will return
           the highest priority default for any given field. Defaults that are more specific
           have a higher priority, in the following order (highest to lowest):

               * specific to user and company
               * specific to user only
               * specific to company only
               * global to everyone

           :param string model: model name
           :param string field_name: field name to which the default applies
           :param value: the default field value to set
           :type value: any serializable Python value
           :param bool for_all_users: whether the default should apply to everybody or only
                                      the user calling the method
           :param int company_id: optional ID of the company to which the default should
                                  apply. If omitted, the default will be global. If True
                                  is passed, the current user's company will be used.
           :param string condition: optional condition specification that can be used to
                                    restrict the applicability of the default values
                                    (e.g. based on another field's value). This is an
                                    opaque string as far as the API is concerned, but client
                                    stacks typically use single-field conditions in the
                                    form ``'key=stringified_value'``.
                                    (Currently, the condition is trimmed to 200 characters,
                                    so values that share the same first 200 characters always
                                    match)
           :return: id of the newly created ir.values entry
        """
        if isinstance(value, unicode):
            value = value.encode('utf8')
        if company_id is True:
            # should be company-specific, need to get company id
            user = self.pool.get('res.users').browse(cr, uid, uid)
            company_id = user.company_id.id

        # remove existing defaults for the same scope
        search_criteria = [('key', '=', 'default'),
                           ('key2', '=', condition and condition[:200]),
                           ('model', '=', model), ('name', '=', field_name),
                           ('user_id', '=', False if for_all_users else uid),
                           ('company_id', '=', company_id)]
        self.unlink(cr, uid, self.search(cr, uid, search_criteria))

        return self.create(
            cr, uid, {
                'name': field_name,
                'value': pickle.dumps(value),
                'model': model,
                'key': 'default',
                'key2': condition and condition[:200],
                'user_id': False if for_all_users else uid,
                'company_id': company_id,
            })
Exemple #8
0
    def set_default(self, cr, uid, model, field_name, value, for_all_users=True, company_id=False, condition=False):
        """Defines a default value for the given model and field_name. Any previous
           default for the same scope (model, field_name, value, for_all_users, company_id, condition)
           will be replaced and lost in the process.

           Defaults can be later retrieved via :meth:`~.get_defaults`, which will return
           the highest priority default for any given field. Defaults that are more specific
           have a higher priority, in the following order (highest to lowest):

               * specific to user and company
               * specific to user only
               * specific to company only
               * global to everyone

           :param string model: model name
           :param string field_name: field name to which the default applies
           :param value: the default field value to set
           :type value: any serializable Python value
           :param bool for_all_users: whether the default should apply to everybody or only
                                      the user calling the method
           :param int company_id: optional ID of the company to which the default should
                                  apply. If omitted, the default will be global. If True
                                  is passed, the current user's company will be used.
           :param string condition: optional condition specification that can be used to
                                    restrict the applicability of the default values
                                    (e.g. based on another field's value). This is an
                                    opaque string as far as the API is concerned, but client
                                    stacks typically use single-field conditions in the
                                    form ``'key=stringified_value'``.
                                    (Currently, the condition is trimmed to 200 characters,
                                    so values that share the same first 200 characters always
                                    match)
           :return: id of the newly created ir.values entry
        """
        if isinstance(value, unicode):
            value = value.encode('utf8')
        if company_id is True:
            # should be company-specific, need to get company id
            user = self.pool.get('res.users').browse(cr, uid, uid)
            company_id = user.company_id.id

        # remove existing defaults for the same scope
        search_criteria = [
            ('key', '=', 'default'),
            ('key2', '=', condition and condition[:200]),
            ('model', '=', model),
            ('name', '=', field_name),
            ('user_id', '=', False if for_all_users else uid),
            ('company_id','=', company_id)
            ]
        self.unlink(cr, uid, self.search(cr, uid, search_criteria))

        return self.create(cr, uid, {
            'name': field_name,
            'value': pickle.dumps(value),
            'model': model,
            'key': 'default',
            'key2': condition and condition[:200],
            'user_id': False if for_all_users else uid,
            'company_id': company_id,
        })