[9.0][IMP] rma_account:

* remove unneded copy attributes.
* simplify action_view methods.
* fix wrong naming.
* fix misplaced views.
* fix wrong count and view actions for rma.orders in invoices.
* fix error when installing the module.
* remove unneded data update when preparing rma lines from invoice lines.
* minor extra fixes.
This commit is contained in:
lreficent
2017-08-25 12:22:53 +02:00
committed by ahenriquez
parent f3851dc8fa
commit 56dee1e9b3
10 changed files with 86 additions and 133 deletions

View File

@@ -6,18 +6,19 @@ RMA Account
=========== ===========
This module integrates Return Merchandise Authorizations (RMA) with invoices, This module integrates Return Merchandise Authorizations (RMA) with invoices,
allowing to: allowing to:
#. Create complete RMA's using existing invoices as a reference. #. Create complete RMA's using existing invoices as a reference.
#. Create refunds from RMA. #. Create refunds from a RMA.
Usage Usage
===== =====
RMA are accessible though Inventory menu. There's four menus, divided by type RMA are accessible though Inventory menu. There's four menus, divided by type.
. Users can access to the list of RMA or RMA lines. Users can access to the list of RMA or RMA lines.
Create an RMA: Create an RMA:
#. Select a partner. Fill the rma lines by selecting an invoice. #. Select a partner. Fill the rma lines by selecting an invoice.
#. Request approval and approve. #. Request approval and approve.
#. Click on RMA Lines button. #. Click on RMA Lines button.
@@ -25,7 +26,6 @@ Create an RMA:
Order, Create Refund". Order, Create Refund".
#. Go back to the RMA. Set the RMA to done if not further action is required. #. Go back to the RMA. Set the RMA to done if not further action is required.
Bug Tracker Bug Tracker
=========== ===========
@@ -34,7 +34,6 @@ Bugs are tracked on `GitHub Issues
check there if your issue has already been reported. If you spotted it first, 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. help us smashing it by providing a detailed and welcomed feedback.
Credits Credits
======= =======
@@ -43,7 +42,7 @@ Contributors
* Jordi Ballester Alomar <jordi.ballester@eficent.com> * Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Aaron Henriquez <ahenriquez@eficent.com> * Aaron Henriquez <ahenriquez@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
Maintainer Maintainer
---------- ----------

View File

@@ -12,13 +12,14 @@
'website': 'http://www.github.com/OCA/rma', 'website': 'http://www.github.com/OCA/rma',
'depends': ['account', 'rma'], 'depends': ['account', 'rma'],
'demo': ['demo/rma_operation.xml'], 'demo': ['demo/rma_operation.xml'],
'data': ['views/rma_order_view.xml', 'data': [
'views/rma_operation_view.xml', 'views/rma_order_view.xml',
'views/rma_order_line_view.xml', 'views/rma_operation_view.xml',
'views/invoice_view.xml', 'views/rma_order_line_view.xml',
'wizards/rma_add_invoice.xml', 'views/invoice_view.xml',
'wizards/rma_refund.xml', 'wizards/rma_add_invoice.xml',
], 'wizards/rma_refund.xml',
],
'installable': True, 'installable': True,
'auto_install': True, 'auto_install': True,
} }

View File

@@ -6,34 +6,25 @@ from openerp import api, fields, models
class AccountInvoice(models.Model): class AccountInvoice(models.Model):
_inherit = "account.invoice" _inherit = "account.invoice"
@api.one @api.one
def _compute_rma_count(self): def _compute_rma_count(self):
rma_list = [] for inv in self:
for invl in self.invoice_line_ids: rmas = self.mapped('invoice_line_ids.rma_line_ids.rma_id')
for rmal in invl.rma_line_ids: inv.rma_count = len(rmas)
rma_list.append(rmal.rma_id.id)
self.rma_count = len(list(set(rma_list)))
rma_count = fields.Integer(compute=_compute_rma_count, rma_count = fields.Integer(
string='# of RMA', compute=_compute_rma_count, string='# of RMA')
copy=False)
@api.multi @api.multi
def action_view_rma_supplier(self): def action_view_rma_supplier(self):
action = self.env.ref('rma.action_rma_supplier') action = self.env.ref('rma.action_rma_supplier')
result = action.read()[0] result = action.read()[0]
rma_list = [] rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids
for invl in self.invoice_line_ids:
for rmal in invl.rma_line_ids:
rma_list.append(rmal.rma_id.id)
self.rma_count = len(list(set(rma_list)))
# choose the view_mode accordingly # choose the view_mode accordingly
if len(rma_list) != 1: if len(rma_list) != 1:
result['domain'] = "[('id', 'in', " + \ result['domain'] = [('id', 'in', rma_list)]
str(rma_list) + ")]"
elif len(rma_list) == 1: elif len(rma_list) == 1:
res = self.env.ref('rma.view_rma_supplier_form', False) res = self.env.ref('rma.view_rma_supplier_form', False)
result['views'] = [(res and res.id or False, 'form')] result['views'] = [(res and res.id or False, 'form')]
@@ -41,18 +32,13 @@ class AccountInvoice(models.Model):
return result return result
@api.multi @api.multi
def action_view_rma(self): def action_view_rma_customer(self):
action = self.env.ref('rma.action_rma_customer') action = self.env.ref('rma.action_rma_customer')
result = action.read()[0] result = action.read()[0]
rma_list = [] rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids
for invl in self.invoice_line_ids:
for rmal in invl.rma_line_ids:
rma_list.append(rmal.rma_id.id)
self.rma_count = len(list(set(rma_list)))
# choose the view_mode accordingly # choose the view_mode accordingly
if len(rma_list) != 1: if len(rma_list) != 1:
result['domain'] = "[('id', 'in', " + \ result['domain'] = [('id', 'in', rma_list)]
str(rma_list) + ")]"
elif len(rma_list) == 1: elif len(rma_list) == 1:
res = self.env.ref('rma.view_rma_form', False) res = self.env.ref('rma.view_rma_form', False)
result['views'] = [(res and res.id or False, 'form')] result['views'] = [(res and res.id or False, 'form')]
@@ -61,20 +47,16 @@ class AccountInvoice(models.Model):
class AccountInvoiceLine(models.Model): class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line" _inherit = "account.invoice.line"
@api.multi @api.multi
def _compute_rma_count(self): def _compute_rma_count(self):
rma_list = []
for invl in self: for invl in self:
for rmal in invl.rma_line_ids: rma_lines = invl.mapped('rma_line_ids')
rma_list.append(rmal.rma_id.id) invl.rma_line_count = len(rma_lines)
invl.rma_count = len(list(set(rma_list)))
rma_count = fields.Integer(compute=_compute_rma_count, rma_line_count = fields.Integer(
string='# of RMA', compute=_compute_rma_count, string='# of RMA')
copy=False)
rma_line_ids = fields.One2many( rma_line_ids = fields.One2many(
comodel_name='rma.order.line', inverse_name='invoice_line_id', comodel_name='rma.order.line', inverse_name='invoice_line_id',
string="RMA", readonly=True, string="RMA", readonly=True,

View File

@@ -10,31 +10,23 @@ class RmaOrder(models.Model):
@api.multi @api.multi
def _compute_invoice_refund_count(self): def _compute_invoice_refund_count(self):
for rec in self: for rec in self:
invoice_list = [] invoices = rec.mapped(
for line in rec.rma_line_ids: 'rma_line_ids.refund_line_ids.invoice_id')
for refund in line.refund_line_ids: rec.invoice_refund_count = len(invoices)
invoice_list.append(refund.invoice_id.id)
rec.invoice_refund_count = len(list(set(invoice_list)))
@api.multi @api.multi
def _compute_invoice_count(self): def _compute_invoice_count(self):
for rec in self: for rec in self:
invoice_list = [] invoices = rec.mapped('rma_line_ids.invoice_id')
for line in rec.rma_line_ids: rec.invoice_count = len(invoices)
if line.invoice_line_id and line.invoice_line_id.id:
invoice_list.append(line.invoice_line_id.invoice_id.id)
rec.invoice_count = len(list(set(invoice_list)))
add_invoice_id = fields.Many2one('account.invoice', string='Add Invoice', add_invoice_id = fields.Many2one('account.invoice', string='Add Invoice',
ondelete='set null', readonly=True, ondelete='set null', readonly=True,
states={'draft': [('readonly', False)]}) states={'draft': [('readonly', False)]})
invoice_refund_count = fields.Integer( invoice_refund_count = fields.Integer(
compute=_compute_invoice_refund_count, compute=_compute_invoice_refund_count, string='# of Refunds')
string='# of Refunds', invoice_count = fields.Integer(
copy=False) compute=_compute_invoice_count, string='# of Invoices')
invoice_count = fields.Integer(compute=_compute_invoice_count,
string='# of Incoming Shipments',
copy=False)
def _prepare_rma_line_from_inv_line(self, line): def _prepare_rma_line_from_inv_line(self, line):
if self.type == 'customer': if self.type == 'customer':
@@ -94,22 +86,13 @@ class RmaOrder(models.Model):
@api.multi @api.multi
def action_view_invoice_refund(self): def action_view_invoice_refund(self):
"""
This function returns an action that display existing vendor refund
bills of given purchase order id.
When only one found, show the vendor bill immediately.
"""
action = self.env.ref('account.action_invoice_tree2') action = self.env.ref('account.action_invoice_tree2')
result = action.read()[0] result = action.read()[0]
invoice_list = [] invoice_ids = self.mapped(
for line in self.rma_line_ids: 'rma_line_ids.refund_line_ids.invoice_id').ids
for refund in line.refund_line_ids:
invoice_list.append(refund.invoice_id.id)
invoice_ids = list(set(invoice_list))
# choose the view_mode accordingly # choose the view_mode accordingly
if len(invoice_ids) != 1: if len(invoice_ids) != 1:
result['domain'] = "[('id', 'in', " + \ result['domain'] = [('id', 'in', invoice_ids)]
str(invoice_ids) + ")]"
elif len(invoice_ids) == 1: elif len(invoice_ids) == 1:
res = self.env.ref('account.invoice_supplier_form', False) res = self.env.ref('account.invoice_supplier_form', False)
result['views'] = [(res and res.id or False, 'form')] result['views'] = [(res and res.id or False, 'form')]
@@ -123,14 +106,10 @@ class RmaOrder(models.Model):
else: else:
action = self.env.ref('account.action_invoice_tree') action = self.env.ref('account.action_invoice_tree')
result = action.read()[0] result = action.read()[0]
invoice_list = [] invoice_ids = self.mapped('rma_line_ids.invoice_id').ids
for line in self.rma_line_ids:
invoice_list.append(line.invoice_id.id)
invoice_ids = list(set(invoice_list))
# choose the view_mode accordingly # choose the view_mode accordingly
if len(invoice_ids) != 1: if len(invoice_ids) != 1:
result['domain'] = "[('id', 'in', " + \ result['domain'] = [('id', 'in', invoice_ids)]
str(invoice_ids) + ")]"
elif len(invoice_ids) == 1: elif len(invoice_ids) == 1:
if self.type == "supplier": if self.type == "supplier":
res = self.env.ref('account.invoice_supplier_form', False) res = self.env.ref('account.invoice_supplier_form', False)

View File

@@ -11,10 +11,10 @@ class RmaOrderLine(models.Model):
@api.model @api.model
def _default_invoice_address(self): def _default_invoice_address(self):
partner_id = self.env.context.get('partner_id', False) partner_id = self.env.context.get('partner_id')
if partner_id: if partner_id:
return self.env['res.partner'].browse(partner_id) return self.env['res.partner'].browse(partner_id)
return False return self.env['res.partner']
@api.multi @api.multi
@api.depends('refund_line_ids', 'refund_line_ids.invoice_id.state', @api.depends('refund_line_ids', 'refund_line_ids.invoice_id.state',
@@ -46,9 +46,8 @@ class RmaOrderLine(models.Model):
default=_default_invoice_address, default=_default_invoice_address,
help="Invoice address for current rma order.") help="Invoice address for current rma order.")
refund_count = fields.Integer(compute=_compute_refund_count, refund_count = fields.Integer(
string='# of Refunds', copy=False, default=0) compute=_compute_refund_count, string='# of Refunds', default=0)
invoice_line_id = fields.Many2one('account.invoice.line', invoice_line_id = fields.Many2one('account.invoice.line',
string='Invoice Line', string='Invoice Line',
ondelete='restrict', ondelete='restrict',
@@ -118,13 +117,10 @@ class RmaOrderLine(models.Model):
def action_view_refunds(self): def action_view_refunds(self):
action = self.env.ref('account.action_invoice_tree2') action = self.env.ref('account.action_invoice_tree2')
result = action.read()[0] result = action.read()[0]
invoice_ids = [] invoice_ids= self.mapped('refund_line_ids.invoice_id').ids
for inv_line in self.refund_line_ids:
invoice_ids.append(inv_line.invoice_id.id)
# choose the view_mode accordingly # choose the view_mode accordingly
if len(invoice_ids) != 1: if len(invoice_ids) != 1:
result['domain'] = "[('id', 'in', " + \ result['domain'] = [('id', 'in', invoice_ids)]
str(invoice_ids) + ")]"
elif len(invoice_ids) == 1: elif len(invoice_ids) == 1:
res = self.env.ref('account.invoice_supplier_form', False) res = self.env.ref('account.invoice_supplier_form', False)
result['views'] = [(res and res.id or False, 'form')] result['views'] = [(res and res.id or False, 'form')]

View File

@@ -9,7 +9,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="number" position="before"> <field name="number" position="before">
<div class="oe_button_box" attrs="{'invisible': [('rma_count', '=', 0)]}"> <div class="oe_button_box" attrs="{'invisible': [('rma_count', '=', 0)]}">
<button type="object" name="action_view_rma" <button type="object" name="action_view_rma_customer"
class="oe_stat_button" class="oe_stat_button"
icon="fa-eject" icon="fa-eject"
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user"> groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
@@ -48,10 +48,10 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<data> <data>
<field name="name" position="after"> <field name="name" position="after">
<field name="rma_count" invisible="1"/> <field name="rma_line_count" invisible="1"/>
<field name="rma_line_id" <field name="rma_line_id"
string="RMA originated"/> string="RMA line originated"/>
<notebook attrs="{'invisible': [('rma_count', '=', 0)]}"> <notebook attrs="{'invisible': [('rma_line_count', '=', 0)]}">
<page string="RMA Lines"> <page string="RMA Lines">
<field name="rma_line_ids"/> <field name="rma_line_ids"/>
</page> </page>

View File

@@ -3,7 +3,7 @@
<data> <data>
<record id="view_rma_form" model="ir.ui.view"> <record id="view_rma_form" model="ir.ui.view">
<field name="name">rma.order.form</field> <field name="name">rma.order.form - rma_account</field>
<field name="model">rma.order</field> <field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_form"/> <field name="inherit_id" ref="rma.view_rma_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
@@ -36,7 +36,7 @@
<record id="view_rma_supplier_form" model="ir.ui.view"> <record id="view_rma_supplier_form" model="ir.ui.view">
<field name="name">rma.order.supplier.form</field> <field name="name">rma.order.supplier.form</field>
<field name="model">rma.order</field> <field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_form"/> <field name="inherit_id" ref="rma.view_rma_supplier_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<button name="action_view_out_shipments" <button name="action_view_out_shipments"
position="after"> position="after">

View File

@@ -6,13 +6,13 @@ from openerp import api, fields, models
from openerp.exceptions import ValidationError from openerp.exceptions import ValidationError
class RmaAddinvoice(models.TransientModel): class RmaAddInvoice(models.TransientModel):
_name = 'rma_add_invoice' _name = 'rma_add_invoice'
_description = 'Wizard to add rma lines' _description = 'Wizard to add rma lines'
@api.model @api.model
def default_get(self, fields): def default_get(self, fields):
res = super(RmaAddinvoice, self).default_get(fields) res = super(RmaAddInvoice, self).default_get(fields)
rma_obj = self.env['rma.order'] rma_obj = self.env['rma.order']
rma_id = self.env.context['active_ids'] or [] rma_id = self.env.context['active_ids'] or []
active_model = self.env.context['active_model'] active_model = self.env.context['active_model']
@@ -42,19 +42,6 @@ class RmaAddinvoice(models.TransientModel):
else: else:
operation = line.product_id.rma_supplier_operation_id or \ operation = line.product_id.rma_supplier_operation_id or \
line.product_id.categ_id.rma_supplier_operation_id line.product_id.categ_id.rma_supplier_operation_id
data = {
'invoice_line_id': line.id,
'product_id': line.product_id.id,
'origin': line.invoice_id.number,
'uom_id': line.uom_id.id,
'operation_id': operation.id,
'product_qty': line.quantity,
'price_unit': line.invoice_id.currency_id.compute(
line.price_unit, line.currency_id, round=False),
'delivery_address_id': line.invoice_id.partner_id.id,
'invoice_address_id': line.invoice_id.partner_id.id,
'rma_id': self.rma_id.id
}
if not operation: if not operation:
operation = self.env['rma.operation'].search( operation = self.env['rma.operation'].search(
[('type', '=', self.rma_id.type)], limit=1) [('type', '=', self.rma_id.type)], limit=1)
@@ -73,19 +60,29 @@ class RmaAddinvoice(models.TransientModel):
if not warehouse: if not warehouse:
raise ValidationError("Please define a warehouse with a" raise ValidationError("Please define a warehouse with a"
" default rma location") " default rma location")
data.update( data = {
{'receipt_policy': operation.receipt_policy, 'invoice_line_id': line.id,
'operation_id': operation.id, 'product_id': line.product_id.id,
'refund_policy': operation.refund_policy, 'origin': line.invoice_id.number,
'delivery_policy': operation.delivery_policy, 'uom_id': line.uom_id.id,
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id, 'operation_id': operation.id,
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id, 'product_qty': line.quantity,
'in_route_id': operation.in_route_id.id or route.id, 'price_unit': line.invoice_id.currency_id.compute(
'out_route_id': operation.out_route_id.id or route.id, line.price_unit, line.currency_id, round=False),
'location_id': (operation.location_id.id or 'delivery_address_id': line.invoice_id.partner_id.id,
operation.in_warehouse_id.lot_rma_id.id or 'invoice_address_id': line.invoice_id.partner_id.id,
warehouse.lot_rma_id.id) 'rma_id': self.rma_id.id,
}) 'receipt_policy': operation.receipt_policy,
'refund_policy': operation.refund_policy,
'delivery_policy': operation.delivery_policy,
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
'in_route_id': operation.in_route_id.id or route.id,
'out_route_id': operation.out_route_id.id or route.id,
'location_id': (operation.location_id.id or
operation.in_warehouse_id.lot_rma_id.id or
warehouse.lot_rma_id.id),
}
return data return data
@api.model @api.model

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<record id="view_rma_add_invoice" model="ir.ui.view"> <record id="view_rma_add_invoice" model="ir.ui.view">
<field name="name">rma.add.invoice</field> <field name="name">rma.add.invoice</field>
<field name="model">rma_add_invoice</field> <field name="model">rma_add_invoice</field>
@@ -104,7 +105,7 @@
</record> </record>
<record id="view_rma_add_invoice_form" model="ir.ui.view"> <record id="view_rma_add_invoice_form" model="ir.ui.view">
<field name="name">rma.order.line.form</field> <field name="name">rma.order.form - invoice wizard</field>
<field name="model">rma.order</field> <field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_form"/> <field name="inherit_id" ref="rma.view_rma_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
@@ -118,7 +119,7 @@
</record> </record>
<record id="view_rma_add_invoice_button_form" model="ir.ui.view"> <record id="view_rma_add_invoice_button_form" model="ir.ui.view">
<field name="name">rma.order.line.supplier.form</field> <field name="name">rma.order.supplier.form - invoice wizard</field>
<field name="model">rma.order</field> <field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_supplier_form"/> <field name="inherit_id" ref="rma.view_rma_supplier_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
@@ -131,5 +132,4 @@
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@@ -66,8 +66,7 @@ class RmaRefund(models.TransientModel):
description = fields.Char(string='Reason', required=True, description = fields.Char(string='Reason', required=True,
default=_get_reason) default=_get_reason)
item_ids = fields.One2many( item_ids = fields.One2many(
'rma.refund.item', comodel_name='rma.refund.item', inverse_name='wiz_id', string='Items')
'wiz_id', string='Items')
@api.multi @api.multi
def compute_refund(self): def compute_refund(self):
@@ -186,8 +185,7 @@ class RmaRefundItem(models.TransientModel):
_description = "RMA Lines to refund" _description = "RMA Lines to refund"
wiz_id = fields.Many2one( wiz_id = fields.Many2one(
'rma.refund', comodel_name='rma.refund', string='Wizard', required=True)
string='Wizard', required=True)
line_id = fields.Many2one('rma.order.line', line_id = fields.Many2one('rma.order.line',
string='RMA order Line', string='RMA order Line',
required=True, required=True,
@@ -204,13 +202,14 @@ class RmaRefundItem(models.TransientModel):
string='Quantity Ordered', copy=False, string='Quantity Ordered', copy=False,
digits=dp.get_precision('Product Unit of Measure'), digits=dp.get_precision('Product Unit of Measure'),
readonly=True) readonly=True)
invoice_address_id = fields.Many2one('res.partner', 'Invoice Address') invoice_address_id = fields.Many2one(
comodel_name='res.partner', string='Invoice Address')
qty_to_refund = fields.Float( qty_to_refund = fields.Float(
string='Quantity To Refund', string='Quantity To Refund',
digits=dp.get_precision('Product Unit of Measure')) digits=dp.get_precision('Product Unit of Measure'))
uom_id = fields.Many2one('product.uom', string='Unit of Measure', uom_id = fields.Many2one('product.uom', string='Unit of Measure',
readonly=True) readonly=True)
refund_policy = fields.Selection([ refund_policy = fields.Selection(selection=[
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
('received', 'Based on Received Quantities')], ('received', 'Based on Received Quantities')],
string="Refund Policy") string="Refund Policy")