Skip to content

Commit

Permalink
[MIG] rma_repair: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminSForgeFlow committed Jan 8, 2025
1 parent a6d45e6 commit d1802c3
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 131 deletions.
2 changes: 1 addition & 1 deletion rma_repair/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "RMA Repair",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"category": "RMA",
"summary": "Links RMA with Repairs.",
Expand Down
4 changes: 2 additions & 2 deletions rma_repair/data/repair_sequence.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">

<record id="repair.seq_repair" model="ir.sequence">
<!-- <record id="repair.seq_repair" model="ir.sequence">
<field name="prefix">RO</field>
</record>
</record> -->

</odoo>
3 changes: 0 additions & 3 deletions rma_repair/models/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ class RepairOrder(models.Model):
under_warranty = fields.Boolean(
related="rma_line_id.under_warranty",
)
payment_state = fields.Selection(
related="invoice_id.payment_state", string="Payment Status"
)
11 changes: 0 additions & 11 deletions rma_repair/models/rma_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ class RmaOperation(models.Model):
comodel_name="stock.location",
help="Indicate here the source location of the product to be repaired",
)
repair_invoice_method = fields.Selection(
selection=[
("none", "No Invoice"),
("b4repair", "Before Repair"),
("after_repair", "After Repair"),
],
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.",
)
repair_route_id = fields.Many2one(
comodel_name="stock.route",
string="Repair Route",
Expand Down
40 changes: 3 additions & 37 deletions rma_repair/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def _compute_repair_transfer_count(self):
inverse_name="rma_line_id",
string="Repair Orders",
readonly=True,
states={"draft": [("readonly", False)]},
copy=False,
)
qty_to_repair = fields.Float(
Expand Down Expand Up @@ -95,36 +94,6 @@ def _compute_repair_transfer_count(self):
selection_add=[("repair", "Based on Repair Quantities")],
ondelete={"repair": lambda recs: recs.write({"delivery_policy": "no"})},
)
qty_to_pay = fields.Float(
compute="_compute_qty_to_pay",
digits="Product Unit of Measure",
)

@api.depends(
"delivery_policy",
"product_qty",
"type",
"repair_ids",
"repair_ids.state",
"repair_ids.invoice_method",
"repair_type",
"repair_ids.invoice_id",
"repair_ids.invoice_id.payment_state",
)
def _compute_qty_to_pay(self):
for rec in self:
qty_to_pay = 0.0
if rec.delivery_policy == "repair":
for repair in rec.repair_ids.filtered(
lambda r: r.invoice_method != "none"
and r.invoice_id
and r.invoice_id.state != "cancel"
and r.invoice_id.payment_state in ["not_paid", "partial"]
):
qty_to_pay += self.uom_id._compute_quantity(
repair.product_qty, repair.product_uom
)
rec.qty_to_pay = qty_to_pay

def action_view_repair_order(self):
action = self.env.ref("repair.action_repair_order_tree")
Expand Down Expand Up @@ -168,7 +137,7 @@ def _get_rma_under_repair_qty(self):

@api.onchange("operation_id")
def _onchange_operation_id(self):
result = super(RmaOrderLine, self)._onchange_operation_id()
result = super()._onchange_operation_id()
if self.operation_id:
self.repair_type = self.operation_id.repair_type or "no"
return result
Expand All @@ -184,13 +153,10 @@ def _onchange_operation_id(self):
"repair_ids",
"repair_type",
"repair_ids.state",
"qty_to_pay",
"repair_ids.invoice_id",
"repair_ids.payment_state",
)
def _compute_qty_to_deliver(self):
res = super(RmaOrderLine, self)._compute_qty_to_deliver()
for rec in self.filtered(lambda l: l.delivery_policy == "repair"):
res = super()._compute_qty_to_deliver()
for rec in self.filtered(lambda line: line.delivery_policy == "repair"):
rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered
return res

Expand Down
2 changes: 1 addition & 1 deletion rma_repair/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StockMove(models.Model):
)

def _is_in_out_rma_move(self, op, states, location_type):
res = super(StockMove, self)._is_in_out_rma_move(op, states, location_type)
res = super()._is_in_out_rma_move(op, states, location_type)
if self.is_rma_repair_transfer:
return False
return res
29 changes: 4 additions & 25 deletions rma_repair/tests/test_rma_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
class TestRmaRepair(common.SingleTransactionCase):
@classmethod
def setUpClass(cls):
super(TestRmaRepair, cls).setUpClass()
super().setUpClass()

