diff --git a/ext/custom-addons/dp_custom/models/stock.py b/ext/custom-addons/dp_custom/models/stock.py index a34b0a19..ceb356cd 100644 --- a/ext/custom-addons/dp_custom/models/stock.py +++ b/ext/custom-addons/dp_custom/models/stock.py @@ -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) \ No newline at end of file +# 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) diff --git a/ext/custom-addons/tz_reports_production/reports/report_production.xml b/ext/custom-addons/tz_reports_production/reports/report_production.xml index d535a5ac..d6127694 100644 --- a/ext/custom-addons/tz_reports_production/reports/report_production.xml +++ b/ext/custom-addons/tz_reports_production/reports/report_production.xml @@ -129,6 +129,9 @@ Voraussichtliches Lieferdatum: +

+ +

-->