diff --git a/purchase_suggest/wizard/purchase_suggest.py b/purchase_suggest/wizard/purchase_suggest.py index bb8fbd7..cf22645 100644 --- a/purchase_suggest/wizard/purchase_suggest.py +++ b/purchase_suggest/wizard/purchase_suggest.py @@ -93,7 +93,7 @@ class PurchaseSuggestionGenerate(models.TransientModel): if op.product_id.id not in products: products[op.product_id.id] = { 'min_qty': op.product_min_qty, - 'draft_po_qty': 0.0, + 'draft_po_qty': 0.0, # This value is set later on 'orderpoint': op, 'product': op.product_id } diff --git a/purchase_suggest_min_qty_on_product/__init__.py b/purchase_suggest_min_qty_on_product/__init__.py new file mode 100644 index 0000000..c5280ed --- /dev/null +++ b/purchase_suggest_min_qty_on_product/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import product +from . import wizard diff --git a/purchase_suggest_min_qty_on_product/__openerp__.py b/purchase_suggest_min_qty_on_product/__openerp__.py new file mode 100644 index 0000000..890213b --- /dev/null +++ b/purchase_suggest_min_qty_on_product/__openerp__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Suggest Min Qty on Product module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +{ + 'name': 'Purchase Suggest Min Qty on Product', + 'version': '0.1', + 'category': 'Purchase', + 'license': 'AGPL-3', + 'summary': 'Replace orderpoints by a min_qty field on product', + 'description': """ +Purchase Suggest Min Qty on Product +=================================== + +With this module, instead of using orderpoints, we add a *min_qty* field on product.product and we use this value as the minimum stock. This makes it easier for users to read and update the min_qty. But this should only be used if there is only 1 warehouse where we handle min stock rules (because, with this module, you cannot set min_qty per warehouse or per stock location). + +This module has been written by Alexis de Lattre from Akretion . + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['purchase_suggest'], + 'data': [ + 'product_view.xml', + 'wizard/purchase_suggest_view.xml', + ], + 'installable': True, +} diff --git a/purchase_suggest_min_qty_on_product/product.py b/purchase_suggest_min_qty_on_product/product.py new file mode 100644 index 0000000..fe0724d --- /dev/null +++ b/purchase_suggest_min_qty_on_product/product.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Suggest Min Qty on Product module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, fields +import openerp.addons.decimal_precision as dp + + +class ProductProduct(models.Model): + _inherit = 'product.product' + + min_qty = fields.Float( + string=u'Minimum Quantity', track_visibility='onchange', + digits=dp.get_precision('Product Unit of Measure'), + company_dependent=True, + help="If the forecast quantity is lower than the value of this field, " + "Odoo will suggest to re-order this product.") diff --git a/purchase_suggest_min_qty_on_product/product_view.xml b/purchase_suggest_min_qty_on_product/product_view.xml new file mode 100644 index 0000000..6bf1af2 --- /dev/null +++ b/purchase_suggest_min_qty_on_product/product_view.xml @@ -0,0 +1,38 @@ + + + + + + + + + purchase_suggest_min_qty_on_product.product.product.tree + product.product + + + + + + + + + + purchase_suggest_min_qty_on_product.product.product.form + product.product + + 1000 + + + + + + + + + + + diff --git a/purchase_suggest_min_qty_on_product/wizard/__init__.py b/purchase_suggest_min_qty_on_product/wizard/__init__.py new file mode 100644 index 0000000..846ea38 --- /dev/null +++ b/purchase_suggest_min_qty_on_product/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import purchase_suggest diff --git a/purchase_suggest_min_qty_on_product/wizard/purchase_suggest.py b/purchase_suggest_min_qty_on_product/wizard/purchase_suggest.py new file mode 100644 index 0000000..7b36db1 --- /dev/null +++ b/purchase_suggest_min_qty_on_product/wizard/purchase_suggest.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Purchase Suggest Min Qty on Product module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp import models, fields, api + + +class PurchaseSuggestionGenerate(models.TransientModel): + _inherit = 'purchase.suggest.generate' + + # Without this module, when we use orderpoints, if there are no orderpoints + # for a consu product, Odoo will not suggest to re-order it. + # But, with this module, Odoo will also suggest to re-order the consu + # products, which may not be what the user wants + product_type = fields.Selection([ + ('product', 'Stockable Product'), + ('product_and_consu', 'Consumable and Stockable Product'), + ], default='product', string='Product Type') + + @api.model + def _prepare_suggest_line(self, product_id, qty_dict): + sline = super(PurchaseSuggestionGenerate, self)._prepare_suggest_line( + product_id, qty_dict) + sline['company_id'] = self.env.user.company_id.id + return sline + + @api.model + def generate_products_dict(self): + '''inherit the native method to use min_qty on product.product''' + ppo = self.env['product.product'] + product_domain = [] + products = {} + if self.product_type == 'product': + product_domain.append(('type', '=', 'product')) + if self.categ_ids or self.seller_ids: + if self.categ_ids: + product_domain.append( + ('categ_id', 'child_of', self.categ_ids.ids)) + if self.seller_ids: + product_domain.append( + ('seller_id', 'in', self.seller_ids.ids)) + product_to_analyse = ppo.search(product_domain) + for product in product_to_analyse: + # We also want the missing product that have min_qty = 0 + # So we remove "if product.z_stock_min > 0" + products[product.id] = { + 'min_qty': product.min_qty, + 'draft_po_qty': 0.0, # This value is set later on + 'orderpoint': False, + 'product': product, + } + return products diff --git a/purchase_suggest_min_qty_on_product/wizard/purchase_suggest_view.xml b/purchase_suggest_min_qty_on_product/wizard/purchase_suggest_view.xml new file mode 100644 index 0000000..94281c8 --- /dev/null +++ b/purchase_suggest_min_qty_on_product/wizard/purchase_suggest_view.xml @@ -0,0 +1,27 @@ + + + + + + + + + purchase_suggest_min_qty_on_product.generate.form + purchase.suggest.generate + + + + 1 + + + + + + + + +