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

@@ -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,