[MIG] rma_repair: Migration to 17.0

This commit is contained in:
JasminSForgeFlow
2025-01-08 12:18:31 +05:30
parent a6d45e6f53
commit 0684b47338
13 changed files with 39 additions and 138 deletions

View File

@@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{ {
"name": "RMA Repair", "name": "RMA Repair",
"version": "16.0.1.0.0", "version": "17.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"category": "RMA", "category": "RMA",
"summary": "Links RMA with Repairs.", "summary": "Links RMA with Repairs.",
@@ -16,7 +16,6 @@
"views/repair_view.xml", "views/repair_view.xml",
"wizards/rma_order_line_make_repair_view.xml", "wizards/rma_order_line_make_repair_view.xml",
"views/rma_order_line_view.xml", "views/rma_order_line_view.xml",
"data/repair_sequence.xml",
], ],
"installable": True, "installable": True,
} }

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="repair.seq_repair" model="ir.sequence">
<field name="prefix">RO</field>
</record>
</odoo>

View File

@@ -13,6 +13,3 @@ class RepairOrder(models.Model):
under_warranty = fields.Boolean( under_warranty = fields.Boolean(
related="rma_line_id.under_warranty", related="rma_line_id.under_warranty",
) )
payment_state = fields.Selection(
related="invoice_id.payment_state", string="Payment Status"
)

View File

@@ -24,17 +24,6 @@ class RmaOperation(models.Model):
comodel_name="stock.location", comodel_name="stock.location",
help="Indicate here the source location of the product to be repaired", 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( repair_route_id = fields.Many2one(
comodel_name="stock.route", comodel_name="stock.route",
string="Repair Route", string="Repair Route",

View File

@@ -48,7 +48,6 @@ class RmaOrderLine(models.Model):
inverse_name="rma_line_id", inverse_name="rma_line_id",
string="Repair Orders", string="Repair Orders",
readonly=True, readonly=True,
states={"draft": [("readonly", False)]},
copy=False, copy=False,
) )
qty_to_repair = fields.Float( qty_to_repair = fields.Float(
@@ -95,36 +94,6 @@ class RmaOrderLine(models.Model):
selection_add=[("repair", "Based on Repair Quantities")], selection_add=[("repair", "Based on Repair Quantities")],
ondelete={"repair": lambda recs: recs.write({"delivery_policy": "no"})}, 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): def action_view_repair_order(self):
action = self.env.ref("repair.action_repair_order_tree") action = self.env.ref("repair.action_repair_order_tree")
@@ -168,7 +137,7 @@ class RmaOrderLine(models.Model):
@api.onchange("operation_id") @api.onchange("operation_id")
def _onchange_operation_id(self): def _onchange_operation_id(self):
result = super(RmaOrderLine, self)._onchange_operation_id() result = super()._onchange_operation_id()
if self.operation_id: if self.operation_id:
self.repair_type = self.operation_id.repair_type or "no" self.repair_type = self.operation_id.repair_type or "no"
return result return result
@@ -184,13 +153,10 @@ class RmaOrderLine(models.Model):
"repair_ids", "repair_ids",
"repair_type", "repair_type",
"repair_ids.state", "repair_ids.state",
"qty_to_pay",
"repair_ids.invoice_id",
"repair_ids.payment_state",
) )
def _compute_qty_to_deliver(self): def _compute_qty_to_deliver(self):
res = super(RmaOrderLine, self)._compute_qty_to_deliver() res = super()._compute_qty_to_deliver()
for rec in self.filtered(lambda l: l.delivery_policy == "repair"): for rec in self.filtered(lambda line: line.delivery_policy == "repair"):
rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered
return res return res

View File

@@ -13,7 +13,7 @@ class StockMove(models.Model):
) )
def _is_in_out_rma_move(self, op, states, location_type): 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: if self.is_rma_repair_transfer:
return False return False
return res return res

View File