cls.rma_obj = cls.env["rma.order"]
cls.rma_line_obj = cls.env["rma.order.line"]
cls.rma_op = cls.env["rma.operation"]
cls.rma_add_invoice_wiz = cls.env["rma_add_account_move"]
cls.rma_make_repair_wiz = cls.env["rma.order.line.make.repair"]
cls.rma_make_picking = cls.env["rma_make_picking.wizard"]
cls.repair_line_obj = cls.env["repair.line"]
cls.acc_obj = cls.env["account.account"]
cls.inv_obj = cls.env["account.move"]
cls.invl_obj = cls.env["account.move.line"]
Expand Down Expand Up @@ -262,7 +261,7 @@ def test_03_create_repair_order(self):
self.assertEqual(repair_transfer_move.location_id, self.stock_rma_location)
self.assertEqual(repair_transfer_move.product_qty, 15.0)
self.assertEqual(repair_transfer_move.product_id, rma.product_id)
rma.repair_ids.action_repair_confirm()
rma.repair_ids.action_repair_start()
self.assertEqual(rma.repair_count, 1)
self.assertEqual(rma.qty_to_repair, 0.0)
self.assertEqual(rma.qty_repaired, 0.0)
Expand Down Expand Up @@ -298,7 +297,7 @@ def test_04_deliver_after_repair(self):
picking = self.env["stock.picking"].browse(res["res_id"])
picking.action_assign()
for mv in picking.move_ids:
mv.quantity_done = mv.product_uom_qty
mv.quantity = mv.product_uom_qty
picking._action_done()
self.assertEqual(rma.repair_transfer_count, 0)
self.assertEqual(rma.qty_to_deliver, 0.0)
Expand All @@ -318,31 +317,11 @@ def test_04_deliver_after_repair(self):
self.assertEqual(repair_transfer_move.location_id, self.stock_rma_location)
self.assertEqual(repair_transfer_move.product_id, rma.product_id)
repair = rma.repair_ids
line = self.repair_line_obj.create(
{
"name": "consume stuff to repair",
"repair_id": repair.id,
"type": "add",
"product_id": self.material.id,
"product_uom": self.material.uom_id.id,
"product_uom_qty": 1.0,
"location_id": self.stock_location.id,
"location_dest_id": self.stock_location.id,
"price_unit": 10.0,
}
)
line.onchange_product_id()
repair.invoice_method = "after_repair"
repair.action_repair_confirm()
repair.action_validate()
repair.action_repair_start()
repair.action_repair_end()
self.assertEqual(rma.qty_to_pay, 0.0)
repair.action_repair_invoice_create()
self.assertEqual(rma.qty_repaired, 1.0)
self.assertEqual(rma.qty_to_deliver, 1.0)
repair.invoice_id.action_post()
self.assertEqual(repair.payment_state, "not_paid")
self.assertEqual(rma.qty_to_pay, 1.0)
self.assertEqual(rma.qty_repaired, 1.0)
self.assertEqual(rma.delivery_policy, "repair")
self.assertEqual(rma.qty_delivered, 0.0)
2 changes: 1 addition & 1 deletion rma_repair/views/repair_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="model">repair.order</field>
<field name="inherit_id" ref="repair.view_repair_order_form" />
<field name="arch" type="xml">
<field name="guarantee_limit" position="after">
<field name="tag_ids" position="after">
<field name="rma_line_id" />
<field name="under_warranty" />
</field>
Expand Down
1 change: 0 additions & 1 deletion rma_repair/views/rma_operation_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<group name="outbound" position="after">
<group name="repair" string="Repair">
<field name="repair_location_id" />
<field name="repair_invoice_method" />
<field name="repair_route_id" />
</group>
</group>
Expand Down
13 changes: 6 additions & 7 deletions rma_repair/views/rma_order_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="oe_stat_button"
icon="fa-wrench"
groups="stock.group_stock_user"
attrs="{'invisible': [('repair_count', '=', 0)]}"
invisible="repair_count == 0"
>
<field
name="repair_count"
Expand All @@ -27,7 +27,7 @@
class="oe_stat_button"
icon="fa-truck"
groups="stock.group_stock_user"
attrs="{'invisible': [('repair_transfer_count', '=', 0)]}"
invisible="repair_transfer_count == 0"
>
<field
name="repair_transfer_count"
Expand All @@ -37,10 +37,9 @@
</button>
</div>
<group name="quantities" position="inside">
<group attrs="{'invisible': [('repair_type', '=', 'no')]}">
<group invisible="repair_type == 'no'">
<field name="qty_to_repair" />
<field name="qty_under_repair" />
<field name="qty_to_pay" />
<field name="qty_repaired" />
</group>
</group>
Expand All @@ -49,7 +48,7 @@
</field>
<notebook position="inside">
<page name="repair" string="Repair Orders">
<field name="repair_ids" nolabel="1" />
<field name="repair_ids" nolabel="1" readonly="state != 'draft'" />
</page>
</notebook>
</field>
Expand All @@ -65,13 +64,13 @@
name="%(action_rma_order_line_make_repair)d"
string="Create Repair Order"
class="oe_highlight"
attrs="{'invisible':['|', '|', ('type', '!=', 'customer'), '|', ('qty_to_repair', '=', 0), ('qty_to_repair', '&lt;', 0), ('state', '!=', 'approved')]}"
invisible="type != 'customer' or qty_to_repair == 0 or qty_to_repair &lt; 0 or state != 'approved'"
type="action"
/>
<button
name="%(action_rma_order_line_make_repair)d"
string="Create Repair Order"
attrs="{'invisible':['|', '|', ('type', '!=', 'customer'), ('qty_to_repair', '>', 0), ('state', '!=', 'approved')]}"
invisible="type != 'customer' or qty_to_repair &gt; 0 or state != 'approved'"
type="action"
/>
</header>
Expand Down
4 changes: 2 additions & 2 deletions rma_repair/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="oe_stat_button"
icon="fa-wrench"
groups="stock.group_stock_user"
attrs="{'invisible':[('type', '!=', 'customer')]}"
invisible="type != 'customer'"
>
<field
name="repair_count"
Expand All @@ -27,7 +27,7 @@
class="oe_stat_button"
icon="fa-truck"
groups="stock.group_stock_user"
attrs="{'invisible': [('repair_transfer_count', '=', 0)]}"
invisible="repair_transfer_count == 0"
>
<field
name="repair_transfer_count"
Expand Down
20 changes: 1 addition & 19 deletions rma_repair/wizards/rma_order_line_make_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ def _prepare_item(self, line):
"partner_id": line.partner_id.id,
"location_id": line.operation_id.repair_location_id.id
or line.location_id.id,
"invoice_method": line.operation_id.repair_invoice_method or "after_repair",
}

