Add module purchase_suggest_min_qty_on_product

This commit is contained in:
Alexis de Lattre
2015-12-30 10:37:01 +01:00
parent abe79d1c48
commit a068c534bb
8 changed files with 224 additions and 1 deletions

View File

@@ -93,7 +93,7 @@ class PurchaseSuggestionGenerate(models.TransientModel):
if op.product_id.id not in products: if op.product_id.id not in products:
products[op.product_id.id] = { products[op.product_id.id] = {
'min_qty': op.product_min_qty, 'min_qty': op.product_min_qty,
'draft_po_qty': 0.0, 'draft_po_qty': 0.0, # This value is set later on
'orderpoint': op, 'orderpoint': op,
'product': op.product_id 'product': op.product_id
} }

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import product
from . import wizard

View File

@@ -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 <alexis.delattre@akretion.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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 <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['purchase_suggest'],
'data': [
'product_view.xml',
'wizard/purchase_suggest_view.xml',
],
'installable': True,
}

View File

@@ -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 <alexis.delattre@akretion.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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.")

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="view_stock_product_tree" model="ir.ui.view">
<field name="name">purchase_suggest_min_qty_on_product.product.product.tree</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="stock.view_stock_product_tree"/>
<field name="arch" type="xml">
<field name="virtual_available" position="after">
<field name="min_qty"/>
</field>
</field>
</record>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">purchase_suggest_min_qty_on_product.product.product.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="priority">1000</field>
<field name="arch" type="xml">
<field name="virtual_available" position="after">
<separator name="min_qty" colspan="2"/>
<field name="min_qty"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import purchase_suggest

View File

@@ -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 <alexis.delattre@akretion.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="purchase_suggest_generate_form" model="ir.ui.view">
<field name="name">purchase_suggest_min_qty_on_product.generate.form</field>
<field name="model">purchase.suggest.generate</field>
<field name="inherit_id" ref="purchase_suggest.purchase_suggest_generate_form"/>
<field name="arch" type="xml">
<field name="location_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="categ_ids" position="before">
<field name="product_type"/>
</field>
</field>
</record>
</data>
</openerp>