mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[9.0][IMP] rma_sale:
* simplify actgion_view methods. * remove unneded copy and ondelete attributes. * Fix wizard to add rma lines from SO. * Update README and some strings.
This commit is contained in:
committed by
Jordi Ballester Alomar
parent
65826d753b
commit
444669ced6
@@ -1,26 +1,37 @@
|
||||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
|
||||
:alt: License LGPL-3
|
||||
|
||||
========
|
||||
RMA Sale
|
||||
========
|
||||
|
||||
This module allows you to:
|
||||
|
||||
# . Import sales order lines into RMA lines
|
||||
# . Create a sales order and/or sales order line from one or more RMA lines
|
||||
#. Import sales order lines into RMA lines
|
||||
#. Create a sales order and/or sales order line from one or more RMA lines
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Import existing sales order lines into an RMA
|
||||
---------------------------------------------
|
||||
**Import existing sales order lines into an RMA:**
|
||||
|
||||
This feature is useful when you create an RMA associated to a product that
|
||||
was shipped and you have as a reference the customer PO number.
|
||||
|
||||
#. Access to a customer RMA
|
||||
#. Press the button "Add from Sales Order"
|
||||
#. Access to a customer RMA.
|
||||
#. Fill the customer.
|
||||
#. Press the button *Add from Sales Order*.
|
||||
#. In the wizard add a sales order and click on *add item* to select the
|
||||
lines you want to add to the RMA.
|
||||
|
||||
**Create a sales order and/or sales order line from RMA lines:**
|
||||
|
||||
#. Go to a approved RMA line.
|
||||
#. Click on *Create a Sales Quotation*.
|
||||
#. In the wizard, select an *Existing Quotation to update* or leave it empty
|
||||
if you want to create a new one.
|
||||
#. Fill the quantity to sell in the lines.
|
||||
#. Hit *Create a Sales Quotation*.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
@@ -30,7 +41,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
|
||||
=======
|
||||
|
||||
@@ -39,7 +49,7 @@ Contributors
|
||||
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Aaron Henriquez <ahenriquez@eficent.com>
|
||||
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -9,15 +9,12 @@ class RmaOrder(models.Model):
|
||||
|
||||
@api.multi
|
||||
def _compute_sales_count(self):
|
||||
self.ensure_one()
|
||||
sales_list = []
|
||||
for rma_line in self.rma_line_ids:
|
||||
if rma_line.sale_line_id and rma_line.sale_line_id.id:
|
||||
sales_list.append(rma_line.sale_line_id.order_id.id)
|
||||
self.sale_count = len(list(set(sales_list)))
|
||||
for rma in self:
|
||||
sales = rma.mapped('rma_line_ids.sale_line_id.order_id')
|
||||
rma.sale_count = len(sales)
|
||||
|
||||
sale_count = fields.Integer(compute=_compute_sales_count,
|
||||
string='# of Sales', copy=False, default=0)
|
||||
sale_count = fields.Integer(
|
||||
compute=_compute_sales_count, string='# of Sales')
|
||||
|
||||
@api.model
|
||||
def _get_line_domain(self, rma_id, line):
|
||||
@@ -33,9 +30,6 @@ class RmaOrder(models.Model):
|
||||
def action_view_sale_order(self):
|
||||
action = self.env.ref('sale.action_quotations')
|
||||
result = action.read()[0]
|
||||
order_ids = []
|
||||
for rma_line in self.rma_line_ids:
|
||||
if rma_line.sale_line_id and rma_line.sale_line_id.id:
|
||||
order_ids.append(rma_line.sale_line_id.order_id.id)
|
||||
result['domain'] = [('id', 'in', order_ids)]
|
||||
so_ids = self.mapped('rma_line_ids.sale_line_id.order_id').ids
|
||||
result['domain'] = [('id', 'in', so_ids)]
|
||||
return result
|
||||
|
||||
@@ -29,48 +29,41 @@ class RmaOrderLine(models.Model):
|
||||
def _compute_qty_sold(self):
|
||||
self.qty_sold = self._get_rma_sold_qty()
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def _compute_sales_count(self):
|
||||
sales_list = []
|
||||
for sale_order_line in self.sale_line_ids:
|
||||
sales_list.append(sale_order_line.order_id.id)
|
||||
self.sales_count = len(list(set(sales_list)))
|
||||
for line in self:
|
||||
sales = line.mapped('sale_line_ids.order_id')
|
||||
line.sales_count = len(sales)
|
||||
|
||||
sale_line_id = fields.Many2one(comodel_name='sale.order.line',
|
||||
string='Originating Sales Order Line',
|
||||
ondelete='restrict')
|
||||
sale_line_ids = fields.One2many(comodel_name='sale.order.line',
|
||||
inverse_name='rma_line_id',
|
||||
string='Sales Order Lines', readonly=True,
|
||||
states={'draft': [('readonly', False)]},
|
||||
copy=False)
|
||||
sale_line_id = fields.Many2one(
|
||||
comodel_name='sale.order.line', string='Originating Sales Order Line',
|
||||
ondelete='restrict')
|
||||
sale_line_ids = fields.One2many(
|
||||
comodel_name='sale.order.line', inverse_name='rma_line_id',
|
||||
string='Sales Order Lines', readonly=True,
|
||||
states={'draft': [('readonly', False)]}, copy=False)
|
||||
qty_to_sell = fields.Float(
|
||||
string='Qty To Sell', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute=_compute_qty_to_sell,
|
||||
store=True)
|
||||
|
||||
qty_sold = fields.Float(
|
||||
string='Qty Sold', copy=False,
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
readonly=True, compute=_compute_qty_sold,
|
||||
store=True)
|
||||
|
||||
sale_type = fields.Selection([
|
||||
sale_type = fields.Selection(selection=[
|
||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
||||
('received', 'Based on Received Quantities')],
|
||||
string="Sale Policy", default='no', required=True)
|
||||
|
||||
sales_count = fields.Integer(compute=_compute_sales_count,
|
||||
string='# of Sales', copy=False, default=0)
|
||||
sales_count = fields.Integer(
|
||||
compute=_compute_sales_count, string='# of Sales')
|
||||
|
||||
@api.multi
|
||||
def action_view_sale_order(self):
|
||||
action = self.env.ref('sale.action_quotations')
|
||||
result = action.read()[0]
|
||||
order_ids = []
|
||||
for sale_line in self.sale_line_ids:
|
||||
order_ids.append(sale_line.order_id.id)
|
||||
order_ids = self.mapped('sale_line_ids.order_id').ids
|
||||
result['domain'] = [('id', 'in', order_ids)]
|
||||
return result
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ from openerp import api, fields, models
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
rma_line_id = fields.Many2one('rma.order.line', string='RMA',
|
||||
ondelete='restrict')
|
||||
rma_line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA', ondelete='restrict')
|
||||
|
||||
@api.multi
|
||||
def _prepare_order_line_procurement(self, group_id=False):
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<header position="inside">
|
||||
<button name="%(action_rma_order_line_make_sale_order)d" states="approved"
|
||||
string="Create Sale Quotation" class="oe_highlight"
|
||||
string="Create Sales Quotation" class="oe_highlight"
|
||||
type="action"/>
|
||||
</header>
|
||||
</field>
|
||||
@@ -83,7 +83,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<header position="inside">
|
||||
<button name="%(action_rma_order_line_make_sale_order)d" states="approved"
|
||||
string="Create Sale Quotation" class="oe_highlight"
|
||||
string="Create Sales Quotation" class="oe_highlight"
|
||||
type="action"/>
|
||||
</header>
|
||||
</field>
|
||||
|
||||
@@ -8,7 +8,7 @@ from openerp.exceptions import ValidationError
|
||||
|
||||
class RmaAddSale(models.TransientModel):
|
||||
_name = 'rma_add_sale'
|
||||
_description = 'Wizard to add rma lines'
|
||||
_description = 'Wizard to add rma lines from SO lines'
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
@@ -27,11 +27,8 @@ class RmaAddSale(models.TransientModel):
|
||||
res['sale_line_ids'] = False
|
||||
return res
|
||||
|
||||
rma_id = fields.Many2one('rma.order',
|
||||
string='RMA Order',
|
||||
readonly=True,
|
||||
ondelete='cascade')
|
||||
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', string='RMA Order', readonly=True)
|
||||
partner_id = fields.Many2one(comodel_name='res.partner', string='Partner',
|
||||
readonly=True)
|
||||
sale_id = fields.Many2one(comodel_name='sale.order', string='Order')
|
||||
@@ -55,6 +52,13 @@ class RmaAddSale(models.TransientModel):
|
||||
[('rma_selectable', '=', True)], limit=1)
|
||||
if not route:
|
||||
raise ValidationError("Please define an rma route")
|
||||
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||
warehouse = self.env['stock.warehouse'].search(
|
||||
[('company_id', '=', self.rma_id.company_id.id),
|
||||
('lot_rma_id', '!=', False)], limit=1)
|
||||
if not warehouse:
|
||||
raise ValidationError("Please define a warehouse with a "
|
||||
"default rma location.")
|
||||
data = {
|
||||
'sale_line_id': line.id,
|
||||
'product_id': line.product_id.id,
|
||||
@@ -67,13 +71,16 @@ class RmaAddSale(models.TransientModel):
|
||||
'price_unit': line.currency_id.compute(
|
||||
line.price_unit, line.currency_id, round=False),
|
||||
'rma_id': self.rma_id.id,
|
||||
'in_route_id': operation.in_route_id.id or route,
|
||||
'out_route_id': operation.out_route_id.id or route,
|
||||
'in_route_id': operation.in_route_id.id or route.id,
|
||||
'out_route_id': operation.out_route_id.id or route.id,
|
||||
'receipt_policy': operation.receipt_policy,
|
||||
'location_id': operation.location_id.id or self.env.ref(
|
||||
'stock.stock_location_stock').id,
|
||||
'location_id': (operation.location_id.id or
|
||||
operation.in_warehouse_id.lot_rma_id.id or
|
||||
warehouse.lot_rma_id.id),
|
||||
'refund_policy': operation.refund_policy,
|
||||
'delivery_policy': operation.delivery_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,
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
@@ -17,5 +17,5 @@ class RmaMakePicking(models.TransientModel):
|
||||
class RmaMakePickingItem(models.TransientModel):
|
||||
_inherit = "rma_make_picking.wizard.item"
|
||||
|
||||
sale_line_id = fields.Many2one('sale.order.line',
|
||||
string='Sale Line')
|
||||
sale_line_id = fields.Many2one(
|
||||
comodel_name='sale.order.line', string='Sale Line')
|
||||
|
||||
@@ -8,18 +8,17 @@ from openerp import _, api, exceptions, fields, models
|
||||
|
||||
class RmaLineMakeSaleOrder(models.TransientModel):
|
||||
_name = "rma.order.line.make.sale.order"
|
||||
_description = "RMA Line Make Sales Order"
|
||||
_description = "Make Sales Order from RMA Line"
|
||||
|
||||
partner_id = fields.Many2one('res.partner', string='Customer',
|
||||
required=False,
|
||||
domain=[('supplier', '=', True)])
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name='res.partner', string='Customer', required=False,
|
||||
domain=[('supplier', '=', True)])
|
||||
item_ids = fields.One2many(
|
||||
'rma.order.line.make.sale.order.item',
|
||||
'wiz_id', string='Items')
|
||||
sale_order_id = fields.Many2one('sale.order',
|
||||
string='Sales Order',
|
||||
required=False,
|
||||
domain=[('state', '=', 'draft')])
|
||||
comodel_name='rma.order.line.make.sale.order.item',
|
||||
inverse_name='wiz_id', string='Items')
|
||||
sale_order_id = fields.Many2one(
|
||||
comodel_name='sale.order', string='Sales Order', required=False,
|
||||
domain=[('state', '=', 'draft')])
|
||||
|
||||
@api.model
|
||||
def _prepare_item(self, line):
|
||||
@@ -132,24 +131,23 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
|
||||
_description = "RMA Line Make Sale Order Item"
|
||||
|
||||
wiz_id = fields.Many2one(
|
||||
'rma.order.line.make.sale.order',
|
||||
string='Wizard', required=True, ondelete='cascade',
|
||||
readonly=True)
|
||||
line_id = fields.Many2one('rma.order.line',
|
||||
string='RMA Line',
|
||||
required=True)
|
||||
rma_id = fields.Many2one('rma.order', related='line_id.rma_id',
|
||||
string='RMA Order', readonly=True)
|
||||
product_id = fields.Many2one('product.product', string='Product',
|
||||
readonly=True)
|
||||
comodel_name='rma.order.line.make.sale.order', string='Wizard',
|
||||
required=True, readonly=True)
|
||||
line_id = fields.Many2one(
|
||||
comodel_name='rma.order.line', string='RMA Line', required=True)
|
||||
rma_id = fields.Many2one(
|
||||
comodel_name='rma.order', related='line_id.rma_id',
|
||||
string='RMA Order', readonly=True)
|
||||
product_id = fields.Many2one(
|
||||
comodel_name='product.product', string='Product', readonly=True)
|
||||
name = fields.Char(string='Description', required=True, readonly=True)
|
||||
product_qty = fields.Float(string='Quantity to sell',
|
||||
digits=dp.get_precision('Product UoS'))
|
||||
product_uom_id = fields.Many2one('product.uom', string='UoM',
|
||||
readonly=True)
|
||||
out_warehouse_id = fields.Many2one('stock.warehouse',
|
||||
string='Outbound Warehouse')
|
||||
free_of_charge = fields.Boolean('Free of Charge')
|
||||
product_qty = fields.Float(
|
||||
string='Quantity to sell', digits=dp.get_precision('Product UoS'))
|
||||
product_uom_id = fields.Many2one(
|
||||
comodel_name='product.uom', string='UoM', readonly=True)
|
||||
out_warehouse_id = fields.Many2one(
|
||||
comodel_name='stock.warehouse', string='Outbound Warehouse')
|
||||
free_of_charge = fields.Boolean(string='Free of Charge')
|
||||
out_route_id = fields.Many2one(
|
||||
'stock.location.route', string='Outbound Route',
|
||||
comodel_name='stock.location.route', string='Outbound Route',
|
||||
domain=[('rma_selectable', '=', True)])
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
<record id="action_rma_order_line_make_sale_order"
|
||||
model="ir.actions.act_window">
|
||||
<field name="name">Create Sale Quotation</field>
|
||||
<field name="name">Create Sales Quotation</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">rma.order.line.make.sale.order</field>
|
||||
<field name="view_type">form</field>
|
||||
|
||||
@@ -17,5 +17,5 @@ class RmaRefund(models.TransientModel):
|
||||
class RmaRefundItem(models.TransientModel):
|
||||
_inherit = "rma.refund.item"
|
||||
|
||||
sale_line_id = fields.Many2one('sale.order.line',
|
||||
string='Sale Line')
|
||||
sale_line_id = fields.Many2one(
|
||||
comodel_name='sale.order.line', string='Sale Order Line')
|
||||
|
||||
Reference in New Issue
Block a user