mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
@@ -1,9 +1,8 @@
|
||||
# Copyright (C) 2019 Open Source Integrators
|
||||
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import fields, models
|
||||
from odoo.addons import decimal_precision as dp
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class StockLocationLimit(models.Model):
|
||||
@@ -11,19 +10,6 @@ class StockLocationLimit(models.Model):
|
||||
_description = 'Stock Location Limit Product'
|
||||
_rec_name = 'product_id'
|
||||
|
||||
@api.onchange('product_id')
|
||||
def onchange_uom_id(self):
|
||||
self.uom_id = self.product_id.uom_id.id
|
||||
|
||||
@api.constrains('product_id', 'uom_id')
|
||||
def check_uom_id(self):
|
||||
if self.uom_id.category_id != self.product_id.uom_id.category_id:
|
||||
raise ValidationError(_(
|
||||
"The unit of measure for the limit with the product %s must "
|
||||
"be in the uom category %s!") %
|
||||
(self.product_id.name,
|
||||
self.product_id.uom_id.category_id.name))
|
||||
|
||||
_sql_constraints = [
|
||||
('product_uniq', 'unique(product_id,location_id)',
|
||||
'You cannot set 2 limits with the same product for a location!')]
|
||||
@@ -31,5 +17,6 @@ class StockLocationLimit(models.Model):
|
||||
product_id = fields.Many2one('product.product', string='Product')
|
||||
qty = fields.Float('Maximum Quantity',
|
||||
digits=dp.get_precision('Product Quantity'))
|
||||
uom_id = fields.Many2one('uom.uom', string='UoM')
|
||||
uom_id = fields.Many2one(
|
||||
'uom.uom', related='product_id.uom_id', string='UoM', store=True)
|
||||
location_id = fields.Many2one('stock.location', string='Location')
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# Copyright (C) 2019 Open Source Integrators
|
||||
# Copyright (C) 2019 Serpent Consulting Services Pvt. Ltd.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
@@ -31,24 +30,16 @@ class TestStockLocationLimitProduct(TransactionCase):
|
||||
'usage': 'internal',
|
||||
})
|
||||
|
||||
def test_onchange_uom_id(self):
|
||||
limit = self.limit_obj
|
||||
with self.assertRaises(ValidationError):
|
||||
# constrain is called when create a record.
|
||||
limit = self.limit_obj.create({
|
||||
'location_id': self.location.id,
|
||||
'product_id': self.product.id,
|
||||
'qty': 100,
|
||||
})
|
||||
if not limit:
|
||||
limit = self.limit_obj.create({
|
||||
'location_id': self.location.id,
|
||||
'product_id': self.product2.id,
|
||||
'qty': 100,
|
||||
'uom_id': self.uom.id,
|
||||
})
|
||||
limit.onchange_uom_id()
|
||||
limit.check_uom_id()
|
||||
limit_count = len(self.limit_obj.search([]))
|
||||
self.assertEqual(limit_count, 2)
|
||||
self.assertEqual(limit.uom_id.id, self.uom.id)
|
||||
def test_creating_stock_location_limit(self):
|
||||
self.limit_obj.create({
|
||||
'location_id': self.location.id,
|
||||
'product_id': self.product.id,
|
||||
'qty': 100,
|
||||
})
|
||||
self.limit_obj.create({
|
||||
'location_id': self.location.id,
|
||||
'product_id': self.product2.id,
|
||||
'qty': 100,
|
||||
})
|
||||
limit_count = len(self.limit_obj.search([]))
|
||||
self.assertEqual(limit_count, 2)
|
||||
|
||||
Reference in New Issue
Block a user