mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[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:
@@ -9,15 +9,16 @@ This module integrates Return Merchandise Authorizations (RMA) with invoices,
|
||||
allowing to:
|
||||
|
||||
#. Create complete RMA's using existing invoices as a reference.
|
||||
#. Create refunds from RMA.
|
||||
#. Create refunds from a RMA.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
RMA are accessible though Inventory menu. There's four menus, divided by type
|
||||
. Users can access to the list of RMA or RMA lines.
|
||||
RMA are accessible though Inventory menu. There's four menus, divided by type.
|
||||
Users can access to the list of RMA or RMA lines.
|
||||
|
||||
Create an RMA:
|
||||
|
||||
#. Select a partner. Fill the rma lines by selecting an invoice.
|
||||
#. Request approval and approve.
|
||||
#. Click on RMA Lines button.
|
||||
@@ -25,7 +26,6 @@ Create an RMA:
|
||||
Order, Create Refund".
|
||||
#. Go back to the RMA. Set the RMA to done if not further action is required.
|
||||
|
||||
|
||||
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,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
@@ -43,7 +42,7 @@ Contributors
|
||||
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Aaron Henriquez <ahenriquez@eficent.com>
|
||||
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
'website': 'http://www.github.com/OCA/rma',
|
||||
'depends': ['account', 'rma'],
|
||||
'demo': ['demo/rma_operation.xml'],
|
||||
'data': ['views/rma_order_view.xml',
|
||||
'data': [
|
||||
'views/rma_order_view.xml',
|
||||
'views/rma_operation_view.xml',
|
||||
'views/rma_order_line_view.xml',
|
||||
'views/invoice_view.xml',
|
||||
|
||||
@@ -6,34 +6,25 @@ from openerp import api, fields, models
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
|
||||
_inherit = "account.invoice"
|
||||
|
||||
@api.one
|
||||
def _compute_rma_count(self):
|
||||
rma_list = []
|
||||
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)))
|
||||
for inv in self:
|
||||
rmas = self.mapped('invoice_line_ids.rma_line_ids.rma_id')
|
||||
inv.rma_count = len(rmas)
|
||||
|
||||
rma_count = fields.Integer(compute=_compute_rma_count,
|
||||
string='# of RMA',
|
||||
copy=False)
|
||||
rma_count = fields.Integer(
|
||||
compute=_compute_rma_count, string='# of RMA')
|
||||
|
||||
@api.multi
|
||||
def action_view_rma_supplier(self):
|
||||
action = self.env.ref('rma.action_rma_supplier')
|
||||
result = action.read()[0]
|
||||
rma_list = []
|
||||
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)))
|
||||
rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids
|
||||
# choose the view_mode accordingly
|
||||
if len(rma_list) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(rma_list) + ")]"
|
||||
result['domain'] = [('id', 'in', rma_list)]
|
||||
elif len(rma_list) == 1:
|
||||
res = self.env.ref('rma.view_rma_supplier_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
@@ -41,18 +32,13 @@ class AccountInvoice(models.Model):
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def action_view_rma(self):
|
||||
def action_view_rma_customer(self):
|
||||
action = self.env.ref('rma.action_rma_customer')
|
||||
result = action.read()[0]
|
||||
rma_list = []
|
||||
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)))
|
||||
rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids
|
||||
# choose the view_mode accordingly
|
||||
if len(rma_list) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(rma_list) + ")]"
|
||||
result['domain'] = [('id', 'in', rma_list)]
|
||||
elif len(rma_list) == 1:
|
||||
res = self.env.ref('rma.view_rma_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
@@ -61,20 +47,16 @@ class AccountInvoice(models.Model):
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
|
||||
_inherit = "account.invoice.line"
|
||||
|
||||
@api.multi
|
||||
def _compute_rma_count(self):
|
||||
rma_list = []
|
||||
for invl in self:
|
||||
for rmal in invl.rma_line_ids:
|
||||
rma_list.append(rmal.rma_id.id)
|
||||
invl.rma_count = len(list(set(rma_list)))
|
||||
rma_lines = invl.mapped('rma_line_ids')
|
||||
invl.rma_line_count = len(rma_lines)
|
||||
|
||||
rma_count = fields.Integer(compute=_compute_rma_count,
|
||||
string='# of RMA',
|
||||
copy=False)
|
||||
rma_line_count = fields.Integer(
|
||||
compute=_compute_rma_count, string='# of RMA')
|
||||
rma_line_ids = fields.One2many(
|
||||
comodel_name='rma.order.line', inverse_name='invoice_line_id',
|
||||
string="RMA", readonly=True,
|
||||
|
||||
@@ -10,31 +10,23 @@ class RmaOrder(models.Model):
|
||||
@api.multi
|
||||
def _compute_invoice_refund_count(self):
|
||||
for rec in self:
|
||||
invoice_list = []
|
||||
for line in rec.rma_line_ids:
|
||||
for refund in line.refund_line_ids:
|
||||
invoice_list.append(refund.invoice_id.id)
|
||||
rec.invoice_refund_count = len(list(set(invoice_list)))
|
||||
invoices = rec.mapped(
|
||||
'rma_line_ids.refund_line_ids.invoice_id')
|
||||
rec.invoice_refund_count = len(invoices)
|
||||
|
||||
@api.multi
|
||||
def _compute_invoice_count(self):
|
||||
for rec in self:
|
||||
invoice_list = []
|
||||
for line in rec.rma_line_ids:
|
||||
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)))
|
||||
invoices = rec.mapped('rma_line_ids.invoice_id')
|
||||
rec.invoice_count = len(invoices)
|
||||
|
||||
add_invoice_id = fields.Many2one('account.invoice', string='Add Invoice',
|
||||
ondelete='set null', readonly=True,
|
||||
states={'draft': [('readonly', False)]})
|
||||
invoice_refund_count = fields.Integer(
|
||||
compute=_compute_invoice_refund_count,
|
||||
string='# of Refunds',
|
||||
copy=False)
|
||||
invoice_count = fields.Integer(compute=_compute_invoice_count,
|
||||
string='# of Incoming Shipments',
|
||||
copy=False)
|
||||
compute=_compute_invoice_refund_count, string='# of Refunds')
|
||||
invoice_count = fields.Integer(
|
||||
compute=_compute_invoice_count, string='# of Invoices')
|
||||
|
||||
def _prepare_rma_line_from_inv_line(self, line):
|
||||
if self.type == 'customer':
|
||||
@@ -94,22 +86,13 @@ class RmaOrder(models.Model):
|
||||
|
||||
@api.multi
|
||||
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')
|
||||
result = action.read()[0]
|
||||
invoice_list = []
|
||||
for line in self.rma_line_ids:
|
||||
for refund in line.refund_line_ids:
|
||||
invoice_list.append(refund.invoice_id.id)
|
||||
invoice_ids = list(set(invoice_list))
|
||||
invoice_ids = self.mapped(
|
||||
'rma_line_ids.refund_line_ids.invoice_id').ids
|
||||
# choose the view_mode accordingly
|
||||
if len(invoice_ids) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(invoice_ids) + ")]"
|
||||
result['domain'] = [('id', 'in', invoice_ids)]
|
||||
elif len(invoice_ids) == 1:
|
||||
res = self.env.ref('account.invoice_supplier_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
@@ -123,14 +106,10 @@ class RmaOrder(models.Model):
|
||||
else:
|
||||
action = self.env.ref('account.action_invoice_tree')
|
||||
result = action.read()[0]
|
||||
invoice_list = []
|
||||
for line in self.rma_line_ids:
|
||||
invoice_list.append(line.invoice_id.id)
|
||||
invoice_ids = list(set(invoice_list))
|
||||
invoice_ids = self.mapped('rma_line_ids.invoice_id').ids
|
||||
# choose the view_mode accordingly
|
||||
if len(invoice_ids) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(invoice_ids) + ")]"
|
||||
result['domain'] = [('id', 'in', invoice_ids)]
|
||||
elif len(invoice_ids) == 1:
|
||||
if self.type == "supplier":
|
||||
res = self.env.ref('account.invoice_supplier_form', False)
|
||||
|
||||
@@ -11,10 +11,10 @@ class RmaOrderLine(models.Model):
|
||||
|
||||
@api.model
|
||||
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:
|
||||
return self.env['res.partner'].browse(partner_id)
|
||||
return False
|
||||
return self.env['res.partner']
|
||||
|
||||
@api.multi
|
||||
@api.depends('refund_line_ids', 'refund_line_ids.invoice_id.state',
|
||||
@@ -46,9 +46,8 @@ class RmaOrderLine(models.Model):
|
||||
default=_default_invoice_address,
|
||||
help="Invoice address for current rma order.")
|
||||
|
||||
refund_count = fields.Integer(compute=_compute_refund_count,
|
||||
string='# of Refunds', copy=False, default=0)
|
||||
|
||||
refund_count = fields.Integer(
|
||||
compute=_compute_refund_count, string='# of Refunds', default=0)
|
||||
invoice_line_id = fields.Many2one('account.invoice.line',
|
||||
string='Invoice Line',
|
||||
ondelete='restrict',
|
||||
@@ -118,13 +117,10 @@ class RmaOrderLine(models.Model):
|
||||
def action_view_refunds(self):
|
||||
action = self.env.ref('account.action_invoice_tree2')
|
||||
result = action.read()[0]
|
||||
invoice_ids = []
|
||||
for inv_line in self.refund_line_ids:
|
||||
invoice_ids.append(inv_line.invoice_id.id)
|
||||
invoice_ids= self.mapped('refund_line_ids.invoice_id').ids
|
||||
# choose the view_mode accordingly
|
||||
if len(invoice_ids) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(invoice_ids) + ")]"
|
||||
result['domain'] = [('id', 'in', invoice_ids)]
|
||||
elif len(invoice_ids) == 1:
|
||||
res = self.env.ref('account.invoice_supplier_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<field name="number" position="before">
|
||||
<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"
|
||||
icon="fa-eject"
|
||||
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user">
|
||||
@@ -48,10 +48,10 @@
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<field name="name" position="after">
|
||||
<field name="rma_count" invisible="1"/>
|
||||
<field name="rma_line_count" invisible="1"/>
|
||||
<field name="rma_line_id"
|
||||
string="RMA originated"/>
|
||||
<notebook attrs="{'invisible': [('rma_count', '=', 0)]}">
|
||||
string="RMA line originated"/>
|
||||
<notebook attrs="{'invisible': [('rma_line_count', '=', 0)]}">
|
||||
<page string="RMA Lines">
|
||||
<field name="rma_line_ids"/>
|
||||
</page>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<data>
|
||||
|
||||
<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="inherit_id" ref="rma.view_rma_form"/>
|
||||
<field name="arch" type="xml">
|
||||
@@ -36,7 +36,7 @@
|
||||
<record id="view_rma_supplier_form" model="ir.ui.view">
|
||||
<field name="name">rma.order.supplier.form</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">
|
||||
<button name="action_view_out_shipments"
|
||||
position="after">
|
||||
|
||||
@@ -6,13 +6,13 @@ from openerp import api, fields, models
|
||||
from openerp.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaAddinvoice(models.TransientModel):
|
||||
class RmaAddInvoice(models.TransientModel):
|
||||
_name = 'rma_add_invoice'
|
||||
_description = 'Wizard to add rma lines'
|
||||
|
||||
@api.model
|
||||
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_id = self.env.context['active_ids'] or []
|
||||
active_model = self.env.context['active_model']
|
||||
@@ -42,19 +42,6 @@ class RmaAddinvoice(models.TransientModel):
|
||||
else:
|
||||
operation = line.product_id.rma_supplier_operation_id or \
|
||||
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:
|
||||
operation = self.env['rma.operation'].search(
|
||||
[('type', '=', self.rma_id.type)], limit=1)
|
||||
@@ -73,9 +60,19 @@ class RmaAddinvoice(models.TransientModel):
|
||||
if not warehouse:
|
||||
raise ValidationError("Please define a warehouse with a"
|
||||
" default rma location")
|
||||
data.update(
|
||||
{'receipt_policy': operation.receipt_policy,
|
||||
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,
|
||||
'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,
|
||||
@@ -84,8 +81,8 @@ class RmaAddinvoice(models.TransientModel):
|
||||
'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)
|
||||
})
|
||||
warehouse.lot_rma_id.id),
|
||||
}
|
||||
return data
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<odoo>
|
||||
|
||||
<record id="view_rma_add_invoice" model="ir.ui.view">
|
||||
<field name="name">rma.add.invoice</field>
|
||||
<field name="model">rma_add_invoice</field>
|
||||
@@ -104,7 +105,7 @@
|
||||
</record>
|
||||
|
||||
<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="inherit_id" ref="rma.view_rma_form"/>
|
||||
<field name="arch" type="xml">
|
||||
@@ -118,7 +119,7 @@
|
||||
</record>
|
||||
|
||||
<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="inherit_id" ref="rma.view_rma_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
@@ -131,5 +132,4 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -66,8 +66,7 @@ class RmaRefund(models.TransientModel):
|
||||
description = fields.Char(string='Reason', required=True,
|
||||
default=_get_reason)
|
||||
item_ids = fields.One2many(
|
||||
'rma.refund.item',
|
||||
'wiz_id', string='Items')
|
||||
comodel_name='rma.refund.item', inverse_name='wiz_id', string='Items')
|
||||
|
||||
@api.multi
|
||||
def compute_refund(self):
|
||||
@@ -186,8 +185,7 @@ class RmaRefundItem(models.TransientModel):
|
||||
_description = "RMA Lines to refund"
|
||||
|
||||
wiz_id = fields.Many2one(
|
||||
'rma.refund',
|
||||
string='Wizard', required=True)
|
||||
comodel_name='rma.refund', string='Wizard', required=True)
|
||||
line_id = fields.Many2one('rma.order.line',
|
||||
string='RMA order Line',
|
||||
required=True,
|
||||
@@ -204,13 +202,14 @@ class RmaRefundItem(models.TransientModel):
|
||||
string='Quantity Ordered', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
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(
|
||||
string='Quantity To Refund',
|
||||
digits=dp.get_precision('Product Unit of Measure'))
|
||||
uom_id = fields.Many2one('product.uom', string='Unit of Measure',
|
||||
readonly=True)
|
||||
refund_policy = fields.Selection([
|
||||
refund_policy = fields.Selection(selection=[
|
||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
||||
('received', 'Based on Received Quantities')],
|
||||
string="Refund Policy")
|
||||
|
||||
Reference in New Issue
Block a user