Skip to Content
Menú
This question has been flagged
12 Respostes
8641 Vistes

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.

Avatar
Descartar

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

Where is "minimum order quantity field"?

Autor

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

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

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

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.

Avatar
Descartar

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

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
Descartar
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).

Avatar
Descartar
Autor

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.

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.

Avatar
Descartar
Autor

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

Related Posts Respostes Vistes Activitat
3
d’ag. 24
1791
0
d’ag. 21
2089
2
de març 15
8325
1
de des. 24
2269
1
de des. 24
1175