Help

3

How to add a default minimum stock rules for newly created products ?

Avatar
Ahmet Altinisik

How to add a default minimum stock rule for newly created products ?

When creating a new product I want a default minimum stock rule to be added automatically. I am not asking how to define minimum stock rule to the product. For normal fields I can define by set defaults menu. However it does not work with minimum stock rule field since there is a create button and a seperate rule is created and selected.

5 Comments
Avatar
Discard
Avatar
Gilles Major (gim)
-

ok I've deleted both answers since they are not related to your question

Avatar
Jānis
-

Where is "minimum order quantity field"?

Avatar
Ahmet Altinisik
-

sorry it is "minimum stock rules" since I am using openerp in my native such errors occurs. I just corrected the question.

Avatar
Cameron
-

Just tried editing the default value directly in the database "stock_warehouse_orderpoint" but had no affect - Sorry - i'll bump the question

Avatar
Marcel Linke
-

Maybe by creating an automatic action to be triggered when creating new products? I've seen that this is possible in administrator settings

4 Answers
3
Avatar
Andreas Brueckl
Best Answer

If you are familiar with OpenERP modules I would suggest to override the create()-method in product.product:

class product_product(osv.Model):
    _inherit = 'product.product'

    def create(self, cr, uid, data, context=None):
        prod_id = super(product_product, self).create(cr, uid, data, context=context)

        vals = {
           'product_id': prod_id,
           ....
        }
        self.pool.get('stock.warehouse.orderpoint').create(cr, uid, vals, context=context)
        return prod_id

But it is not that easy because there are other required fields in stock.warehouse.orderpoint which you would have to populate. (e.g. warehouse_id, location_id).

If you use 'Automated Actions', the problem with the required fields also exist. However I do not think that is possible apply Automated Actions on created objects.

1 Comment
Avatar
Discard
Avatar
Hachem Chraiti
-

i can not find the create method of the product?? from which method the product creation is handled?

0
Avatar
Herve GUERIN
Best Answer

Hi,

Thanks to 

I needed this trick in odoo v8, so here is my version :


    class ProductProduct(models.Model):

      _inherit = 'product.product' 

      @api.model

      def create(self, data, context=None):

        """ add a default orderpoint line to every new product """

        product = super(ProductProduct, self).create(data, context=context)

        # apply same domain rule as the one of button "Règles de réassort" of the odoo-web interface

        if product.product_tmpl_id.type != 'service':

            # add automatically the orderpoint (règle d'approvisionnement)

            vals = {

               'product_id': product.id,

               'product_min_qty': 0,

               'product_max_qty': 0,

               'qty_multiple': 1,

            }

            # desperatly a call with old api way but I didn't succeded to do this with the new api way

            self.pool.get('stock.warehouse.orderpoint').create(self._cr, self._uid, vals, context=context)

        return product


Now, I'd like to add a rule to check if the sub-record stock.warehouse.orderpoint is still there when there is an update (otherwize, the integrity is not fully checked)

Avatar
Discard
0
Avatar
Jānis
Best Answer

Hope this will help you:

go to product card and open page Procurements and in section Suppliers make new entry with minimal quantity.

1 Comment
Avatar
Discard
Avatar
Ahmet Altinisik
-

sorry maybe question was not clear enogh, I updated the question

0
Avatar
Gilles Major (gim)
Best Answer

I'm not exactly sure what you mean.

If what you're concerned about is defining minimum quantities for purchases: - go to the product form => procurements tab. In the Suppliers section, you can define a minimal order quantity for a given supplier (you need to activate "Manage pricelist per supplier" in the purchase settings first).

1 Comment
Avatar
Discard
Avatar
Ahmet Altinisik
-

When creating a new product I want a default minimum order quantitiy value to be added automatically. I am not asking how to define minimum order quantitiy.