@@ -8,7 +8,7 @@ from odoo.tests import common
class TestRmaRepair(common.SingleTransactionCase): class TestRmaRepair(common.SingleTransactionCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestRmaRepair, cls).setUpClass() super().setUpClass()
cls.rma_obj = cls.env["rma.order"] cls.rma_obj = cls.env["rma.order"]
cls.rma_line_obj = cls.env["rma.order.line"] cls.rma_line_obj = cls.env["rma.order.line"]
@@ -16,7 +16,6 @@ class TestRmaRepair(common.SingleTransactionCase):
cls.rma_add_invoice_wiz = cls.env["rma_add_account_move"] 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_repair_wiz = cls.env["rma.order.line.make.repair"]
cls.rma_make_picking = cls.env["rma_make_picking.wizard"] 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.acc_obj = cls.env["account.account"]
cls.inv_obj = cls.env["account.move"] cls.inv_obj = cls.env["account.move"]
cls.invl_obj = cls.env["account.move.line"] cls.invl_obj = cls.env["account.move.line"]
@@ -262,7 +261,7 @@ class TestRmaRepair(common.SingleTransactionCase):
self.assertEqual(repair_transfer_move.location_id, self.stock_rma_location) 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_qty, 15.0)
self.assertEqual(repair_transfer_move.product_id, rma.product_id) 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.repair_count, 1)
self.assertEqual(rma.qty_to_repair, 0.0) self.assertEqual(rma.qty_to_repair, 0.0)
self.assertEqual(rma.qty_repaired, 0.0) self.assertEqual(rma.qty_repaired, 0.0)
@@ -298,7 +297,7 @@ class TestRmaRepair(common.SingleTransactionCase):
picking = self.env["stock.picking"].browse(res["res_id"]) picking = self.env["stock.picking"].browse(res["res_id"])
picking.action_assign() picking.action_assign()
for mv in picking.move_ids: for mv in picking.move_ids:
mv.quantity_done = mv.product_uom_qty mv.quantity = mv.product_uom_qty
picking._action_done() picking._action_done()
self.assertEqual(rma.repair_transfer_count, 0) self.assertEqual(rma.repair_transfer_count, 0)
self.assertEqual(rma.qty_to_deliver, 0.0) self.assertEqual(rma.qty_to_deliver, 0.0)
@@ -318,31 +317,11 @@ class TestRmaRepair(common.SingleTransactionCase):
self.assertEqual(repair_transfer_move.location_id, self.stock_rma_location) self.assertEqual(repair_transfer_move.location_id, self.stock_rma_location)
self.assertEqual(repair_transfer_move.product_id, rma.product_id) self.assertEqual(repair_transfer_move.product_id, rma.product_id)
repair = rma.repair_ids repair = rma.repair_ids
line = self.repair_line_obj.create( repair.action_validate()
{
"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_repair_start() repair.action_repair_start()
repair.action_repair_end() 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_repaired, 1.0)
self.assertEqual(rma.qty_to_deliver, 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.qty_repaired, 1.0)
self.assertEqual(rma.delivery_policy, "repair") self.assertEqual(rma.delivery_policy, "repair")
self.assertEqual(rma.qty_delivered, 0.0) self.assertEqual(rma.qty_delivered, 0.0)

View File

@@ -6,7 +6,7 @@
<field name="model">repair.order</field> <field name="model">repair.order</field>
<field name="inherit_id" ref="repair.view_repair_order_form" /> <field name="inherit_id" ref="repair.view_repair_order_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="guarantee_limit" position="after"> <field name="tag_ids" position="after">
<field name="rma_line_id" /> <field name="rma_line_id" />
<field name="under_warranty" /> <field name="under_warranty" />
</field> </field>

View File

@@ -20,7 +20,6 @@
<group name="outbound" position="after"> <group name="outbound" position="after">
<group name="repair" string="Repair"> <group name="repair" string="Repair">
<field name="repair_location_id" /> <field name="repair_location_id" />
<field name="repair_invoice_method" />
<field name="repair_route_id" /> <field name="repair_route_id" />
</group> </group>
</group> </group>

View File

@@ -13,7 +13,7 @@
class="oe_stat_button" class="oe_stat_button"
icon="fa-wrench" icon="fa-wrench"
groups="stock.group_stock_user" groups="stock.group_stock_user"
attrs="{'invisible': [('repair_count', '=', 0)]}" invisible="repair_count == 0"
> >
<field <field
name="repair_count" name="repair_count"
@@ -27,7 +27,7 @@
class="oe_stat_button" class="oe_stat_button"
icon="fa-truck" icon="fa-truck"
groups="stock.group_stock_user" groups="stock.group_stock_user"
attrs="{'invisible': [('repair_transfer_count', '=', 0)]}" invisible="repair_transfer_count == 0"
> >
<field <field
name="repair_transfer_count" name="repair_transfer_count"
@@ -37,10 +37,9 @@
</button> </button>
</div> </div>
<group name="quantities" position="inside"> <group name="quantities" position="inside">
<group attrs="{'invisible': [('repair_type', '=', 'no')]}"> <group invisible="repair_type == 'no'">
<field name="qty_to_repair" /> <field name="qty_to_repair" />
<field name="qty_under_repair" /> <field name="qty_under_repair" />
<field name="qty_to_pay" />
<field name="qty_repaired" /> <field name="qty_repaired" />
</group> </group>
</group> </group>
@@ -49,7 +48,7 @@
</field> </field>
<notebook position="inside"> <notebook position="inside">
<page name="repair" string="Repair Orders"> <page name="repair" string="Repair Orders">
<field name="repair_ids" nolabel="1" /> <field name="repair_ids" nolabel="1" readonly="state != 'draft'" />
</page> </page>
</notebook> </notebook>
</field> </field>
@@ -65,13 +64,13 @@
name="%(action_rma_order_line_make_repair)d" name="%(action_rma_order_line_make_repair)d"
string="Create Repair Order" string="Create Repair Order"
class="oe_highlight" 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" type="action"
/> />
<button <button
name="%(action_rma_order_line_make_repair)d" name="%(action_rma_order_line_make_repair)d"
string="Create Repair Order" 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" type="action"
/> />
</header> </header>

View File

@@ -13,7 +13,7 @@
class="oe_stat_button" class="oe_stat_button"
icon="fa-wrench" icon="fa-wrench"
groups="stock.group_stock_user" groups="stock.group_stock_user"
attrs="{'invisible':[('type', '!=', 'customer')]}" invisible="type != 'customer'"
> >
<field <field
name="repair_count" name="repair_count"
@@ -27,7 +27,7 @@
class="oe_stat_button" class="oe_stat_button"
icon="fa-truck" icon="fa-truck"
groups="stock.group_stock_user" groups="stock.group_stock_user"
attrs="{'invisible': [('repair_transfer_count', '=', 0)]}" invisible="repair_transfer_count == 0"
> >
<field <field
name="repair_transfer_count" name="repair_transfer_count"

View File

@@ -29,12 +29,11 @@ class RmaLineMakeRepair(models.TransientModel):
"partner_id": line.partner_id.id, "partner_id": line.partner_id.id,
"location_id": line.operation_id.repair_location_id.id "location_id": line.operation_id.repair_location_id.id
or line.location_id.id, or line.location_id.id,
"invoice_method": line.operation_id.repair_invoice_method or "after_repair",
} }
@api.model @api.model
def default_get(self, fields_list): 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_obj = self.env["rma.order.line"]
rma_line_ids = self.env.context["active_ids"] or [] rma_line_ids = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"] active_model = self.env.context["active_model"]
@@ -118,34 +117,17 @@ class RmaLineMakeRepairItem(models.TransientModel):
location_id = fields.Many2one( location_id = fields.Many2one(
comodel_name="stock.location", string="Location", required=True 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): def _prepare_repair_order(self, rma_line):
self.ensure_one() self.ensure_one()
addr = rma_line.partner_id.address_get(["delivery", "invoice"])
return { return {
"product_id": rma_line.product_id.id, "product_id": rma_line.product_id.id,
"partner_id": rma_line.partner_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, "product_qty": self.product_qty,
"rma_line_id": rma_line.id, "rma_line_id": rma_line.id,
"product_uom": rma_line.product_id.uom_po_id.id, "product_uom": rma_line.product_id.uom_po_id.id,
"company_id": rma_line.company_id.id, "company_id": rma_line.company_id.id,
"location_id": self.location_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, "lot_id": rma_line.lot_id.id,
} }

View File

@@ -30,7 +30,6 @@
groups="stock.group_stock_multi_locations" groups="stock.group_stock_multi_locations"
force_save="1" force_save="1"
/> />
<field name="invoice_method" />
</tree> </tree>
</field> </field>
</group> </group>