mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
Merge pull request #65 from grindtildeath/12.0-mig-rma_repair
[12.0][MIG] rma_repair
This commit is contained in:
3
oca_dependencies.txt
Normal file
3
oca_dependencies.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# List the OCA project dependencies, one per line
|
||||
# Add a repository url and branch if you need a forked version
|
||||
manufacture
|
||||
48
rma_repair/README.rst
Normal file
48
rma_repair/README.rst
Normal file
@@ -0,0 +1,48 @@
|
||||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
|
||||
:alt: License LGPL-3
|
||||
|
||||
==========
|
||||
RMA Repair
|
||||
==========
|
||||
|
||||
This module allows you to create repairs from one or more RMA lines.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
This module depends on ``repair_refurbish`` which is available at
|
||||
`OCA/manufacture <https://github.com/OCA/manufacture>`_.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
To create repairs from RMA lines:
|
||||
|
||||
#. Go to an approved RMA.
|
||||
#. Click on *Create Repair Order*.
|
||||
#. Fill the required information in the lines.
|
||||
#. Hit *Create Repair Orders*.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/Eficent/stock-rma/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Aaron Henriquez <ahenriquez@eficent.com>
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
* Akim Juillerat <akim.juillerat@camptocamp.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
This module is maintained by Eficent
|
||||
4
rma_repair/__init__.py
Normal file
4
rma_repair/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import models
|
||||
from . import wizards
|
||||
25
rma_repair/__manifest__.py
Normal file
25
rma_repair/__manifest__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
{
|
||||
"name": "RMA Repair",
|
||||
"version": "12.0.1.0.0",
|
||||
"license": "LGPL-3",
|
||||
"category": "RMA",
|
||||
"summary": "Links RMA with Repairs.",
|
||||
"author": "Eficent, Odoo Community Association (OCA)",
|
||||
"website": "http://www.github.com/OCA/rma",
|
||||
"depends": [
|
||||
"rma_account",
|
||||
"repair_refurbish"
|
||||
],
|
||||
"data": ["views/rma_order_view.xml",
|
||||
"views/rma_operation_view.xml",
|
||||
"views/repair_view.xml",
|
||||
"wizards/rma_order_line_make_repair_view.xml",
|
||||
"views/rma_order_line_view.xml",
|
||||
"data/repair_sequence.xml",
|
||||
],
|
||||
"installable": True,
|
||||
"auto_install": True,
|
||||
}
|
||||
8
rma_repair/data/repair_sequence.xml
Normal file
8
rma_repair/data/repair_sequence.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?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>
|
||||
6
rma_repair/models/__init__.py
Normal file
6
rma_repair/models/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import repair
|
||||
from . import rma_order_line
|
||||
from . import rma_order
|
||||
from . import rma_operation
|
||||
15
rma_repair/models/repair.py
Normal file
15
rma_repair/models/repair.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RepairOrder(models.Model):
|
||||
_inherit = "repair.order"
|
||||
|
||||
rma_line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA', ondelete='restrict',
|
||||
)
|
||||
under_warranty = fields.Boolean(
|
||||
related='rma_line_id.under_warranty', readonly=False,
|
||||
)
|
||||
13
rma_repair/models/rma_operation.py
Normal file
13
rma_repair/models/rma_operation.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
_inherit = 'rma.operation'
|
||||
|
||||
repair_type = fields.Selection([
|
||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
||||
('received', 'Based on Received Quantities')],
|
||||
string="Repair Policy", default='no')
|
||||
25
rma_repair/models/rma_order.py
Normal file
25
rma_repair/models/rma_order.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class RmaOrder(models.Model):
|
||||
_inherit = "rma.order"
|
||||
|
||||
@api.multi
|
||||
def _compute_repair_count(self):
|
||||
for rma in self:
|
||||
repairs = rma.mapped('rma_line_ids.repair_ids')
|
||||
rma.repair_count = len(repairs)
|
||||
|
||||
repair_count = fields.Integer(
|
||||
compute='_compute_repair_count', string='# of Repairs')
|
||||
|
||||
@api.multi
|
||||
def action_view_repair_order(self):
|
||||
action = self.env.ref('repair.action_repair_order_tree')
|
||||
result = action.read()[0]
|
||||
repair_ids = self.mapped('rma_line_ids.repair_ids').ids
|
||||
result['domain'] = [('id', 'in', repair_ids)]
|
||||
return result
|
||||
82
rma_repair/models/rma_order_line.py
Normal file
82
rma_repair/models/rma_order_line.py
Normal file
@@ -0,0 +1,82 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
_inherit = "rma.order.line"
|
||||
|
||||
@api.depends('repair_ids', 'repair_type', 'repair_ids.state',
|
||||
'qty_to_receive')
|
||||
def _compute_qty_to_repair(self):
|
||||
for line in self:
|
||||
if line.repair_type == 'no':
|
||||
line.qty_to_repair = 0.0
|
||||
elif line.repair_type == 'ordered':
|
||||
qty = line._get_rma_repaired_qty()
|
||||
line.qty_to_repair = line.product_qty - qty
|
||||
elif line.repair_type == 'received':
|
||||
qty = line._get_rma_repaired_qty()
|
||||
line.qty_to_repair = line.qty_received - qty
|
||||
else:
|
||||
line.qty_to_repair = 0.0
|
||||
|
||||
@api.depends('repair_ids', 'repair_type', 'repair_ids.state',
|
||||
'qty_to_receive')
|
||||
def _compute_qty_repaired(self):
|
||||
for line in self:
|
||||
line.qty_repaired = line._get_rma_repaired_qty()
|
||||
|
||||
@api.depends('repair_ids')
|
||||
def _compute_repair_count(self):
|
||||
for line in self:
|
||||
line.repair_count = len(line.repair_ids)
|
||||
|
||||
repair_ids = fields.One2many(
|
||||
comodel_name='repair.order', inverse_name='rma_line_id',
|
||||
string='Repair Orders', readonly=True,
|
||||
states={'draft': [('readonly', False)]}, copy=False)
|
||||
qty_to_repair = fields.Float(
|
||||
string='Qty To Repair', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute='_compute_qty_to_repair',
|
||||
store=True)
|
||||
qty_repaired = fields.Float(
|
||||
string='Qty Repaired', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute='_compute_qty_repaired',
|
||||
store=True, help="Quantity repaired or being repaired.")
|
||||
repair_type = fields.Selection(selection=[
|
||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
||||
('received', 'Based on Received Quantities')],
|
||||
string="Repair Policy", default='no', required=True)
|
||||
repair_count = fields.Integer(
|
||||
compute='_compute_repair_count', string='# of Repairs')
|
||||
|
||||
@api.multi
|
||||
def action_view_repair_order(self):
|
||||
action = self.env.ref('repair.action_repair_order_tree')
|
||||
result = action.read()[0]
|
||||
repair_ids = self.repair_ids.ids
|
||||
if len(repair_ids) != 1:
|
||||
result['domain'] = [('id', 'in', repair_ids)]
|
||||
elif len(repair_ids) == 1:
|
||||
res = self.env.ref('repair.view_repair_order_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = repair_ids[0]
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def _get_rma_repaired_qty(self):
|
||||
self.ensure_one()
|
||||
qty = 0.0
|
||||
for repair in self.repair_ids.filtered(
|
||||
lambda p: p.state != 'cancel'):
|
||||
repair_qty = self.uom_id._compute_quantity(
|
||||
repair.product_qty,
|
||||
repair.product_uom,
|
||||
)
|
||||
qty += repair_qty
|
||||
return qty
|
||||
2
rma_repair/tests/__init__.py
Normal file
2
rma_repair/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
from . import test_rma_repair
|
||||
154
rma_repair/tests/test_rma_repair.py
Normal file
154
rma_repair/tests/test_rma_repair.py
Normal file
@@ -0,0 +1,154 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestRmaRepair(common.SingleTransactionCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestRmaRepair, cls).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_invoice']
|
||||
cls.rma_make_repair_wiz = cls.env['rma.order.line.make.repair']
|
||||
cls.acc_obj = cls.env['account.account']
|
||||
cls.inv_obj = cls.env['account.invoice']
|
||||
cls.invl_obj = cls.env['account.invoice.line']
|
||||
cls.product_obj = cls.env['product.product']
|
||||
cls.partner_obj = cls.env['res.partner']
|
||||
|
||||
cls.rma_route_cust = cls.env.ref('rma.route_rma_customer')
|
||||
receivable_type = cls.env.ref('account.data_account_type_receivable')
|
||||
|
||||
# Create partners
|
||||
customer1 = cls.partner_obj.create({'name': 'Customer 1'})
|
||||
|
||||
# Create RMA group and operation:
|
||||
cls.rma_group_customer = cls.rma_obj.create({
|
||||
'partner_id': customer1.id,
|
||||
'type': 'customer',
|
||||
})
|
||||
cls.operation_1 = cls.rma_op.create({
|
||||
'code': 'TEST',
|
||||
'name': 'Repair afer receive',
|
||||
'type': 'customer',
|
||||
'receipt_policy': 'ordered',
|
||||
'repair_type': 'received',
|
||||
'in_route_id': cls.rma_route_cust.id,
|
||||
'out_route_id': cls.rma_route_cust.id,
|
||||
})
|
||||
cls.operation_2 = cls.rma_op.create({
|
||||
'code': 'TEST',
|
||||
'name': 'Repair on order',
|
||||
'type': 'customer',
|
||||
'receipt_policy': 'ordered',
|
||||
'repair_type': 'ordered',
|
||||
'in_route_id': cls.rma_route_cust.id,
|
||||
'out_route_id': cls.rma_route_cust.id,
|
||||
})
|
||||
|
||||
# Create products
|
||||
cls.product_1 = cls.product_obj.create({
|
||||
'name': 'Test Product 1',
|
||||
'type': 'product',
|
||||
'list_price': 100.0,
|
||||
'rma_customer_operation_id': cls.operation_1.id,
|
||||
})
|
||||
cls.product_2 = cls.product_obj.create({
|
||||
'name': 'Test Product 2',
|
||||
'type': 'product',
|
||||
'list_price': 150.0,
|
||||
'rma_customer_operation_id': cls.operation_2.id,
|
||||
})
|
||||
|
||||
# Create Invoices:
|
||||
customer_account = cls.acc_obj.search(
|
||||
[('user_type_id', '=', receivable_type.id)], limit=1).id
|
||||
cls.inv_customer = cls.inv_obj.create({
|
||||
'partner_id': customer1.id,
|
||||
'account_id': customer_account,
|
||||
'type': 'out_invoice',
|
||||
})
|
||||
cls.inv_line_1 = cls.invl_obj.create({
|
||||
'name': cls.product_1.name,
|
||||
'product_id': cls.product_1.id,
|
||||
'quantity': 12.0,
|
||||
'price_unit': 100.0,
|
||||
'invoice_id': cls.inv_customer.id,
|
||||
'uom_id': cls.product_1.uom_id.id,
|
||||
'account_id': customer_account,
|
||||
})
|
||||
cls.inv_line_2 = cls.invl_obj.create({
|
||||
'name': cls.product_2.name,
|
||||
'product_id': cls.product_2.id,
|
||||
'quantity': 15.0,
|
||||
'price_unit': 150.0,
|
||||
'invoice_id': cls.inv_customer.id,
|
||||
'uom_id': cls.product_2.uom_id.id,
|
||||
'account_id': customer_account,
|
||||
})
|
||||
|
||||
def test_01_add_from_invoice_customer(self):
|
||||
"""Test wizard to create RMA from a customer invoice."""
|
||||
add_inv = self.rma_add_invoice_wiz.with_context({
|
||||
'customer': True,
|
||||
'active_ids': self.rma_group_customer.id,
|
||||
'active_model': 'rma.order',
|
||||
}).create({
|
||||
'invoice_line_ids':
|
||||
[(6, 0, self.inv_customer.invoice_line_ids.ids)],
|
||||
})
|
||||
add_inv.add_lines()
|
||||
self.assertEqual(len(self.rma_group_customer.rma_line_ids), 2)
|
||||
rma_1 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_1)
|
||||
rma_1.repair_type = self.operation_1.repair_type
|
||||
self.assertEquals(rma_1.operation_id, self.operation_1,
|
||||
"Operation should be operation_1")
|
||||
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_2)
|
||||
rma_2.repair_type = self.operation_2.repair_type
|
||||
self.assertEquals(rma_2.operation_id, self.operation_2,
|
||||
"Operation should be operation_2")
|
||||
|
||||
def test_02_rma_repair_operation(self):
|
||||
"""Test RMA quantities using repair operations."""
|
||||
# Received repair_type:
|
||||
rma_1 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_1)
|
||||
self.assertEquals(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")
|
||||
# Ordered repair_type:
|
||||
rma_2 = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_2)
|
||||
self.assertEquals(rma_2.operation_id.repair_type, 'ordered',
|
||||
"Incorrect Repair operation")
|
||||
self.assertEqual(rma_2.qty_to_repair, 15.0)
|
||||
|
||||
def test_03_create_repair_order(self):
|
||||
"""Generate a Repair Order from a customer RMA."""
|
||||
rma = self.rma_group_customer.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_2)
|
||||
rma.action_rma_to_approve()
|
||||
rma.action_rma_approve()
|
||||
self.assertEqual(rma.repair_count, 0)
|
||||
self.assertEqual(rma.qty_to_repair, 15.0)
|
||||
self.assertEqual(rma.qty_repaired, 0.0)
|
||||
make_repair = self.rma_make_repair_wiz.with_context({
|
||||
'customer': True,
|
||||
'active_ids': rma.ids,
|
||||
'active_model': 'rma.order.line',
|
||||
}).create({
|
||||
'description': 'Test refund',
|
||||
})
|
||||
make_repair.make_repair_order()
|
||||
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)
|
||||
16
rma_repair/views/repair_view.xml
Normal file
16
rma_repair/views/repair_view.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_repair_order_form" model="ir.ui.view">
|
||||
<field name="name">repair.order.form rma_repair</field>
|
||||
<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="rma_line_id"/>
|
||||
<field name="under_warranty"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
26
rma_repair/views/rma_operation_view.xml
Normal file
26
rma_repair/views/rma_operation_view.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="rma_operation_tree" model="ir.ui.view">
|
||||
<field name="name">rma.operation.tree - rma_repair</field>
|
||||
<field name="model">rma.operation</field>
|
||||
<field name="inherit_id" ref="rma.rma_operation_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="repair_type"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="rma_operation_form" model="ir.ui.view">
|
||||
<field name="name">rma.operation.form - rma_repair</field>
|
||||
<field name="model">rma.operation</field>
|
||||
<field name="inherit_id" ref="rma.rma_operation_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="repair_type"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
50
rma_repair/views/rma_order_line_view.xml
Normal file
50
rma_repair/views/rma_order_line_view.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_line_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.form - rma_repair</field>
|
||||
<field name="model">rma.order.line</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<div name='button_box' position="inside">
|
||||
<button type="object" name="action_view_repair_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-strikethrough"
|
||||
groups="stock.group_stock_user">
|
||||
<field name="repair_count" widget="statinfo"
|
||||
string="Repair Orders"/>
|
||||
</button>
|
||||
</div>
|
||||
<group name="quantities" position="inside">
|
||||
<group>
|
||||
<field name="qty_to_repair"/>
|
||||
<field name="qty_repaired"/>
|
||||
</group>
|
||||
</group>
|
||||
<field name="delivery_policy" position="after">
|
||||
<field name="repair_type"/>
|
||||
</field>
|
||||
<notebook position="inside">
|
||||
<page name="repair" string="Repair Orders">
|
||||
<field name="repair_ids" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_rma_line_button_repair_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.line.form - rma_repair</field>
|
||||
<field name="model">rma.order.line</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_line_button_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<header position="inside">
|
||||
<button name="%(action_rma_order_line_make_repair)d"
|
||||
states="approved"
|
||||
string="Create Repair Order"
|
||||
class="oe_highlight"
|
||||
type="action"/>
|
||||
</header>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
21
rma_repair/views/rma_order_view.xml
Normal file
21
rma_repair/views/rma_order_view.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.form - rma_repair</field>
|
||||
<field name="model">rma.order</field>
|
||||
<field name="inherit_id" ref="rma.view_rma_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<button type="object" name="action_view_repair_order"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
groups="stock.group_stock_user">
|
||||
<field name="repair_count" widget="statinfo"
|
||||
string="Repair Orders"/>
|
||||
</button>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
3
rma_repair/wizards/__init__.py
Normal file
3
rma_repair/wizards/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from . import rma_order_line_make_repair
|
||||
167
rma_repair/wizards/rma_order_line_make_repair.py
Normal file
167
rma_repair/wizards/rma_order_line_make_repair.py
Normal file
@@ -0,0 +1,167 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
|
||||
|
||||
import odoo.addons.decimal_precision as dp
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaLineMakeRepair(models.TransientModel):
|
||||
_name = "rma.order.line.make.repair"
|
||||
_description = "Make Repair Order from RMA Line"
|
||||
|
||||
item_ids = fields.One2many(
|
||||
comodel_name='rma.order.line.make.repair.item',
|
||||
inverse_name='wiz_id', string='Items')
|
||||
|
||||
@api.model
|
||||
def _prepare_item(self, line):
|
||||
if line.product_id.refurbish_product_id:
|
||||
to_refurbish = True
|
||||
refurbish_product_id = line.product_id.refurbish_product_id.id
|
||||
else:
|
||||
to_refurbish = refurbish_product_id = False
|
||||
return {
|
||||
'line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
'product_qty': line.qty_to_repair,
|
||||
'rma_id': line.rma_id.id,
|
||||
'out_route_id': line.out_route_id.id,
|
||||
'product_uom_id': line.uom_id.id,
|
||||
'partner_id': line.partner_id.id,
|
||||
'to_refurbish': to_refurbish,
|
||||
'refurbish_product_id': refurbish_product_id,
|
||||
'location_id': line.location_id.id,
|
||||
'location_dest_id': line.location_id.id,
|
||||
'invoice_method': 'after_repair',
|
||||
}
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(RmaLineMakeRepair, self).default_get(
|
||||
fields)
|
||||
rma_line_obj = self.env['rma.order.line']
|
||||
rma_line_ids = self.env.context['active_ids'] or []
|
||||
active_model = self.env.context['active_model']
|
||||
|
||||
if not rma_line_ids:
|
||||
return res
|
||||
assert active_model == 'rma.order.line', 'Bad context propagation'
|
||||
items = []
|
||||
lines = rma_line_obj.browse(rma_line_ids)
|
||||
for line in lines:
|
||||
items.append([0, 0, self._prepare_item(line)])
|
||||
res['item_ids'] = items
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def make_repair_order(self):
|
||||
res = []
|
||||
repair_obj = self.env['repair.order']
|
||||
for item in self.item_ids:
|
||||
rma_line = item.line_id
|
||||
data = item._prepare_repair_order(rma_line)
|
||||
repair = repair_obj.create(data)
|
||||
res.append(repair.id)
|
||||
return {
|
||||
'domain': [('id', 'in', res)],
|
||||
'name': _('Repairs'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'repair.order',
|
||||
'view_id': False,
|
||||
'context': False,
|
||||
'type': 'ir.actions.act_window'
|
||||
}
|
||||
|
||||
|
||||
class RmaLineMakeRepairItem(models.TransientModel):
|
||||
_name = "rma.order.line.make.repair.item"
|
||||
_description = "RMA Line Make Repair Item"
|
||||
|
||||
@api.constrains('product_qty')
|
||||
def _check_prodcut_qty(self):
|
||||
for rec in self:
|
||||
if rec.product_qty <= 0.0:
|
||||
raise ValidationError(_('Quantity must be positive.'))
|
||||
|
||||
@api.onchange('to_refurbish')
|
||||
def _onchange_to_refurbish(self):
|
||||
if self.to_refurbish:
|
||||
self.refurbish_product_id = self.product_id.refurbish_product_id
|
||||
else:
|
||||
self.refurbish_product_id = False
|
||||
|
||||
wiz_id = fields.Many2one(
|
||||
comodel_name='rma.order.line.make.repair', string='Wizard',
|
||||
ondelete='cascade',
|
||||
)
|
||||
line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA',
|
||||
required=True,
|
||||
)
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', related='line_id.rma_id',
|
||||
string='RMA Order',
|
||||
)
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product', string='Product', readonly=True,
|
||||
)
|
||||
product_qty = fields.Float(
|
||||
string='Quantity to repair', digits=dp.get_precision('Product UoS'),
|
||||
)
|
||||
product_uom_id = fields.Many2one(
|
||||
comodel_name='uom.uom', string='UoM', readonly=True,
|
||||
)
|
||||
out_route_id = fields.Many2one(
|
||||
comodel_name='stock.location.route', string='Outbound Route',
|
||||
domain=[('rma_selectable', '=', True)],
|
||||
)
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Customer', required=False,
|
||||
domain=[('customer', '=', True)], readonly=True,
|
||||
)
|
||||
location_id = fields.Many2one(
|
||||
comodel_name="stock.location", string="Location", required=True,
|
||||
)
|
||||
location_dest_id = fields.Many2one(
|
||||
comodel_name="stock.location", string="Destination location",
|
||||
required=True,
|
||||
)
|
||||
to_refurbish = fields.Boolean(string="To Refurbish?")
|
||||
refurbish_product_id = fields.Many2one(
|
||||
comodel_name="product.product", string="Refurbished Product",
|
||||
)
|
||||
invoice_method = fields.Selection(
|
||||
string="Invoice Method", 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.",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _prepare_repair_order(self, rma_line):
|
||||
location_dest = (self.location_dest_id if not self.to_refurbish else
|
||||
rma_line.product_id.property_stock_refurbish)
|
||||
refurbish_location_dest_id = (self.location_dest_id.id if
|
||||
self.to_refurbish else False)
|
||||
return {
|
||||
'product_id': rma_line.product_id.id,
|
||||
'partner_id': rma_line.partner_id.id,
|
||||
'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,
|
||||
'location_dest_id': location_dest.id,
|
||||
'refurbish_location_dest_id': refurbish_location_dest_id,
|
||||
'refurbish_product_id': self.refurbish_product_id.id,
|
||||
'to_refurbish': self.to_refurbish,
|
||||
'invoice_method': self.invoice_method,
|
||||
'partner_invoice_id': rma_line.invoice_address_id.id,
|
||||
}
|
||||
52
rma_repair/wizards/rma_order_line_make_repair_view.xml
Normal file
52
rma_repair/wizards/rma_order_line_make_repair_view.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_order_line_make_repair" model="ir.ui.view">
|
||||
<field name="name">RMA Line Make Repair</field>
|
||||
<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 string="Details" editable="bottom" create="false">
|
||||
<field name="line_id" options="{'no_open': true}"/>
|
||||
<field name="product_id"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id" groups="uom.group_uom"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="to_refurbish"/>
|
||||
<field name="refurbish_product_id" attrs="{'required': [('to_refurbish', '=', True)]}"/>
|
||||
<field name="location_id" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="location_dest_id" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="invoice_method"/>
|
||||
</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>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_rma_order_line_make_repair"
|
||||
model="ir.actions.act_window">
|
||||
<field name="name">Create Repair</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">rma.order.line.make.repair</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="binding_model_id" ref="rma_repair.model_rma_order_line"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user