Add support for max_qty in purchase_suggest

This commit is contained in:
Alexis de Lattre
2016-06-19 23:40:52 +02:00
parent 6812d2e68b
commit 62b01c781f
5 changed files with 51 additions and 3 deletions

View File

@@ -51,6 +51,16 @@ class PurchaseSuggestGenerate(models.TransientModel):
order='id desc', limit=1)
# I cannot filter on 'date_order' because it is not a stored field
porderline_id = porderlines and porderlines[0].id or False
future_qty = qty_dict['virtual_available'] + qty_dict['draft_po_qty']
if float_compare(
qty_dict['max_qty'], qty_dict['min_qty'],
precision_rounding=qty_dict['product'].uom_id.rounding) == 1:
# order to go up to qty_max
qty_to_order = qty_dict['max_qty'] - future_qty
else:
# order to go up to qty_min
qty_to_order = qty_dict['min_qty'] - future_qty
sline = {
'company_id':
qty_dict['orderpoint'] and qty_dict['orderpoint'].company_id.id,
@@ -64,7 +74,9 @@ class PurchaseSuggestGenerate(models.TransientModel):
qty_dict['orderpoint'] and qty_dict['orderpoint'].id,
'location_id': self.location_id.id,
'min_qty': qty_dict['min_qty'],
'max_qty': qty_dict['max_qty'],
'last_po_line_id': porderline_id,
'qty_to_order': qty_to_order,
}
return sline
@@ -98,6 +110,7 @@ class PurchaseSuggestGenerate(models.TransientModel):
if op.product_id.id not in products:
products[op.product_id.id] = {
'min_qty': op.product_min_qty,
'max_qty': op.product_max_qty,
'draft_po_qty': 0.0, # This value is set later on
'orderpoint': op,
'product': op.product_id
@@ -237,6 +250,10 @@ class PurchaseSuggest(models.TransientModel):
string="Min Quantity", readonly=True,
digits=dp.get_precision('Product Unit of Measure'),
help="in the unit of measure for the product")
max_qty = fields.Float(
string="Max Quantity", readonly=True,
digits=dp.get_precision('Product Unit of Measure'),
help="in the unit of measure for the product")
qty_to_order = fields.Float(
string='Quantity to Order',
digits=dp.get_precision('Product Unit of Measure'),

View File

@@ -59,7 +59,8 @@
<field name="incoming_qty"/>
<field name="outgoing_qty"/>
<field name="draft_po_qty"/>
<field name="min_qty"/>
<field name="min_qty" string="Min Qty"/>
<field name="max_qty" string="Max Qty"/>
<field name="uom_id" groups="product.group_uom"/>
<field name="last_po_date" widget="date"/>
<field name="last_po_qty"/>

View File

@@ -20,8 +20,10 @@
#
##############################################################################
from openerp import models, fields
from openerp import models, fields, api, _
import openerp.addons.decimal_precision as dp
from openerp.tools import float_compare, float_is_zero
from openerp.exceptions import ValidationError
class ProductProduct(models.Model):
@@ -34,3 +36,28 @@ class ProductProduct(models.Model):
help="If the forecast quantity is lower than the value of this field, "
"Odoo will suggest to re-order this product. This field is in the "
"unit of measure of the product.")
max_qty = fields.Float(
string=u'Maximum 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 the minimum "
" quantity, Odoo will suggest to re-order this product to go up to "
"the maximum quantity. This field is in the unit of measure of the "
"product.")
@api.constrains('min_qty', 'max_qty')
def check_min_max_qty(self):
precision = self.env['decimal.precision'].precision_get(
'Product Unit of Measure')
for product in self:
if (
not float_is_zero(
product.max_qty, precision_digits=precision) and
float_compare(
product.max_qty, product.min_qty,
precision_digits=precision) != 1):
raise ValidationError(_(
"On product '%s', the maximum quantity (%s) is lower "
"than the minimum quantity (%s).") % (
product.name_get()[0][1],
product.max_qty, product.min_qty))

View File

@@ -29,6 +29,7 @@
<field name="virtual_available" position="after">
<separator name="min_qty" colspan="2"/>
<field name="min_qty"/>
<field name="max_qty"/>
</field>
</field>
</record>

View File

@@ -44,7 +44,8 @@ class PurchaseSuggestionGenerate(models.TransientModel):
@api.model
def generate_products_dict(self):
'''inherit the native method to use min_qty on product.product'''
'''inherit the native method to use min_qty/max_qty on
product.product'''
ppo = self.env['product.product']
products = {}
product_domain = self._prepare_product_domain()
@@ -56,6 +57,7 @@ class PurchaseSuggestionGenerate(models.TransientModel):
# So we remove "if product.z_stock_min > 0"
products[product.id] = {
'min_qty': product.min_qty,
'max_qty': product.max_qty,
'draft_po_qty': 0.0, # This value is set later on
'orderpoint': False,
'product': product,