[ENH]qty under repair on rma

This commit is contained in:
ahenriquez
2019-09-19 17:25:45 +02:00
committed by Jordi Ballester Alomar
parent 12e3057056
commit e380478b84
6 changed files with 89 additions and 8 deletions

View File

@@ -3,7 +3,7 @@
{
"name": "RMA Repair",
"version": "12.0.1.1.0",
"version": "12.0.1.2.0",
"license": "LGPL-3",
"category": "RMA",
"summary": "Links RMA with Repairs.",

View File

@@ -13,3 +13,4 @@ class RepairOrder(models.Model):
under_warranty = fields.Boolean(
related='rma_line_id.under_warranty', readonly=False,
)
invoice_status = fields.Selection(related='invoice_id.state')

View File

@@ -15,10 +15,12 @@ class RmaOrderLine(models.Model):
if line.repair_type == 'no':
line.qty_to_repair = 0.0
elif line.repair_type == 'ordered':
qty = line._get_rma_repaired_qty()
qty = line._get_rma_repaired_qty() + \
line._get_rma_under_repair_qty()
line.qty_to_repair = line.product_qty - qty
elif line.repair_type == 'received':
qty = line._get_rma_repaired_qty()
qty = line._get_rma_repaired_qty() + \
line._get_rma_under_repair_qty()
line.qty_to_repair = line.qty_received - qty
else:
line.qty_to_repair = 0.0
@@ -29,6 +31,12 @@ class RmaOrderLine(models.Model):
for line in self:
line.qty_repaired = line._get_rma_repaired_qty()
@api.depends('repair_ids', 'repair_type', 'repair_ids.state',
'qty_to_receive')
def _compute_qty_under_repair(self):
for line in self:
line.qty_under_repair = line._get_rma_under_repair_qty()
@api.depends('repair_ids')
def _compute_repair_count(self):
for line in self:
@@ -43,6 +51,11 @@ class RmaOrderLine(models.Model):
digits=dp.get_precision('Product Unit of Measure'),
readonly=True, compute='_compute_qty_to_repair',
store=True)
qty_under_repair = fields.Float(
string='Qty Under Repair', copy=False,
digits=dp.get_precision('Product Unit of Measure'),
readonly=True, compute='_compute_qty_under_repair',
store=True)
qty_repaired = fields.Float(
string='Qty Repaired', copy=False,
digits=dp.get_precision('Product Unit of Measure'),
@@ -57,9 +70,24 @@ class RmaOrderLine(models.Model):
delivery_policy = fields.Selection(selection_add=[
('repair', 'Based on Repair Quantities')])
qty_to_pay = fields.Float(
compute='_compute_qty_to_pay')
qty_to_deliver = fields.Float(
compute='_compute_qty_to_deliver')
@api.multi
@api.depends('delivery_policy', 'product_qty', 'type', 'repair_ids',
'repair_ids.state', 'repair_ids.invoice_method',
'repair_type', 'repair_ids.invoice_status')
def _compute_qty_to_pay(self):
for rec in self.filtered(lambda l: l.delivery_policy == 'repair'):
qty_to_pay = 0.0
for repair in rec.repair_ids.filtered(
lambda r: r.invoice_method != 'none'
and r.invoice_status != 'paid'):
qty_to_pay += repair.product_qty
rec.qty_to_pay = qty_to_pay
@api.multi
def action_view_repair_order(self):
action = self.env.ref('repair.action_repair_order_tree')
@@ -78,7 +106,20 @@ class RmaOrderLine(models.Model):
self.ensure_one()
qty = 0.0
for repair in self.repair_ids.filtered(
lambda p: p.state != 'cancel'):
lambda p: p.state == 'done'):
repair_qty = self.uom_id._compute_quantity(
repair.product_qty,
repair.product_uom,
)
qty += repair_qty
return qty
@api.multi
def _get_rma_under_repair_qty(self):
self.ensure_one()
qty = 0.0
for repair in self.repair_ids.filtered(
lambda p: p.state not in ('draft', 'cancel', 'done')):
repair_qty = self.uom_id._compute_quantity(
repair.product_qty,
repair.product_uom,
@@ -97,9 +138,10 @@ class RmaOrderLine(models.Model):
@api.depends('move_ids', 'move_ids.state',
'delivery_policy', 'product_qty', 'type', 'qty_delivered',
'qty_received', 'repair_ids', 'repair_type',
'repair_ids.state')
'repair_ids.state', 'qty_to_pay', 'repair_ids.invoice_status')
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'):
rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered
rec.qty_to_deliver = rec.qty_repaired - rec.qty_delivered - \
rec.qty_to_pay
return res

View File

@@ -15,6 +15,7 @@ class TestRmaRepair(common.SingleTransactionCase):
cls.rma_op = cls.env['rma.operation']
cls.rma_add_invoice_wiz = cls.env['rma_add_invoice']
cls.rma_make_repair_wiz = cls.env['rma.order.line.make.repair']
cls.repair_line_obj = cls.env['repair.line']
cls.acc_obj = cls.env['account.account']
cls.inv_obj = cls.env['account.invoice']
cls.invl_obj = cls.env['account.invoice.line']
@@ -123,6 +124,15 @@ class TestRmaRepair(common.SingleTransactionCase):
'partner_id': customer1.id,
'type': 'customer',
})
cls.bank_journal = cls.env['account.journal'].search(
[('type', '=', 'bank')], limit=1)
cls.material = cls.product_obj.create({
'name': 'Materials',
'type': 'product',
})
cls.material.product_tmpl_id.standard_price = 10
cls.stock_location = cls.env.ref('stock.stock_location_stock')
def test_01_add_from_invoice_customer(self):
"""Test wizard to create RMA from a customer invoice."""
@@ -183,7 +193,8 @@ class TestRmaRepair(common.SingleTransactionCase):
rma.repair_ids.action_repair_confirm()
self.assertEqual(rma.repair_count, 1)
self.assertEqual(rma.qty_to_repair, 0.0)
self.assertEqual(rma.qty_repaired, 15.0)
self.assertEqual(rma.qty_repaired, 0.0)
self.assertEqual(rma.qty_under_repair, 15.0)
def test_04_deliver_after_repair(self):
"""Only deliver after repair"""
@@ -211,5 +222,28 @@ class TestRmaRepair(common.SingleTransactionCase):
'description': 'Test deliver',
})
make_repair.make_repair_order()
rma.repair_ids.action_repair_confirm()
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_repair_start()
repair.action_repair_end()
repair.action_repair_invoice_create()
self.assertEqual(rma.qty_repaired, 1.0)
repair.invoice_id.action_invoice_open()
self.assertEqual(rma.qty_to_deliver, 0.0)
repair.invoice_id.pay_and_reconcile(self.bank_journal, 200.0)
self.assertEqual(repair.invoice_status, 'paid')
self.assertEqual(rma.qty_to_pay, 0.0)
self.assertEqual(rma.qty_to_deliver, 1.0)

View File

@@ -18,6 +18,8 @@
<group name="quantities" position="inside">
<group>
<field name="qty_to_repair"/>
<field name="qty_under_repair"/>
<field name="qty_to_pay"/>
<field name="qty_repaired"/>
</group>
</group>

View File

@@ -154,6 +154,8 @@ class RmaLineMakeRepairItem(models.TransientModel):
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,