Skip to content

Commit

Permalink
[IMP] stock_no_negative: Behave correctly on other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow authored and pedrobaeza committed Dec 14, 2017
1 parent 3c6fdd7 commit 77c4682
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion stock_no_negative/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
'name': 'Stock Disallow Negative',
'version': '10.0.1.0.2',
'version': '10.0.1.0.0',
'category': 'Inventory, Logistic, Storage',
'license': 'AGPL-3',
'summary': 'Disallow negative stock levels by default',
Expand Down
11 changes: 8 additions & 3 deletions stock_no_negative/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from odoo import models, api, _
from odoo.exceptions import ValidationError
from odoo.tools import float_compare
from odoo.tools import config, float_compare


class StockQuant(models.Model):
Expand All @@ -16,9 +16,14 @@ class StockQuant(models.Model):
def check_negative_qty(self):
p = self.env['decimal.precision'].precision_get(
'Product Unit of Measure')
check_negative_qty = (
config['test_enable'] and self.env.context.get(
'test_stock_no_negative')) or (
'test_enable' not in config.options)
if not check_negative_qty:
return
for quant in self:
if (
float_compare(quant.qty, 0, precision_digits=p) == -1 and
if (float_compare(quant.qty, 0, precision_digits=p) == -1 and
quant.product_id.type == 'product' and
not quant.product_id.allow_negative_stock and
not quant.product_id.categ_id.allow_negative_stock):
Expand Down
6 changes: 4 additions & 2 deletions stock_no_negative/tests/test_stock_no_negative.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def test_check_constrains(self):
self.stock_immediate_transfer = self.env['stock.immediate.transfer'].\
create({'pick_id': self.stock_picking.id})
with self.assertRaises(ValidationError):
self.stock_immediate_transfer.process()
self.stock_immediate_transfer.with_context(
test_stock_no_negative=True).process()

def test_true_allow_negative_stock(self):
"""Assert that negative stock levels are allowed when
Expand All @@ -82,7 +83,8 @@ def test_true_allow_negative_stock(self):
self.stock_picking.do_new_transfer()
self.stock_immediate_transfer = self.env['stock.immediate.transfer'].\
create({'pick_id': self.stock_picking.id})
self.stock_immediate_transfer.process()
self.stock_immediate_transfer.with_context(
test_stock_no_negative=True).process()
quant = self.env['stock.quant'].search([('product_id', '=',
self.product.id),
('location_id', '=',
Expand Down

0 comments on commit 77c4682

Please sign in to comment.