diff --git a/rma_repair/i18n/es.po b/rma_repair/i18n/es.po index 287264306..27f631fa5 100644 --- a/rma_repair/i18n/es.po +++ b/rma_repair/i18n/es.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-05-28 13:23+0000\n" -"PO-Revision-Date: 2024-05-28 13:23+0000\n" +"POT-Creation-Date: 2024-06-04 14:06+0000\n" +"PO-Revision-Date: 2024-06-04 14:06+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -15,6 +15,16 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: rma_repair +#: model:ir.model.fields.selection,name:rma_repair.selection__rma_repair_line_wizard__invoice_method__after_repair +msgid "After Repair" +msgstr "Después de Reparar" + +#. module: rma_repair +#: model:ir.model.fields.selection,name:rma_repair.selection__rma_repair_line_wizard__invoice_method__b4repair +msgid "Before Repair" +msgstr "Antes de Reparar" + #. module: rma_repair #: model:ir.model.fields,field_description:rma_repair.field_rma__can_create_repair_order msgid "Can Create Repair Order" @@ -43,11 +53,13 @@ msgid "Create Repair Orders and Block RMA" msgstr "Crear órdenes de reparación y bloquear RMA" #. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__create_uid #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__create_uid msgid "Created by" msgstr "Creado por" #. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__create_date #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__create_date msgid "Created on" msgstr "Creado el" @@ -55,6 +67,7 @@ msgstr "Creado el" #. module: rma_repair #: model:ir.model.fields,field_description:rma_repair.field_repair_order__display_name #: model:ir.model.fields,field_description:rma_repair.field_rma__display_name +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__display_name #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__display_name msgid "Display Name" msgstr "Nombre mostrado" @@ -64,34 +77,53 @@ msgstr "Nombre mostrado" msgid "Has Lots" msgstr "Tiene lotes" +#. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__invoice_method +msgid "Invoice Method" +msgstr "Método de Facturación" + #. module: rma_repair #: model:ir.model.fields,field_description:rma_repair.field_repair_order____last_update #: model:ir.model.fields,field_description:rma_repair.field_rma____last_update +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard____last_update #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard____last_update msgid "Last Modified on" msgstr "Última modificación el" #. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__write_uid #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__write_uid msgid "Last Updated by" msgstr "Última actualización por" #. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__write_date #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__write_date msgid "Last Updated on" msgstr "Última actualización el" #. module: rma_repair -#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__lot_ids +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__line_ids +msgid "Line" +msgstr "Línea" + +#. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__lot_ids msgid "Lot" msgstr "Lote" +#. module: rma_repair +#: model:ir.model.fields.selection,name:rma_repair.selection__rma_repair_line_wizard__invoice_method__none +msgid "No Invoice" +msgstr "Sin factura" + #. module: rma_repair #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__partner_id msgid "Partner" msgstr "Cliente" #. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__product_id #: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__product_id msgid "Product" msgstr "Producto" @@ -108,10 +140,15 @@ msgid "Quantity must be positive." msgstr "La cantidad debe ser positiva." #. module: rma_repair -#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_wizard__product_qty +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__product_qty msgid "Quantity to repair" msgstr "Cantidad a reparar" +#. module: rma_repair +#: model:ir.model,name:rma_repair.model_rma_repair_line_wizard +msgid "RMA Repair Line Wizard" +msgstr "RMA Asistente de Línea de Reparación" + #. module: rma_repair #: model:ir.model,name:rma_repair.model_rma_repair_wizard msgid "RMA Repair Wizard" @@ -135,6 +172,18 @@ msgstr "Orden de reparación" msgid "Repair Orders" msgstr "Órdenes de reparación" +#. module: rma_repair +#: model:ir.model.fields,help:rma_repair.field_rma_repair_line_wizard__invoice_method +msgid "" +"Selecting 'Before Repair' or 'After Repair' will allow you to generate " +"invoice before or after the repair is done respectively. 'No invoice' means " +"you don't want to generate invoice for this repair order." +msgstr "" +"Seleccionando 'Antes de reparar' o 'Después de reparar' permitirá generar " +"las facturas antes o después de que se realice la reparación " +"respectivamente. 'Sin factura' significa que no quiere generar factura para " +"esta orden de reparación." + #. module: rma_repair #: code:addons/rma_repair/wizards/rma_repair_wizard.py:0 #, python-format @@ -149,6 +198,11 @@ msgid "" msgstr "" "La cantidad total a reparar debe ser menor o igual a la cantidad de RMA." +#. module: rma_repair +#: model:ir.model.fields,field_description:rma_repair.field_rma_repair_line_wizard__wizard_id +msgid "Wizard" +msgstr "Asistente" + #. module: rma_repair #: code:addons/rma_repair/wizards/rma_repair_wizard.py:0 #, python-format diff --git a/rma_repair/security/ir.model.access.csv b/rma_repair/security/ir.model.access.csv index 15039303a..248aed8a8 100644 --- a/rma_repair/security/ir.model.access.csv +++ b/rma_repair/security/ir.model.access.csv @@ -1,3 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_rma_repair_wizard_user,rma.repair.wizard.user,model_rma_repair_wizard,rma.rma_group_user_own,1,0,0,0 access_rma_repair_wizard_manager,rma.repair.wizard.manager,model_rma_repair_wizard,rma.rma_group_manager,1,1,1,1 +access_rma_repair_line_wizard_manager,rma.repair.line.wizard.manager,model_rma_repair_line_wizard,rma.rma_group_manager,1,1,1,1 diff --git a/rma_repair/wizards/rma_repair_wizard.py b/rma_repair/wizards/rma_repair_wizard.py index e1465700c..e1f472c28 100644 --- a/rma_repair/wizards/rma_repair_wizard.py +++ b/rma_repair/wizards/rma_repair_wizard.py @@ -27,26 +27,43 @@ def default_get(self, fields_list): res["product_id"] = rma.product_id.id return res - @api.constrains("lot_ids") - def _check_lot_ids(self): + rma_id = fields.Many2one( + comodel_name="rma", string="RMA", readonly=True, required=True + ) + product_id = fields.Many2one( + comodel_name="product.product", readonly=True, required=True + ) + partner_id = fields.Many2one( + comodel_name="res.partner", readonly=True, required=True + ) + line_ids = fields.One2many( + comodel_name="rma.repair.line.wizard", inverse_name="wizard_id" + ) + has_lots = fields.Boolean(compute="_compute_has_lots") + + @api.depends("rma_id") + def _compute_has_lots(self): + for rec in self: + rec.has_lots = bool( + rec.rma_id.reception_move_id.picking_id.move_line_ids.lot_id + ) + + def _check_repair_order_values(self): for rec in self: dup_lot = rec.rma_id.repair_order_ids.filtered( - lambda x: x.lot_id in rec.lot_ids + lambda x: x.lot_id in rec.line_ids.lot_ids ) if dup_lot: raise ValidationError( _("You already have a repair order for the lot [%s].") % ", ".join(dup_lot.mapped("lot_id.name")) ) - - @api.constrains("product_qty") - def _check_product_qty(self): - for rec in self: if not rec.has_lots: - if rec.product_qty <= 0.0: + if rec.line_ids.filtered(lambda x: x.product_qty <= 0.0): raise ValidationError(_("Quantity must be positive.")) if ( - rec.product_qty + rec.rma_id.product_qty_in_repair + sum(rec.line_ids.mapped("product_qty")) + + rec.rma_id.product_qty_in_repair > rec.rma_id.product_uom_qty ): raise ValidationError( @@ -56,44 +73,18 @@ def _check_product_qty(self): ) ) - rma_id = fields.Many2one( - comodel_name="rma", string="RMA", readonly=True, required=True - ) - product_id = fields.Many2one( - comodel_name="product.product", readonly=True, required=True - ) - product_qty = fields.Float(string="Quantity to repair", digits="Product UoS") - partner_id = fields.Many2one( - comodel_name="res.partner", readonly=True, required=True - ) - lot_ids = fields.Many2many(comodel_name="stock.production.lot") - - @api.onchange("rma_id") - def _onchange_domain_lot_ids(self): - for rec in self: - rma_lots = rec.rma_id.reception_move_id.picking_id.move_line_ids.lot_id - return {"domain": {"lot_ids": [("id", "in", rma_lots.ids)]}} - - has_lots = fields.Boolean(compute="_compute_has_lots") - - @api.depends("rma_id") - def _compute_has_lots(self): - for rec in self: - rec.has_lots = bool( - rec.rma_id.reception_move_id.picking_id.move_line_ids.lot_id - ) - - def _prepare_repair_order(self, lot_id=None): + def _prepare_repair_order(self, line, lot_id=None): self.ensure_one() vals = { "rma_id": self.rma_id.id, "product_id": self.product_id.id, "partner_id": self.partner_id.id, - "product_qty": self.product_qty or 1.0, + "product_qty": line.product_qty or 1.0, "product_uom": self.product_id.uom_id.id, "company_id": self.rma_id.company_id.id, "location_id": self.rma_id.location_id.id, "lot_id": lot_id, + "invoice_method": line.invoice_method, } if self.rma_id.user_id: vals["user_id"] = self.rma_id.user_id.id @@ -101,16 +92,20 @@ def _prepare_repair_order(self, lot_id=None): def action_create_repair_order(self): self.ensure_one() - lot_ids = self.lot_ids or [None] - idx = 0 + self._check_repair_order_values() repairs = [] - while True: - lot_id = lot_ids[idx] - data = self._prepare_repair_order(lot_id=lot_id.id if lot_id else None) - repairs.append(data) - idx += 1 - if idx >= len(lot_ids): - break + for line in self.line_ids: + lot_ids = line.lot_ids or [None] + idx = 0 + while True: + lot_id = lot_ids[idx] + data = self._prepare_repair_order( + line, lot_id=lot_id.id if lot_id else None + ) + repairs.append(data) + idx += 1 + if idx >= len(lot_ids): + break repair_orders = self.env["repair.order"] for data in repairs: repair = self.env["repair.order"].create(data) @@ -128,3 +123,32 @@ def action_create_repair_order_and_block_rma(self): self.ensure_one() self.rma_id.action_lock() return self.action_create_repair_order() + + +class RmaRepairLineWizard(models.TransientModel): + _name = "rma.repair.line.wizard" + _description = "RMA Repair Line Wizard" + + wizard_id = fields.Many2one(comodel_name="rma.repair.wizard", ondelete="cascade") + product_id = fields.Many2one(related="wizard_id.product_id") + product_qty = fields.Float(string="Quantity to repair", digits="Product UoS") + invoice_method = fields.Selection( + [ + ("none", "No Invoice"), + ("b4repair", "Before Repair"), + ("after_repair", "After Repair"), + ], + required=True, + help="Selecting 'Before Repair' or 'After Repair' will allow you to generate " + "invoice before or after the repair is done respectively. 'No invoice' " + "means you don't want to generate invoice for this repair order.", + ) + lot_ids = fields.Many2many(comodel_name="stock.production.lot") + + @api.onchange("product_id") + def _onchange_domain_lot_id(self): + for rec in self: + rma_lots_ids = set( + rec.wizard_id.rma_id.reception_move_id.picking_id.move_line_ids.lot_id.ids + ) - set(rec.wizard_id.line_ids.lot_ids.ids) + return {"domain": {"lot_ids": [("id", "in", list(rma_lots_ids))]}} diff --git a/rma_repair/wizards/rma_repair_wizard_views.xml b/rma_repair/wizards/rma_repair_wizard_views.xml index ea97cb638..3da74cfee 100644 --- a/rma_repair/wizards/rma_repair_wizard_views.xml +++ b/rma_repair/wizards/rma_repair_wizard_views.xml @@ -11,18 +11,24 @@ - - - + + + + + + + +