@api.model
def default_get(self, fields_list):
res = super(RmaLineMakeRepair, self).default_get(fields_list)
res = super().default_get(fields_list)
rma_line_obj = self.env["rma.order.line"]
rma_line_ids = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"]
Expand Down Expand Up @@ -118,34 +117,17 @@ def _check_product_qty(self):
location_id = fields.Many2one(
comodel_name="stock.location", string="Location", required=True
)
invoice_method = fields.Selection(
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.",
)

def _prepare_repair_order(self, rma_line):
self.ensure_one()
addr = rma_line.partner_id.address_get(["delivery", "invoice"])
return {
"product_id": rma_line.product_id.id,
"partner_id": rma_line.partner_id.id,
"pricelist_id": rma_line.partner_id.property_product_pricelist.id or False,
"product_qty": self.product_qty,
"rma_line_id": rma_line.id,
"product_uom": rma_line.product_id.uom_po_id.id,
"company_id": rma_line.company_id.id,
"location_id": self.location_id.id,
"invoice_method": self.invoice_method,
"address_id": addr["delivery"],
"partner_invoice_id": addr["invoice"],
"lot_id": rma_line.lot_id.id,
}

Expand Down
41 changes: 20 additions & 21 deletions rma_repair/wizards/rma_order_line_make_repair_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,43 @@
<field name="model">rma.order.line.make.repair</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Create Repair">
<separator string="New Repair Orders details:" />
<newline />
<group>
<field name="item_ids" nolabel="1" colspan="2">
<tree name="Details" editable="bottom" create="false">
<field
<form string="Create Repair">
<separator string="New Repair Orders details:" />
<newline />
<group>
<field name="item_ids" nolabel="1" colspan="2">
<tree name="Details" editable="bottom" create="false">
<field
name="line_id"
force_save="1"
options="{'no_open': true}"
/>
<field name="product_id" force_save="1" />
<field name="product_qty" />
<field
<field name="product_id" force_save="1" />
<field name="product_qty" />
<field
name="product_uom_id"
force_save="1"
groups="uom.group_uom"
/>
<field name="partner_id" force_save="1" />
<field
<field name="partner_id" force_save="1" />
<field
name="location_id"
groups="stock.group_stock_multi_locations"
force_save="1"
/>
<field name="invoice_method" />
</tree>
</field>
</group>
<newline />
<footer>
<button
</tree>
</field>
</group>
<newline />
<footer>
<button
name="make_repair_order"
string="Create Repair Orders"
type="object"
class="oe_highlight"
/>
<button special="cancel" string="Cancel" class="oe_link" />
</footer>
<button special="cancel" string="Cancel" class="oe_link" />
</footer>
</form>
</field>
</record>
Expand Down

0 comments on commit d1802c3

Please sign in to comment.