summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorSimon Lejeune <sle@openerp.com>2020-01-17 12:19:15 +0000
committerRémy Voet (ryv) <ryv@odoo.com>2020-01-20 14:01:21 +0000
commitb9334c53b84228c00ab100ffd28620b3c923c4e6 (patch)
tree68dc96e5b5b854d18606fc9d5e746aa1b8aa731a /addons
parent177a479cf66ecab017fadf2034fc52501643ee41 (diff)
[REF] stock: move line: some guidelines
- move all the constrains at the same place, make sure they are private - move all the onchanges at the same place, make sure they are private - move `_get_similar_move_lines` helper at the bottom of the file with the other helpers
Diffstat (limited to 'addons')
-rw-r--r--addons/product_expiry/models/stock_move_line.py4
-rw-r--r--addons/stock/models/stock_move_line.py44
2 files changed, 24 insertions, 24 deletions
diff --git a/addons/product_expiry/models/stock_move_line.py b/addons/product_expiry/models/stock_move_line.py
index db8956563d2..49e9a6fc180 100644
--- a/addons/product_expiry/models/stock_move_line.py
+++ b/addons/product_expiry/models/stock_move_line.py
@@ -14,8 +14,8 @@ class StockMoveLine(models.Model):
' become dangerous and must not be consumed.')
@api.onchange('product_id', 'product_uom_id')
- def onchange_product_id(self):
- res = super(StockMoveLine, self).onchange_product_id()
+ def _onchange_product_id(self):
+ res = super(StockMoveLine, self)._onchange_product_id()
if self.picking_type_use_create_lots:
if self.product_id.use_expiration_date:
self.expiration_date = fields.Datetime.today() + datetime.timedelta(days=self.product_id.expiration_time)
diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py
index bdf659dc6b8..42a65359c10 100644
--- a/addons/stock/models/stock_move_line.py
+++ b/addons/stock/models/stock_move_line.py
@@ -81,12 +81,6 @@ class StockMoveLine(models.Model):
for line in self:
line.product_qty = line.product_uom_id._compute_quantity(line.product_uom_qty, line.product_id.uom_id, rounding_method='HALF-UP')
- @api.constrains('lot_id', 'product_id')
- def _check_lot_product(self):
- for line in self:
- if line.lot_id and line.product_id != line.lot_id.sudo().product_id:
- raise ValidationError(_('This lot %s is incompatible with this product %s' % (line.lot_id.name, line.product_id.display_name)))
-
def _set_product_qty(self):
""" The meaning of product_qty field changed lately and is now a functional field computing the quantity
in the default product UoM. This code has been added to raise an error if a write is made given a value
@@ -94,14 +88,25 @@ class StockMoveLine(models.Model):
detect errors. """
raise UserError(_('The requested operation cannot be processed because of a programming error setting the `product_qty` field instead of the `product_uom_qty`.'))
+ @api.constrains('lot_id', 'product_id')
+ def _check_lot_product(self):
+ for line in self:
+ if line.lot_id and line.product_id != line.lot_id.sudo().product_id:
+ raise ValidationError(_('This lot %s is incompatible with this product %s' % (line.lot_id.name, line.product_id.display_name)))
+
@api.constrains('product_uom_qty')
- def check_reserved_done_quantity(self):
+ def _check_reserved_done_quantity(self):
for move_line in self:
if move_line.state == 'done' and not float_is_zero(move_line.product_uom_qty, precision_digits=self.env['decimal.precision'].precision_get('Product Unit of Measure')):
raise ValidationError(_('A done move line should never have a reserved quantity.'))
+ @api.constrains('qty_done')
+ def _check_positive_qty_done(self):
+ if any([ml.qty_done < 0 for ml in self]):
+ raise ValidationError(_('You can not enter negative quantities.'))
+
@api.onchange('product_id', 'product_uom_id')
- def onchange_product_id(self):
+ def _onchange_product_id(self):
if self.product_id:
if not self.id and self.user_has_groups('stock.group_stock_multi_locations'):
self.location_dest_id = self.location_dest_id._get_putaway_strategy(self.product_id) or self.location_dest_id
@@ -115,7 +120,7 @@ class StockMoveLine(models.Model):
self.product_uom_id = self.product_id.uom_id.id
@api.onchange('lot_name', 'lot_id')
- def onchange_serial_number(self):
+ def _onchange_serial_number(self):
""" When the user is encoding a move line for a tracked product, we apply some logic to
help him. This includes:
- automatically switch `qty_done` to 1.0
@@ -154,19 +159,6 @@ class StockMoveLine(models.Model):
res['warning'] = {'title': _('Warning'), 'message': message}
return res
- @api.constrains('qty_done')
- def _check_positive_qty_done(self):
- if any([ml.qty_done < 0 for ml in self]):
- raise ValidationError(_('You can not enter negative quantities.'))
-
- def _get_similar_move_lines(self):
- self.ensure_one()
- lines = self.env['stock.move.line']
- picking_id = self.move_id.picking_id if self.move_id else self.picking_id
- if picking_id:
- lines |= picking_id.move_line_ids.filtered(lambda ml: ml.product_id == self.product_id and (ml.lot_id or ml.lot_name))
- return lines
-
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
@@ -472,6 +464,14 @@ class StockMoveLine(models.Model):
'date': fields.Datetime.now(),
})
+ def _get_similar_move_lines(self):
+ self.ensure_one()
+ lines = self.env['stock.move.line']
+ picking_id = self.move_id.picking_id if self.move_id else self.picking_id
+ if picking_id:
+ lines |= picking_id.move_line_ids.filtered(lambda ml: ml.product_id == self.product_id and (ml.lot_id or ml.lot_name))
+ return lines
+
def _create_and_assign_production_lot(self):
""" Creates and assign a new production lot of the move line."""
self.ensure_one()