mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[14.0][FIX] rma_repair:
* fix quantity computation * use a payment_state field instead of inovice state one. * Use proper digits and unit conversion. * Add a filter "To repair". * Remove dead code and clean warnings.
This commit is contained in:
committed by
JasminSForgeFlow
parent
f9f251fdd5
commit
a222744528
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2020 ForgeFlow S.L.
|
# Copyright 2020-21 ForgeFlow S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import fields, models
|
from odoo import fields, models
|
||||||
@@ -13,6 +13,6 @@ class RepairOrder(models.Model):
|
|||||||
under_warranty = fields.Boolean(
|
under_warranty = fields.Boolean(
|
||||||
related="rma_line_id.under_warranty", readonly=False
|
related="rma_line_id.under_warranty", readonly=False
|
||||||
)
|
)
|
||||||
invoice_status = fields.Selection(
|
payment_state = fields.Selection(
|
||||||
related="invoice_id.state", string="Invoice Status"
|
related="invoice_id.payment_state", string="Payment Status"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2020 ForgeFlow S.L.
|
# Copyright 2020-21 ForgeFlow S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
@@ -14,10 +14,10 @@ class RmaOrderLine(models.Model):
|
|||||||
line.qty_to_repair = 0.0
|
line.qty_to_repair = 0.0
|
||||||
elif line.repair_type == "ordered":
|
elif line.repair_type == "ordered":
|
||||||
qty = line._get_rma_repaired_qty() + line._get_rma_under_repair_qty()
|
qty = line._get_rma_repaired_qty() + line._get_rma_under_repair_qty()
|
||||||
line.qty_to_repair = line.product_qty - qty
|
line.qty_to_repair = max(line.product_qty - qty, 0)
|
||||||
elif line.repair_type == "received":
|
elif line.repair_type == "received":
|
||||||
qty = line._get_rma_repaired_qty() + line._get_rma_under_repair_qty()
|
qty = line._get_rma_repaired_qty() + line._get_rma_under_repair_qty()
|
||||||
line.qty_to_repair = line.qty_received - qty
|
line.qty_to_repair = max(line.qty_received - qty, 0)
|
||||||
else:
|
else:
|
||||||
line.qty_to_repair = 0.0
|
line.qty_to_repair = 0.0
|
||||||
|
|
||||||
@@ -87,8 +87,10 @@ 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")
|
qty_to_pay = fields.Float(
|
||||||
qty_to_deliver = fields.Float(compute="_compute_qty_to_deliver")
|
compute="_compute_qty_to_pay",
|
||||||
|
digits="Product Unit of Measure",
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends(
|
@api.depends(
|
||||||
"delivery_policy",
|
"delivery_policy",
|
||||||
@@ -98,7 +100,8 @@ class RmaOrderLine(models.Model):
|
|||||||
"repair_ids.state",
|
"repair_ids.state",
|
||||||
"repair_ids.invoice_method",
|
"repair_ids.invoice_method",
|
||||||
"repair_type",
|
"repair_type",
|
||||||
"repair_ids.invoice_status",
|
"repair_ids.invoice_id",
|
||||||
|
"repair_ids.invoice_id.payment_state",
|
||||||
)
|
)
|
||||||
def _compute_qty_to_pay(self):
|
def _compute_qty_to_pay(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@@ -106,9 +109,13 @@ class RmaOrderLine(models.Model):
|
|||||||
if rec.delivery_policy == "repair":
|
if rec.delivery_policy == "repair":
|
||||||
for repair in rec.repair_ids.filtered(
|
for repair in rec.repair_ids.filtered(
|
||||||
lambda r: r.invoice_method != "none"
|
lambda r: r.invoice_method != "none"
|
||||||
and r.invoice_status != "posted"
|
and r.invoice_id
|
||||||
|
and r.invoice_id.state != "cancel"
|
||||||
|
and r.invoice_id.payment_state in ["not_paid", "partial"]
|
||||||
):
|
):
|
||||||
qty_to_pay += repair.product_qty
|
qty_to_pay += self.uom_id._compute_quantity(
|
||||||
|
repair.product_qty, repair.product_uom
|
||||||
|
)
|
||||||
rec.qty_to_pay = qty_to_pay
|
rec.qty_to_pay = qty_to_pay
|
||||||
|
|
||||||
def action_view_repair_order(self):
|
def action_view_repair_order(self):
|
||||||
@@ -137,7 +144,7 @@ class RmaOrderLine(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
qty = 0.0
|
qty = 0.0
|
||||||
for repair in self.repair_ids.filtered(
|
for repair in self.repair_ids.filtered(
|
||||||
lambda p: p.state not in ("draft", "cancel", "done")
|
lambda p: p.state not in ("cancel", "done")
|
||||||
):
|
):
|
||||||
repair_qty = self.uom_id._compute_quantity(
|
repair_qty = self.uom_id._compute_quantity(
|
||||||
repair.product_qty, repair.product_uom
|
repair.product_qty, repair.product_uom
|
||||||
@@ -164,7 +171,8 @@ class RmaOrderLine(models.Model):
|
|||||||
"repair_type",
|
"repair_type",
|
||||||
"repair_ids.state",
|
"repair_ids.state",
|
||||||
"qty_to_pay",
|
"qty_to_pay",
|
||||||
"repair_ids.invoice_status",
|
"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(RmaOrderLine, self)._compute_qty_to_deliver()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2020 ForgeFlow S.L.
|
# Copyright 2020-21 ForgeFlow S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
@@ -168,14 +168,14 @@ class TestRmaRepair(common.SingleTransactionCase):
|
|||||||
lambda r: r.product_id == self.product_1
|
lambda r: r.product_id == self.product_1
|
||||||
)
|
)
|
||||||
rma_1.repair_type = self.operation_1.repair_type
|
rma_1.repair_type = self.operation_1.repair_type
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
rma_1.operation_id, self.operation_1, "Operation should be operation_1"
|
rma_1.operation_id, self.operation_1, "Operation should be operation_1"
|
||||||
)
|
)
|
||||||
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
||||||
lambda r: r.product_id == self.product_2
|
lambda r: r.product_id == self.product_2
|
||||||
)
|
)
|
||||||
rma_2.repair_type = self.operation_2.repair_type
|
rma_2.repair_type = self.operation_2.repair_type
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
rma_2.operation_id, self.operation_2, "Operation should be operation_2"
|
rma_2.operation_id, self.operation_2, "Operation should be operation_2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -185,15 +185,15 @@ class TestRmaRepair(common.SingleTransactionCase):
|
|||||||
rma_1 = self.rma_group_customer.rma_line_ids.filtered(
|
rma_1 = self.rma_group_customer.rma_line_ids.filtered(
|
||||||
lambda r: r.product_id == self.product_1
|
lambda r: r.product_id == self.product_1
|
||||||
)
|
)
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
rma_1.operation_id.repair_type, "received", "Incorrect Repair operation"
|
rma_1.operation_id.repair_type, "received", "Incorrect Repair operation"
|
||||||
)
|
)
|
||||||
self.assertEquals(rma_1.qty_to_repair, 0.0, "Quantity to repair should be 0.0")
|
self.assertEqual(rma_1.qty_to_repair, 0.0, "Quantity to repair should be 0.0")
|
||||||
# Ordered repair_type:
|
# Ordered repair_type:
|
||||||
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
||||||
lambda r: r.product_id == self.product_2
|
lambda r: r.product_id == self.product_2
|
||||||
)
|
)
|
||||||
self.assertEquals(
|
self.assertEqual(
|
||||||
rma_2.operation_id.repair_type, "ordered", "Incorrect Repair operation"
|
rma_2.operation_id.repair_type, "ordered", "Incorrect Repair operation"
|
||||||
)
|
)
|
||||||
self.assertEqual(rma_2.qty_to_repair, 15.0)
|
self.assertEqual(rma_2.qty_to_repair, 15.0)
|
||||||
@@ -259,13 +259,13 @@ class TestRmaRepair(common.SingleTransactionCase):
|
|||||||
repair.action_repair_confirm()
|
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()
|
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.post()
|
repair.invoice_id.action_post()
|
||||||
repair.invoice_id.action_register_payment()
|
self.assertEqual(repair.payment_state, "not_paid")
|
||||||
self.assertEqual(repair.invoice_status, "posted")
|
self.assertEqual(rma.qty_to_pay, 1.0)
|
||||||
self.assertEqual(rma.qty_to_pay, 0.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)
|
||||||
|
|||||||
@@ -57,4 +57,21 @@
|
|||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="view_rma_rma_line_filter" model="ir.ui.view">
|
||||||
|
<field name="name">rma.order.line.select - rma_repair</field>
|
||||||
|
<field name="model">rma.order.line</field>
|
||||||
|
<field name="inherit_id" ref="rma.view_rma_rma_line_filter" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<group name="stock_quantities" position="after">
|
||||||
|
<group name="repair_quantities" groups="stock.group_stock_user">
|
||||||
|
<filter
|
||||||
|
domain="[('state','!=', 'done'),('qty_to_repair','>',0.0)]"
|
||||||
|
help="To Repair"
|
||||||
|
name="to_repair"
|
||||||
|
/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user