Skip to content

Commit

Permalink
[IMP] rma_repair: manage repair order with invoice method
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 committed Jun 4, 2024
1 parent 371ea06 commit be2f468
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 62 deletions.
62 changes: 58 additions & 4 deletions rma_repair/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@ 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"
"Content-Type: text/plain; charset=UTF-8\n"
"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"
Expand Down Expand Up @@ -43,18 +53,21 @@ 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"

#. 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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rma_repair/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
118 changes: 71 additions & 47 deletions rma_repair/wizards/rma_repair_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -56,61 +73,39 @@ 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
return vals

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)
Expand All @@ -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))]}}
26 changes: 16 additions & 10 deletions rma_repair/wizards/rma_repair_wizard_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
<group>
<field name="rma_id" options="{'no_open': true}" />
<field name="partner_id" />
<field name="product_id" />
<field
name="product_qty"
attrs="{'invisible': [('has_lots', '!=', False)]}"
/>
<field
name="lot_ids"
widget="many2many_tags"
attrs="{'invisible': [('has_lots', '=', False)]}"
/>
<field name="has_lots" invisible="1" />
</group>
<field name="line_ids" nolabel="1">
<tree editable="bottom">
<field name="product_id" />
<field
name="product_qty"
attrs="{'column_invisible': [('parent.has_lots', '=', True)], 'required': [('parent.has_lots', '=', False)]}"
/>
<field
name="lot_ids"
widget="many2many_tags"
attrs="{'column_invisible': [('parent.has_lots', '=', False)], 'required': [('parent.has_lots', '=', True)]}"
options="{'no_create_edit': True, 'no_quick_create': True}"
/>
<field name="invoice_method" />
</tree>
</field>
<newline />
<footer>
<button
Expand Down

0 comments on commit be2f468

Please sign in to comment.