diff --git a/stock_ux/__manifest__.py b/stock_ux/__manifest__.py index 2483534c7..cb50a8a5d 100644 --- a/stock_ux/__manifest__.py +++ b/stock_ux/__manifest__.py @@ -19,7 +19,7 @@ ############################################################################## { "name": "Stock UX", - "version": "19.0.1.1.0", + "version": "19.0.2.0.0", "category": "Warehouse Management", "sequence": 14, "summary": "", @@ -45,6 +45,7 @@ "views/report_deliveryslip.xml", "views/res_config_settings_views.xml", "wizards/stock_operation_wizard_views.xml", + "wizards/stock_return_picking_views.xml", "report/ir.action.reports.xml", "report/picking_templates.xml", "views/res_company_views.xml", diff --git a/stock_ux/models/stock_move.py b/stock_ux/models/stock_move.py index c7210c662..3fc0c3bf2 100644 --- a/stock_ux/models/stock_move.py +++ b/stock_ux/models/stock_move.py @@ -25,14 +25,19 @@ class StockMove(models.Model): lots_visible = fields.Boolean( related="move_line_ids.lots_visible", ) - picking_partner_id = fields.Many2one( "res.partner", "Transfer Destination Address", related="picking_id.partner_id", ) - origin_description = fields.Char(compute="_compute_origin_description", compute_sudo=True) + is_exchange_move = fields.Boolean() + + @api.model + def _prepare_merge_moves_distinct_fields(self): + fields = super()._prepare_merge_moves_distinct_fields() + fields.append("is_exchange_move") + return fields @api.depends( "move_line_ids.quantity", diff --git a/stock_ux/models/stock_rule.py b/stock_ux/models/stock_rule.py index 990c2b83b..4cce41f41 100644 --- a/stock_ux/models/stock_rule.py +++ b/stock_ux/models/stock_rule.py @@ -15,3 +15,13 @@ def _compute_propagate_carrier(self): """Make True by default if picking code is outgoing""" for rec in self: rec.propagate_carrier = rec.picking_type_id.code == "outgoing" + + def _get_stock_move_values( + self, product_id, product_qty, product_uom, location_dest_id, name, origin, company_id, values + ): + move_values = super()._get_stock_move_values( + product_id, product_qty, product_uom, location_dest_id, name, origin, company_id, values + ) + if self.env.context.get("is_exchange_move"): + move_values["is_exchange_move"] = True + return move_values diff --git a/stock_ux/wizards/__init__.py b/stock_ux/wizards/__init__.py index 101a950c4..55a30e0bb 100644 --- a/stock_ux/wizards/__init__.py +++ b/stock_ux/wizards/__init__.py @@ -4,3 +4,4 @@ ############################################################################## from . import stock_operation_wizard from . import stock_label_type +from . import stock_return_picking diff --git a/stock_ux/wizards/stock_return_picking.py b/stock_ux/wizards/stock_return_picking.py new file mode 100644 index 000000000..34f080e93 --- /dev/null +++ b/stock_ux/wizards/stock_return_picking.py @@ -0,0 +1,45 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo import _, api, models +from odoo.exceptions import UserError + + +class StockReturnPicking(models.TransientModel): + _inherit = "stock.return.picking" + + @api.model + def default_get(self, fields): + """Get sale order for lines.""" + result = super().default_get(fields) + try: + for line in result["product_return_moves"]: + assert line[0] == 0 + # en realidad no nos importa si hay linea de venta o no ya que + # también lo usamos en compras y queremos que en todo caso este + line[2]["to_refund"] = True + except KeyError: + pass + return result + + def action_create_exchanges(self): + if any(self.product_return_moves.mapped("to_refund")): + raise UserError(_("You cannot create exchanges for return lines marked to refund.")) + return super(StockReturnPicking, self.with_context(is_exchange_move=True)).action_create_exchanges() + + +class StockReturnPickingLine(models.TransientModel): + _inherit = "stock.return.picking.line" + + def _prepare_move_default_values(self, new_picking): + vals = super()._prepare_move_default_values(new_picking) + if self.env.context.get("is_exchange_move"): + vals["is_exchange_move"] = True + return vals + + def _prepare_picking_default_values_based_on(self, picking): + vals = super()._prepare_picking_default_values_based_on(picking) + if self.env.context.get("is_exchange_move"): + vals["is_exchange_move"] = True + return vals diff --git a/stock_ux/wizards/stock_return_picking_views.xml b/stock_ux/wizards/stock_return_picking_views.xml new file mode 100644 index 000000000..b8bd6840e --- /dev/null +++ b/stock_ux/wizards/stock_return_picking_views.xml @@ -0,0 +1,33 @@ + + + + Improve refunds wizard + + stock.return.picking + + + + + + + + + + + Para Abonar (actualizar OC/OV) + + + + +