extended warning when lot already has been used.

(sequence in stock.move derived from sale_order_line)
develop
Andreas Osim 2018-10-30 14:52:29 +01:00
parent eefe70e33e
commit 73dd7ec7c3
2 changed files with 33 additions and 3 deletions

View File

@ -19,7 +19,9 @@
#
##############################################################################
from odoo import fields, models, api, tools
from odoo import fields, models, api, tools, _
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare, float_is_zero
class StockProductionLot(models.Model):
@ -61,18 +63,26 @@ class StockPicking(models.Model):
res = lang_obj.format('%.' + str(2) + 'f', value, grouping=True, monetary=True)
return res
class StockMove(models.Model):
_inherit = "stock.move"
manu_lots_visible = fields.Boolean(compute='_compute_manu_lots_visible')
@api.model
def create(self, vals):
res = super(StockMove, self).create(vals)
for move in res:
move.update({'sequence': move.sale_line_id.sequence,})
return res
@api.multi
def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
self.ensure_one()
vals = super(StockMove, self)._prepare_move_line_vals(quantity=quantity, reserved_quant=reserved_quant)
if self.sale_line_id.lot_id and not self.sale_line_id.product_id.can_be_sold_unconfigured:
move_lot = self.sale_line_id.lot_id.id
vals.update({'lot_id': move_lot, })
vals.update({'lot_id': move_lot,})
return vals
def _compute_manu_lots_visible(self):
@ -98,4 +108,21 @@ class StockMove(models.Model):
else:
move.weight += (move.product_qty * move.product_id.weight)
# print(move.weight)
# print(move.weight)
class StockQuant(models.Model):
_inherit = "stock.quant"
@api.constrains('quantity')
def check_quantity(self):
info = ''
for quant in self:
if float_compare(quant.quantity, 1, precision_rounding=quant.product_uom_id.rounding) > 0 and quant.lot_id and quant.product_id.tracking == 'serial':
smls = self.env['stock.move.line'].search([('lot_id', '=', quant.lot_id.id)])
for sml in smls:
sm = self.env['stock.move'].search([('id', '=', sml.move_id.id)])
info += '\n %s; %s; %s: %s' % (sm.origin,sm.reference,sm.sequence,quant.lot_id.name)
if info:
raise ValidationError(_('A serial number should only be linked to a single product.') + info)

View File

@ -129,6 +129,9 @@
<strong>Voraussichtliches Lieferdatum:</strong>
<span t-field="order_line.delivery_date"/>
</t>
<p t-if="order_line.lot_id">
<span t-esc="order_line.lot_id.name.split('.')[2]"/>
</p>
-->
<p t-if="order_line.lot_id.notes">
<span t-field="order_line.lot_id.notes"/>