diff --git a/stock_batch_picking_ux/__manifest__.py b/stock_batch_picking_ux/__manifest__.py index bd5f4f500..d3f934834 100644 --- a/stock_batch_picking_ux/__manifest__.py +++ b/stock_batch_picking_ux/__manifest__.py @@ -18,8 +18,8 @@ # ############################################################################## { - "name": "Stock Usability with Batch Picking and stock vouchers", - "version": "18.0.1.1.0", + "name": "Stock Usability with Batch Picking", + "version": "19.0.1.0.0", "category": "Warehouse Management", "sequence": 14, "summary": "", @@ -29,18 +29,16 @@ "images": [], "depends": [ "stock_ux", - "stock_voucher", "stock_picking_batch", ], "data": [ "views/stock_batch_picking_views.xml", "views/stock_move_line_views.xml", - "views/stock_picking_views.xml", "reports/ir.actions.report.xml", "reports/picking_templates.xml", ], "demo": [], - "installable": False, + "installable": True, "auto_install": True, "application": False, } diff --git a/stock_batch_picking_ux/models/__init__.py b/stock_batch_picking_ux/models/__init__.py index 25800d491..6ed745539 100644 --- a/stock_batch_picking_ux/models/__init__.py +++ b/stock_batch_picking_ux/models/__init__.py @@ -3,6 +3,3 @@ # directory ############################################################################## from . import stock_batch_picking -from . import stock_move_line -from . import stock_picking_voucher -from . import stock_picking diff --git a/stock_batch_picking_ux/models/stock_batch_picking.py b/stock_batch_picking_ux/models/stock_batch_picking.py index 6ffa43939..769b6c420 100644 --- a/stock_batch_picking_ux/models/stock_batch_picking.py +++ b/stock_batch_picking_ux/models/stock_batch_picking.py @@ -18,34 +18,22 @@ class StockPickingBatch(models.Model): # required=True, help="If you choose a partner then only pickings of this partner will" "be sellectable", ) - voucher_number = fields.Char() - voucher_required = fields.Boolean( - # related='picking_type_id.voucher_required', - compute="_compute_picking_type_data", - ) - restrict_number_package = fields.Boolean( - compute="_compute_picking_type_data", - ) - number_of_packages = fields.Integer( - copy=False, - ) - + # restrict_number_package = fields.Boolean( + # compute="_compute_picking_type_data", + # ) + # number_of_packages = fields.Integer( + # copy=False, + # ) picking_type_id = fields.Many2one(required=True) - picking_type_ids = fields.Many2many( "stock.picking.type", # related='picking_type_id.voucher_required', compute="_compute_picking_type_data", ) - vouchers = fields.Char( - related="picking_ids.vouchers", - ) - picking_count = fields.Integer( string="# Transferencias", compute="_compute_picking_count", ) - notes = fields.Text(help="free form remarks") def _compute_picking_count(self): @@ -59,40 +47,43 @@ def _compute_picking_count(self): for batch in self: batch.picking_count = counts.get(batch.id, 0) + @api.depends("partner_id") + def _compute_allowed_picking_ids(self): + super()._compute_allowed_picking_ids() + for rec in self.filtered("partner_id"): + rec.allowed_picking_ids = rec.allowed_picking_ids.filtered(lambda p: p.partner_id == rec.partner_id) + + def write(self, vals): + # Interceptamos las operaciones de picking_ids para evitar que se borren físicamente + # En lugar de comando 2 (delete), usamos comando 3 (unlink) que solo desvincula + if "picking_ids" in vals: + new_picking_ops = [] + for operation in vals["picking_ids"]: + if operation[0] == 2: # Si es un delete (2), lo convertimos a unlink (3) + new_picking_ops.append((3, operation[1])) # Unlink en lugar de delete + else: + new_picking_ops.append(operation) + vals["picking_ids"] = new_picking_ops + return super().write(vals) + @api.depends("picking_ids") def _compute_picking_type_data(self): for rec in self: types = rec.picking_ids.mapped("picking_type_id") rec.picking_type_ids = types - rec.voucher_required = any(x.voucher_required for x in types) - rec.restrict_number_package = False + # rec.voucher_required = any(x.voucher_required for x in types) + # rec.restrict_number_package = False # este viene exigido desde la cia pero seguramente lo movamos a # exigir desde picking type # solo es requerido para outgoings - if rec.picking_type_code == "outgoing": - rec.restrict_number_package = any(x.picking_type_id.restrict_number_package for x in rec.picking_ids) + # if rec.picking_type_code == "outgoing": + # rec.restrict_number_package = any(x.picking_type_id.restrict_number_package for x in rec.picking_ids) @api.onchange("picking_type_code", "partner_id") def changes_set_pickings(self): # if we change type or partner reset pickings self.picking_ids = False - @api.onchange("voucher_number", "picking_ids") - def format_voucher_number(self): - for rec in self: - if not rec.voucher_number: - continue - voucher_number = self.env["stock.picking.voucher"]._format_document_number(rec.voucher_number) - if voucher_number and voucher_number != rec.voucher_number: - rec.voucher_number = voucher_number - - def write(self, vals): - if "voucher_number" in vals and vals.get("voucher_number"): - voucher_number = self.env["stock.picking.voucher"]._format_document_number(vals.get("voucher_number")) - if voucher_number and voucher_number != vals.get("voucher_number"): - vals["voucher_number"] = voucher_number - return super().write(vals) - def add_picking_operation(self): self.ensure_one() view_id = self.env.ref("stock_ux.view_move_line_tree").id @@ -112,28 +103,14 @@ def action_done(self): # al agregar la restriccion de que al menos una tenga que tener # cantidad entonces nunca se manda el force_qty al picking if all(operation.quantity == 0 for operation in rec.move_line_ids): - raise UserError(_("Debe definir Cantidad Realizada en al menos una " "operación.")) + raise UserError(_("Debe definir Cantidad Realizada en al menos una operación.")) - if rec.restrict_number_package and not rec.number_of_packages > 0: - raise UserError(_("The number of packages can not be 0")) - if rec.number_of_packages: - rec.picking_ids.write({"number_of_packages": rec.number_of_packages}) + # if rec.restrict_number_package and not rec.number_of_packages > 0: + # raise UserError(_("The number of packages can not be 0")) + # if rec.number_of_packages: + # rec.picking_ids.write({"number_of_packages": rec.number_of_packages}) - if rec.picking_type_code == "incoming" and rec.voucher_number: - for picking in rec.picking_ids: - # agregamos esto para que no se asigne a los pickings - # que no se van a recibir ya que todavia no se limpiaron - # y ademas, por lo de arriba, no se fuerza la cantidad - # si son todos cero, se terminan sacando - if all(operation.quantity == 0 for operation in picking.move_line_ids): - continue - rec.env["stock.picking.voucher"].create( - { - "picking_id": picking.id, - "name": rec.voucher_number, - } - ) - return super(StockPickingBatch, self.with_context(do_not_assign_numbers=True)).action_done() + return super().action_done() def action_view_stock_picking(self): """This function returns an action that display existing pickings of diff --git a/stock_batch_picking_ux/models/stock_move_line.py b/stock_batch_picking_ux/models/stock_move_line.py deleted file mode 100644 index ca978061e..000000000 --- a/stock_batch_picking_ux/models/stock_move_line.py +++ /dev/null @@ -1,15 +0,0 @@ -############################################################################## -# For copyright and license notices, see __manifest__.py file in module root -# directory -############################################################################## -from odoo import fields, models - - -class StockMoveLine(models.Model): - _inherit = "stock.move.line" - - origin = fields.Char( - related="move_id.picking_id.origin", - # we store so we can group - store=True, - ) diff --git a/stock_batch_picking_ux/models/stock_picking.py b/stock_batch_picking_ux/models/stock_picking.py deleted file mode 100644 index 762dccb7a..000000000 --- a/stock_batch_picking_ux/models/stock_picking.py +++ /dev/null @@ -1,58 +0,0 @@ -# @2016 Cyril Gaudin, Camptocamp SA -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import models -from odoo.tools import float_is_zero - - -class StockPicking(models.Model): - _inherit = "stock.picking" - - # sobreescribimos esta funcion por el FIX, deberia ir a la oca una vez - # depurado - def force_transfer(self, force_qty=True): - """Do the picking transfer (by calling do_transfer) - - If *force_qty* is True, force the transfer for all product_qty - when quantity is 0. - - Otherwise, process only pack operation with quantity. - If a picking has no quantity filled, we released it from his batch - """ - for pick in self: - if pick.state != "assigned": - pick.action_assign() - # FIX - # fix porque si el picking esta parcialmente disponible - # no lo termina procesando - # if pick.state != 'assigned': - if pick.state not in ["assigned", "partially_available"]: - continue - # END FIX - - if force_qty: - for pack in pick.move_line_ids: - pack.quantity = pack.quantity - else: - if all( - float_is_zero(pack.quantity, precision_rounding=pack.product_uom_id.rounding) - for pack in pick.move_line_ids - ): - # No qties to process, release out of the batch - pick.batch_id = False - continue - else: - for pack in pick.move_line_ids: - if not pack.quantity: - pack.unlink() - - pick._action_done() - - def _action_generate_backorder_wizard(self, show_transfers=False): - if self._context.get("picking_batches", False): - wiz = self.env["stock.backorder.confirmation"].create({"pick_ids": [(4, p.id) for p in self]}) - wiz.process() - self._context.get("picking_batches").write({"state": "done"}) - return True - else: - return super(StockPicking, self)._action_generate_backorder_wizard(show_transfers=show_transfers) diff --git a/stock_batch_picking_ux/models/stock_picking_voucher.py b/stock_batch_picking_ux/models/stock_picking_voucher.py deleted file mode 100644 index 995f94446..000000000 --- a/stock_batch_picking_ux/models/stock_picking_voucher.py +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################## -# For copyright and license notices, see __manifest__.py file in module root -# directory -############################################################################## -from odoo import _, models -from odoo.exceptions import ValidationError - - -class StockPickingVoucher(models.Model): - _inherit = "stock.picking.voucher" - - def _check_voucher_number_unique(self): - """ - We modify it to make it unique per batch (if available) or per - pikcing - """ - self.ensure_one() - if self.picking_id.batch_id: - same_number_recs = self.search( - [ - ("picking_id.partner_id", "=", self.picking_id.partner_id.id), - ("name", "=", self.name), - ("picking_id.batch_id", "!=", self.picking_id.batch_id.id), - ("id", "!=", self.id), - ] - ) - if same_number_recs: - raise ValidationError(_("Picking voucher number must be unique per " "partner")) - - else: - return super()._check_voucher_number_unique() diff --git a/stock_batch_picking_ux/views/stock_batch_picking_views.xml b/stock_batch_picking_ux/views/stock_batch_picking_views.xml index 00d5d516a..26aa3e14e 100644 --- a/stock_batch_picking_ux/views/stock_batch_picking_views.xml +++ b/stock_batch_picking_ux/views/stock_batch_picking_views.xml @@ -52,26 +52,12 @@ - - - - - - - - - - - - - - {'show_print_button': 1} - [('company_id', '=', company_id), ('state', 'in', ('confirmed', 'partially_available', 'assigned')), ('picking_type_id', '=', picking_type_id)] if not partner_id else [('company_id', '=', company_id), ('state', 'in', ('confirmed', 'partially_available', 'assigned')), ('picking_type_id', '=', picking_type_id), ('partner_id', '=', partner_id)] - - - - {'from_batch': True} - + + + + + + diff --git a/stock_batch_picking_ux/views/stock_picking_views.xml b/stock_batch_picking_ux/views/stock_picking_views.xml deleted file mode 100644 index fea5c5a62..000000000 --- a/stock_batch_picking_ux/views/stock_picking_views.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - stock.picking.list - stock.picking - - - - - - - - - - - - - - - - - - - - - - - - stock.picking.batch.form - stock.picking.batch - - - - - - - - - - stock.picking.list.inherited - stock.picking - - 99 - - - - - - - - - stock.picking.list.inherited2 - stock.picking - - 99 - - - - - - - - - - diff --git a/stock_batch_picking_voucher/views/stock_picking_views.xml b/stock_batch_picking_voucher/views/stock_picking_views.xml deleted file mode 100644 index 0e8eabca8..000000000 --- a/stock_batch_picking_voucher/views/stock_picking_views.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - stock.picking.form.exception - stock.picking - 99 - - - - - - - - - - - - - - - - - - stock.picking.list.inherit - stock.picking - - - - - - - diff --git a/stock_ux/models/stock_picking.py b/stock_ux/models/stock_picking.py index 885da80c3..56ad07ebe 100644 --- a/stock_ux/models/stock_picking.py +++ b/stock_ux/models/stock_picking.py @@ -23,7 +23,8 @@ class StockPicking(models.Model): copy=False, ) - def unlink(self): + @api.ondelete(at_uninstall=False) + def _check_block_picking_deletion(self): """ To avoid errors we block deletion of pickings in other state than draft or cancel @@ -41,7 +42,6 @@ def unlink(self): ) % (",".join(not_del_pickings.mapped("picking_type_id.name")), not_del_pickings.ids) ) - return super().unlink() def copy(self, default=None): for picking in self: