mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] : black, isort
This commit is contained in:
committed by
JasminSForgeFlow
parent
daa6a3dc9a
commit
76fef77e64
@@ -2,22 +2,22 @@
|
|||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'RMA Sale',
|
"name": "RMA Sale",
|
||||||
'version': '12.0.1.0.0',
|
"version": "12.0.1.0.0",
|
||||||
'license': 'LGPL-3',
|
"license": "LGPL-3",
|
||||||
'category': 'RMA',
|
"category": "RMA",
|
||||||
'summary': 'Links RMA with Sales Orders',
|
"summary": "Links RMA with Sales Orders",
|
||||||
'author': "Eficent, Odoo Community Association (OCA)",
|
"author": "Eficent, Odoo Community Association (OCA)",
|
||||||
'website': 'https://github.com/Eficent/stock-rma',
|
"website": "https://github.com/Eficent/stock-rma",
|
||||||
'depends': ['rma_account', 'sale_stock'],
|
"depends": ["rma_account", "sale_stock"],
|
||||||
'data': [
|
"data": [
|
||||||
'data/rma_operation.xml',
|
"data/rma_operation.xml",
|
||||||
'views/rma_order_view.xml',
|
"views/rma_order_view.xml",
|
||||||
'views/rma_operation_view.xml',
|
"views/rma_operation_view.xml",
|
||||||
'views/sale_order_view.xml',
|
"views/sale_order_view.xml",
|
||||||
'wizards/rma_order_line_make_sale_order_view.xml',
|
"wizards/rma_order_line_make_sale_order_view.xml",
|
||||||
'wizards/rma_add_sale.xml',
|
"wizards/rma_add_sale.xml",
|
||||||
'views/rma_order_line_view.xml',
|
"views/rma_order_line_view.xml",
|
||||||
],
|
],
|
||||||
'installable': True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ from odoo import fields, models
|
|||||||
|
|
||||||
|
|
||||||
class RmaOperation(models.Model):
|
class RmaOperation(models.Model):
|
||||||
_inherit = 'rma.operation'
|
_inherit = "rma.operation"
|
||||||
|
|
||||||
sale_policy = fields.Selection([
|
sale_policy = fields.Selection(
|
||||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
[
|
||||||
('received', 'Based on Received Quantities')],
|
("no", "Not required"),
|
||||||
string="Sale Policy", default='no')
|
("ordered", "Based on Ordered Quantities"),
|
||||||
|
("received", "Based on Received Quantities"),
|
||||||
|
],
|
||||||
|
string="Sale Policy",
|
||||||
|
default="no",
|
||||||
|
)
|
||||||
|
|||||||
@@ -6,30 +6,34 @@ from odoo import api, fields, models
|
|||||||
class RmaOrder(models.Model):
|
class RmaOrder(models.Model):
|
||||||
_inherit = "rma.order"
|
_inherit = "rma.order"
|
||||||
|
|
||||||
@api.depends('rma_line_ids', 'rma_line_ids.sale_line_id',
|
@api.depends(
|
||||||
'rma_line_ids.sale_line_id.order_id')
|
"rma_line_ids",
|
||||||
|
"rma_line_ids.sale_line_id",
|
||||||
|
"rma_line_ids.sale_line_id.order_id",
|
||||||
|
)
|
||||||
def _compute_sales_count(self):
|
def _compute_sales_count(self):
|
||||||
for rma in self:
|
for rma in self:
|
||||||
sales = rma.mapped('rma_line_ids.sale_line_id.order_id')
|
sales = rma.mapped("rma_line_ids.sale_line_id.order_id")
|
||||||
rma.sale_count = len(sales)
|
rma.sale_count = len(sales)
|
||||||
|
|
||||||
sale_count = fields.Integer(
|
sale_count = fields.Integer(compute="_compute_sales_count", string="# of Sales")
|
||||||
compute='_compute_sales_count', string='# of Sales')
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_line_domain(self, rma_id, line):
|
def _get_line_domain(self, rma_id, line):
|
||||||
if line.sale_line_id and line.sale_line_id.id:
|
if line.sale_line_id and line.sale_line_id.id:
|
||||||
domain = [('rma_id', '=', rma_id.id),
|
domain = [
|
||||||
('type', '=', 'supplier'),
|
("rma_id", "=", rma_id.id),
|
||||||
('sale_line_id', '=', line.sale_line_id.id)]
|
("type", "=", "supplier"),
|
||||||
|
("sale_line_id", "=", line.sale_line_id.id),
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
domain = super(RmaOrder, self)._get_line_domain(rma_id, line)
|
domain = super(RmaOrder, self)._get_line_domain(rma_id, line)
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_sale_order(self):
|
def action_view_sale_order(self):
|
||||||
action = self.env.ref('sale.action_quotations')
|
action = self.env.ref("sale.action_quotations")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
so_ids = self.mapped('rma_line_ids.sale_line_id.order_id').ids
|
so_ids = self.mapped("rma_line_ids.sale_line_id.order_id").ids
|
||||||
result['domain'] = [('id', 'in', so_ids)]
|
result["domain"] = [("id", "in", so_ids)]
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -1,88 +1,114 @@
|
|||||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
from odoo import api, fields, models, _
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
from odoo.addons import decimal_precision as dp
|
from odoo.addons import decimal_precision as dp
|
||||||
|
|
||||||
|
|
||||||
class RmaOrderLine(models.Model):
|
class RmaOrderLine(models.Model):
|
||||||
_inherit = "rma.order.line"
|
_inherit = "rma.order.line"
|
||||||
|
|
||||||
@api.depends('sale_line_ids', 'sale_policy', 'sales_count',
|
@api.depends(
|
||||||
'sale_line_ids.state', 'qty_received', 'product_qty')
|
"sale_line_ids",
|
||||||
|
"sale_policy",
|
||||||
|
"sales_count",
|
||||||
|
"sale_line_ids.state",
|
||||||
|
"qty_received",
|
||||||
|
"product_qty",
|
||||||
|
)
|
||||||
def _compute_qty_to_sell(self):
|
def _compute_qty_to_sell(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.sale_policy == 'ordered':
|
if rec.sale_policy == "ordered":
|
||||||
qty = rec._get_rma_sold_qty()
|
qty = rec._get_rma_sold_qty()
|
||||||
rec.qty_to_sell = rec.product_qty - qty
|
rec.qty_to_sell = rec.product_qty - qty
|
||||||
elif rec.sale_policy == 'received':
|
elif rec.sale_policy == "received":
|
||||||
qty = rec._get_rma_sold_qty()
|
qty = rec._get_rma_sold_qty()
|
||||||
rec.qty_to_sell = rec.qty_received - qty
|
rec.qty_to_sell = rec.qty_received - qty
|
||||||
else:
|
else:
|
||||||
rec.qty_to_sell = 0.0
|
rec.qty_to_sell = 0.0
|
||||||
|
|
||||||
@api.depends('sale_line_ids', 'sale_policy', 'sales_count',
|
@api.depends("sale_line_ids", "sale_policy", "sales_count", "sale_line_ids.state")
|
||||||
'sale_line_ids.state')
|
|
||||||
def _compute_qty_sold(self):
|
def _compute_qty_sold(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.qty_sold = rec._get_rma_sold_qty()
|
rec.qty_sold = rec._get_rma_sold_qty()
|
||||||
|
|
||||||
@api.depends('sale_line_ids', 'sale_line_ids.order_id')
|
@api.depends("sale_line_ids", "sale_line_ids.order_id")
|
||||||
def _compute_sales_count(self):
|
def _compute_sales_count(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
sales = line.mapped('sale_line_ids.order_id')
|
sales = line.mapped("sale_line_ids.order_id")
|
||||||
line.sales_count = len(sales)
|
line.sales_count = len(sales)
|
||||||
|
|
||||||
sale_line_id = fields.Many2one(
|
sale_line_id = fields.Many2one(
|
||||||
comodel_name='sale.order.line', string='Originating Sales Order Line',
|
comodel_name="sale.order.line",
|
||||||
ondelete='restrict', copy=False,
|
string="Originating Sales Order Line",
|
||||||
readonly=True, states={'draft': [('readonly', False)]},
|
ondelete="restrict",
|
||||||
|
copy=False,
|
||||||
|
readonly=True,
|
||||||
|
states={"draft": [("readonly", False)]},
|
||||||
)
|
)
|
||||||
sale_id = fields.Many2one(
|
sale_id = fields.Many2one(
|
||||||
string="Source Sales Order", related='sale_line_id.order_id',
|
string="Source Sales Order", related="sale_line_id.order_id"
|
||||||
)
|
)
|
||||||
sale_line_ids = fields.One2many(
|
sale_line_ids = fields.One2many(
|
||||||
comodel_name='sale.order.line', inverse_name='rma_line_id',
|
comodel_name="sale.order.line",
|
||||||
string='Sales Order Lines', readonly=True,
|
inverse_name="rma_line_id",
|
||||||
states={'draft': [('readonly', False)]}, copy=False)
|
string="Sales Order Lines",
|
||||||
|
readonly=True,
|
||||||
|
states={"draft": [("readonly", False)]},
|
||||||
|
copy=False,
|
||||||
|
)
|
||||||
qty_to_sell = fields.Float(
|
qty_to_sell = fields.Float(
|
||||||
string='Qty To Sell', copy=False,
|
string="Qty To Sell",
|
||||||
digits=dp.get_precision('Product Unit of Measure'),
|
copy=False,
|
||||||
readonly=True, compute='_compute_qty_to_sell',
|
digits=dp.get_precision("Product Unit of Measure"),
|
||||||
store=True)
|
readonly=True,
|
||||||
|
compute="_compute_qty_to_sell",
|
||||||
|
store=True,
|
||||||
|
)
|
||||||
qty_sold = fields.Float(
|
qty_sold = fields.Float(
|
||||||
string='Qty Sold', copy=False,
|
string="Qty Sold",
|
||||||
digits=dp.get_precision('Product Unit of Measure'),
|
copy=False,
|
||||||
readonly=True, compute='_compute_qty_sold',
|
digits=dp.get_precision("Product Unit of Measure"),
|
||||||
store=True)
|
readonly=True,
|
||||||
sale_policy = fields.Selection(selection=[
|
compute="_compute_qty_sold",
|
||||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
store=True,
|
||||||
('received', 'Based on Received Quantities')],
|
)
|
||||||
string="Sale Policy", default='no', required=True,
|
sale_policy = fields.Selection(
|
||||||
readonly=True, states={'draft': [('readonly', False)]})
|
selection=[
|
||||||
sales_count = fields.Integer(
|
("no", "Not required"),
|
||||||
compute='_compute_sales_count', string='# of Sales')
|
("ordered", "Based on Ordered Quantities"),
|
||||||
|
("received", "Based on Received Quantities"),
|
||||||
|
],
|
||||||
|
string="Sale Policy",
|
||||||
|
default="no",
|
||||||
|
required=True,
|
||||||
|
readonly=True,
|
||||||
|
states={"draft": [("readonly", False)]},
|
||||||
|
)
|
||||||
|
sales_count = fields.Integer(compute="_compute_sales_count", string="# of Sales")
|
||||||
|
|
||||||
@api.onchange('product_id', 'partner_id')
|
@api.onchange("product_id", "partner_id")
|
||||||
def _onchange_product_id(self):
|
def _onchange_product_id(self):
|
||||||
"""Domain for sale_line_id is computed here to make it dynamic."""
|
"""Domain for sale_line_id is computed here to make it dynamic."""
|
||||||
res = super(RmaOrderLine, self)._onchange_product_id()
|
res = super(RmaOrderLine, self)._onchange_product_id()
|
||||||
if not res.get('domain'):
|
if not res.get("domain"):
|
||||||
res['domain'] = {}
|
res["domain"] = {}
|
||||||
domain = [
|
domain = [
|
||||||
'|',
|
"|",
|
||||||
('order_id.partner_id', '=', self.partner_id.id),
|
("order_id.partner_id", "=", self.partner_id.id),
|
||||||
('order_id.partner_id', 'child_of', self.partner_id.id)]
|
("order_id.partner_id", "child_of", self.partner_id.id),
|
||||||
|
]
|
||||||
if self.product_id:
|
if self.product_id:
|
||||||
domain.append(('product_id', '=', self.product_id.id))
|
domain.append(("product_id", "=", self.product_id.id))
|
||||||
res['domain']['sale_line_id'] = domain
|
res["domain"]["sale_line_id"] = domain
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.onchange('operation_id')
|
@api.onchange("operation_id")
|
||||||
def _onchange_operation_id(self):
|
def _onchange_operation_id(self):
|
||||||
res = super(RmaOrderLine, self)._onchange_operation_id()
|
res = super(RmaOrderLine, self)._onchange_operation_id()
|
||||||
if self.operation_id:
|
if self.operation_id:
|
||||||
self.sale_policy = self.operation_id.sale_policy or 'no'
|
self.sale_policy = self.operation_id.sale_policy or "no"
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -94,80 +120,90 @@ class RmaOrderLine(models.Model):
|
|||||||
if not operation:
|
if not operation:
|
||||||
operation = line.product_id.categ_id.rma_customer_operation_id
|
operation = line.product_id.categ_id.rma_customer_operation_id
|
||||||
if not operation:
|
if not operation:
|
||||||
operation = self.env['rma.operation'].search(
|
operation = self.env["rma.operation"].search(
|
||||||
[('type', '=', self.type)], limit=1)
|
[("type", "=", self.type)], limit=1
|
||||||
|
)
|
||||||
if not operation:
|
if not operation:
|
||||||
raise ValidationError(_("Please define an operation first"))
|
raise ValidationError(_("Please define an operation first"))
|
||||||
if not operation.in_route_id or not operation.out_route_id:
|
if not operation.in_route_id or not operation.out_route_id:
|
||||||
route = self.env['stock.location.route'].search(
|
route = self.env["stock.location.route"].search(
|
||||||
[('rma_selectable', '=', True)], limit=1)
|
[("rma_selectable", "=", True)], limit=1
|
||||||
|
)
|
||||||
if not route:
|
if not route:
|
||||||
raise ValidationError(_("Please define an RMA route"))
|
raise ValidationError(_("Please define an RMA route"))
|
||||||
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||||
warehouse = self.env['stock.warehouse'].search(
|
warehouse = self.env["stock.warehouse"].search(
|
||||||
[('company_id', '=', self.company_id.id),
|
[("company_id", "=", self.company_id.id), ("lot_rma_id", "!=", False)],
|
||||||
('lot_rma_id', '!=', False)], limit=1)
|
limit=1,
|
||||||
|
)
|
||||||
if not warehouse:
|
if not warehouse:
|
||||||
raise ValidationError(_(
|
raise ValidationError(
|
||||||
"Please define a warehouse with a default RMA location."))
|
_("Please define a warehouse with a default RMA location.")
|
||||||
|
)
|
||||||
data = {
|
data = {
|
||||||
'product_id': line.product_id.id,
|
"product_id": line.product_id.id,
|
||||||
'origin': line.order_id.name,
|
"origin": line.order_id.name,
|
||||||
'uom_id': line.product_uom.id,
|
"uom_id": line.product_uom.id,
|
||||||
'operation_id': operation.id,
|
"operation_id": operation.id,
|
||||||
'product_qty': line.product_uom_qty,
|
"product_qty": line.product_uom_qty,
|
||||||
'delivery_address_id': line.order_id.partner_id.id,
|
"delivery_address_id": line.order_id.partner_id.id,
|
||||||
'invoice_address_id': line.order_id.partner_id.id,
|
"invoice_address_id": line.order_id.partner_id.id,
|
||||||
'price_unit': line.currency_id.compute(
|
"price_unit": line.currency_id.compute(
|
||||||
line.price_unit, line.currency_id, round=False),
|
line.price_unit, line.currency_id, round=False
|
||||||
'in_route_id': operation.in_route_id.id or route.id,
|
),
|
||||||
'out_route_id': operation.out_route_id.id or route.id,
|
"in_route_id": operation.in_route_id.id or route.id,
|
||||||
'receipt_policy': operation.receipt_policy,
|
"out_route_id": operation.out_route_id.id or route.id,
|
||||||
'currency_id': line.currency_id.id,
|
"receipt_policy": operation.receipt_policy,
|
||||||
'location_id': (operation.location_id.id or
|
"currency_id": line.currency_id.id,
|
||||||
operation.in_warehouse_id.lot_rma_id.id or
|
"location_id": (
|
||||||
warehouse.lot_rma_id.id),
|
operation.location_id.id
|
||||||
'refund_policy': operation.refund_policy,
|
or operation.in_warehouse_id.lot_rma_id.id
|
||||||
'delivery_policy': operation.delivery_policy,
|
or warehouse.lot_rma_id.id
|
||||||
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
),
|
||||||
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
|
"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,
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@api.onchange('sale_line_id')
|
@api.onchange("sale_line_id")
|
||||||
def _onchange_sale_line_id(self):
|
def _onchange_sale_line_id(self):
|
||||||
if not self.sale_line_id:
|
if not self.sale_line_id:
|
||||||
return
|
return
|
||||||
data = self._prepare_rma_line_from_sale_order_line(
|
data = self._prepare_rma_line_from_sale_order_line(self.sale_line_id)
|
||||||
self.sale_line_id)
|
|
||||||
self.update(data)
|
self.update(data)
|
||||||
self._remove_other_data_origin('sale_line_id')
|
self._remove_other_data_origin("sale_line_id")
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _remove_other_data_origin(self, exception):
|
def _remove_other_data_origin(self, exception):
|
||||||
res = super(RmaOrderLine, self)._remove_other_data_origin(exception)
|
res = super(RmaOrderLine, self)._remove_other_data_origin(exception)
|
||||||
if not exception == 'sale_line_id':
|
if not exception == "sale_line_id":
|
||||||
self.sale_line_id = False
|
self.sale_line_id = False
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.constrains('sale_line_id', 'partner_id')
|
@api.constrains("sale_line_id", "partner_id")
|
||||||
def _check_sale_partner(self):
|
def _check_sale_partner(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if (rec.sale_line_id and
|
if (
|
||||||
rec.sale_line_id.order_id.partner_id != rec.partner_id and
|
rec.sale_line_id
|
||||||
rec.sale_line_id.order_id.partner_id.parent_id !=
|
and rec.sale_line_id.order_id.partner_id != rec.partner_id
|
||||||
rec.partner_id):
|
and rec.sale_line_id.order_id.partner_id.parent_id != rec.partner_id
|
||||||
raise ValidationError(_(
|
):
|
||||||
|
raise ValidationError(
|
||||||
|
_(
|
||||||
"RMA customer and originating sales order line customer "
|
"RMA customer and originating sales order line customer "
|
||||||
"doesn't match."))
|
"doesn't match."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_sale_order(self):
|
def action_view_sale_order(self):
|
||||||
action = self.env.ref('sale.action_quotations')
|
action = self.env.ref("sale.action_quotations")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
order_ids = self.mapped('sale_line_ids.order_id').ids
|
order_ids = self.mapped("sale_line_ids.order_id").ids
|
||||||
result['domain'] = [('id', 'in', order_ids)]
|
result["domain"] = [("id", "in", order_ids)]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -175,6 +211,7 @@ class RmaOrderLine(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
qty = 0.0
|
qty = 0.0
|
||||||
for sale_line in self.sale_line_ids.filtered(
|
for sale_line in self.sale_line_ids.filtered(
|
||||||
lambda p: p.state not in ('draft', 'sent', 'cancel')):
|
lambda p: p.state not in ("draft", "sent", "cancel")
|
||||||
|
):
|
||||||
qty += sale_line.product_uom_qty
|
qty += sale_line.product_uom_qty
|
||||||
return qty
|
return qty
|
||||||
|
|||||||
@@ -7,37 +7,55 @@ class SaleOrderLine(models.Model):
|
|||||||
_inherit = "sale.order.line"
|
_inherit = "sale.order.line"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
def name_search(self, name="", args=None, operator="ilike", limit=100):
|
||||||
"""Allows to search by SO reference."""
|
"""Allows to search by SO reference."""
|
||||||
if not args:
|
if not args:
|
||||||
args = []
|
args = []
|
||||||
args += ['|',
|
args += [
|
||||||
|
"|",
|
||||||
(self._rec_name, operator, name),
|
(self._rec_name, operator, name),
|
||||||
('order_id.name', operator, name)]
|
("order_id.name", operator, name),
|
||||||
|
]
|
||||||
return super(SaleOrderLine, self).name_search(
|
return super(SaleOrderLine, self).name_search(
|
||||||
name=name, args=args, operator=operator, limit=limit)
|
name=name, args=args, operator=operator, limit=limit
|
||||||
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _name_search(self, name='', args=None, operator='ilike',
|
def _name_search(
|
||||||
limit=100, name_get_uid=None):
|
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
|
||||||
|
):
|
||||||
"""Typed text is cleared here for better extensibility."""
|
"""Typed text is cleared here for better extensibility."""
|
||||||
return super(SaleOrderLine, self)._name_search(
|
return super(SaleOrderLine, self)._name_search(
|
||||||
name='', args=args, operator=operator, limit=limit,
|
name="",
|
||||||
name_get_uid=name_get_uid)
|
args=args,
|
||||||
|
operator=operator,
|
||||||
|
limit=limit,
|
||||||
|
name_get_uid=name_get_uid,
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def name_get(self):
|
def name_get(self):
|
||||||
res = []
|
res = []
|
||||||
if self.env.context.get('rma'):
|
if self.env.context.get("rma"):
|
||||||
for sale in self:
|
for sale in self:
|
||||||
if sale.order_id.name:
|
if sale.order_id.name:
|
||||||
res.append(
|
res.append(
|
||||||
(sale.id, "SO:%s | INV: %s, | PART:%s | QTY:%s" % (
|
(
|
||||||
|
sale.id,
|
||||||
|
"SO:%s | INV: %s, | PART:%s | QTY:%s"
|
||||||
|
% (
|
||||||
sale.order_id.name,
|
sale.order_id.name,
|
||||||
" ".join(str(x) for x in [
|
" ".join(
|
||||||
inv.number
|
str(x)
|
||||||
for inv in sale.order_id.invoice_ids]),
|
for x in [
|
||||||
sale.product_id.name, sale.product_uom_qty)))
|
inv.number for inv in sale.order_id.invoice_ids
|
||||||
|
]
|
||||||
|
),
|
||||||
|
sale.product_id.name,
|
||||||
|
sale.product_uom_qty,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
res.append(super(SaleOrderLine, sale).name_get()[0])
|
res.append(super(SaleOrderLine, sale).name_get()[0])
|
||||||
return res
|
return res
|
||||||
@@ -45,13 +63,13 @@ class SaleOrderLine(models.Model):
|
|||||||
return super(SaleOrderLine, self).name_get()
|
return super(SaleOrderLine, self).name_get()
|
||||||
|
|
||||||
rma_line_id = fields.Many2one(
|
rma_line_id = fields.Many2one(
|
||||||
comodel_name='rma.order.line', string='RMA', ondelete='restrict')
|
comodel_name="rma.order.line", string="RMA", ondelete="restrict"
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _prepare_order_line_procurement(self, group_id=False):
|
def _prepare_order_line_procurement(self, group_id=False):
|
||||||
vals = super(SaleOrderLine, self)._prepare_order_line_procurement(
|
vals = super(SaleOrderLine, self)._prepare_order_line_procurement(
|
||||||
group_id=group_id)
|
group_id=group_id
|
||||||
vals.update({
|
)
|
||||||
'rma_line_id': self.rma_line_id.id
|
vals.update({"rma_line_id": self.rma_line_id.id})
|
||||||
})
|
|
||||||
return vals
|
return vals
|
||||||
|
|||||||
@@ -5,95 +5,103 @@ from odoo.tests import common
|
|||||||
|
|
||||||
|
|
||||||
class TestRmaSale(common.SingleTransactionCase):
|
class TestRmaSale(common.SingleTransactionCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TestRmaSale, cls).setUpClass()
|
super(TestRmaSale, cls).setUpClass()
|
||||||
|
|
||||||
cls.rma_obj = cls.env['rma.order']
|
cls.rma_obj = cls.env["rma.order"]
|
||||||
cls.rma_line_obj = cls.env['rma.order.line']
|
cls.rma_line_obj = cls.env["rma.order.line"]
|
||||||
cls.rma_op_obj = cls.env['rma.operation']
|
cls.rma_op_obj = cls.env["rma.operation"]
|
||||||
cls.rma_add_sale_wiz = cls.env['rma_add_sale']
|
cls.rma_add_sale_wiz = cls.env["rma_add_sale"]
|
||||||
cls.rma_make_sale_wiz = cls.env['rma.order.line.make.sale.order']
|
cls.rma_make_sale_wiz = cls.env["rma.order.line.make.sale.order"]
|
||||||
cls.so_obj = cls.env['sale.order']
|
cls.so_obj = cls.env["sale.order"]
|
||||||
cls.sol_obj = cls.env['sale.order.line']
|
cls.sol_obj = cls.env["sale.order.line"]
|
||||||
cls.product_obj = cls.env['product.product']
|
cls.product_obj = cls.env["product.product"]
|
||||||
cls.partner_obj = cls.env['res.partner']
|
cls.partner_obj = cls.env["res.partner"]
|
||||||
|
|
||||||
cls.rma_route_cust = cls.env.ref('rma.route_rma_customer')
|
cls.rma_route_cust = cls.env.ref("rma.route_rma_customer")
|
||||||
|
|
||||||
# Create customer
|
# Create customer
|
||||||
customer1 = cls.partner_obj.create({'name': 'Customer 1'})
|
customer1 = cls.partner_obj.create({"name": "Customer 1"})
|
||||||
|
|
||||||
# Create products
|
# Create products
|
||||||
cls.product_1 = cls.product_obj.create({
|
cls.product_1 = cls.product_obj.create(
|
||||||
'name': 'Test Product 1',
|
{"name": "Test Product 1", "type": "product", "list_price": 100.0}
|
||||||
'type': 'product',
|
)
|
||||||
'list_price': 100.0,
|
cls.product_2 = cls.product_obj.create(
|
||||||
})
|
{"name": "Test Product 2", "type": "product", "list_price": 150.0}
|
||||||
cls.product_2 = cls.product_obj.create({
|
)
|
||||||
'name': 'Test Product 2',
|
|
||||||
'type': 'product',
|
|
||||||
'list_price': 150.0,
|
|
||||||
})
|
|
||||||
|
|
||||||
# Create SO:
|
# Create SO:
|
||||||
cls.so = cls.so_obj.create({
|
cls.so = cls.so_obj.create(
|
||||||
'partner_id': customer1.id,
|
{
|
||||||
'partner_invoice_id': customer1.id,
|
"partner_id": customer1.id,
|
||||||
'partner_shipping_id': customer1.id,
|
"partner_invoice_id": customer1.id,
|
||||||
'order_line': [
|
"partner_shipping_id": customer1.id,
|
||||||
(0, 0, {
|
"order_line": [
|
||||||
'name': cls.product_1.name,
|
(
|
||||||
'product_id': cls.product_1.id,
|
0,
|
||||||
'product_uom_qty': 20.0,
|
0,
|
||||||
'product_uom': cls.product_1.uom_id.id,
|
{
|
||||||
'price_unit': cls.product_1.list_price
|
"name": cls.product_1.name,
|
||||||
}),
|
"product_id": cls.product_1.id,
|
||||||
(0, 0, {
|
"product_uom_qty": 20.0,
|
||||||
'name': cls.product_2.name,
|
"product_uom": cls.product_1.uom_id.id,
|
||||||
'product_id': cls.product_2.id,
|
"price_unit": cls.product_1.list_price,
|
||||||
'product_uom_qty': 18.0,
|
},
|
||||||
'product_uom': cls.product_2.uom_id.id,
|
),
|
||||||
'price_unit': cls.product_2.list_price
|
(
|
||||||
}),
|
0,
|
||||||
|
0,
|
||||||
|
{
|
||||||
|
"name": cls.product_2.name,
|
||||||
|
"product_id": cls.product_2.id,
|
||||||
|
"product_uom_qty": 18.0,
|
||||||
|
"product_uom": cls.product_2.uom_id.id,
|
||||||
|
"price_unit": cls.product_2.list_price,
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
'pricelist_id': cls.env.ref('product.list0').id,
|
"pricelist_id": cls.env.ref("product.list0").id,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# Create RMA group and operation:
|
# Create RMA group and operation:
|
||||||
cls.rma_group = cls.rma_obj.create({
|
cls.rma_group = cls.rma_obj.create({"partner_id": customer1.id})
|
||||||
'partner_id': customer1.id,
|
cls.operation_1 = cls.rma_op_obj.create(
|
||||||
})
|
{
|
||||||
cls.operation_1 = cls.rma_op_obj.create({
|
"code": "TEST",
|
||||||
'code': 'TEST',
|
"name": "Sale afer receive",
|
||||||
'name': 'Sale afer receive',
|
"type": "customer",
|
||||||
'type': 'customer',
|
"receipt_policy": "ordered",
|
||||||
'receipt_policy': 'ordered',
|
"sale_policy": "received",
|
||||||
'sale_policy': 'received',
|
"in_route_id": cls.rma_route_cust.id,
|
||||||
'in_route_id': cls.rma_route_cust.id,
|
"out_route_id": cls.rma_route_cust.id,
|
||||||
'out_route_id': cls.rma_route_cust.id,
|
}
|
||||||
})
|
)
|
||||||
cls.operation_2 = cls.rma_op_obj.create({
|
cls.operation_2 = cls.rma_op_obj.create(
|
||||||
'code': 'TEST',
|
{
|
||||||
'name': 'Receive and Sale',
|
"code": "TEST",
|
||||||
'type': 'customer',
|
"name": "Receive and Sale",
|
||||||
'receipt_policy': 'ordered',
|
"type": "customer",
|
||||||
'sale_policy': 'ordered',
|
"receipt_policy": "ordered",
|
||||||
'in_route_id': cls.rma_route_cust.id,
|
"sale_policy": "ordered",
|
||||||
'out_route_id': cls.rma_route_cust.id,
|
"in_route_id": cls.rma_route_cust.id,
|
||||||
})
|
"out_route_id": cls.rma_route_cust.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_01_add_from_sale_order(self):
|
def test_01_add_from_sale_order(self):
|
||||||
"""Test wizard to create RMA from Sales Orders."""
|
"""Test wizard to create RMA from Sales Orders."""
|
||||||
add_sale = self.rma_add_sale_wiz.with_context({
|
add_sale = self.rma_add_sale_wiz.with_context(
|
||||||
'customer': True,
|
{
|
||||||
'active_ids': self.rma_group.id,
|
"customer": True,
|
||||||
'active_model': 'rma.order',
|
"active_ids": self.rma_group.id,
|
||||||
}).create({
|
"active_model": "rma.order",
|
||||||
'sale_id': self.so.id,
|
}
|
||||||
'sale_line_ids': [(6, 0, self.so.order_line.ids)],
|
).create(
|
||||||
})
|
{"sale_id": self.so.id, "sale_line_ids": [(6, 0, self.so.order_line.ids)]}
|
||||||
|
)
|
||||||
add_sale.add_lines()
|
add_sale.add_lines()
|
||||||
self.assertEqual(len(self.rma_group.rma_line_ids), 2)
|
self.assertEqual(len(self.rma_group.rma_line_ids), 2)
|
||||||
|
|
||||||
@@ -101,38 +109,33 @@ class TestRmaSale(common.SingleTransactionCase):
|
|||||||
"""Test RMA quantities using sale operations."""
|
"""Test RMA quantities using sale operations."""
|
||||||
# Received sale_policy:
|
# Received sale_policy:
|
||||||
rma_1 = self.rma_group.rma_line_ids.filtered(
|
rma_1 = self.rma_group.rma_line_ids.filtered(
|
||||||
lambda r: r.product_id == self.product_1)
|
lambda r: r.product_id == self.product_1
|
||||||
rma_1.write({
|
)
|
||||||
'operation_id': self.operation_1.id,
|
rma_1.write({"operation_id": self.operation_1.id})
|
||||||
})
|
|
||||||
rma_1._onchange_operation_id()
|
rma_1._onchange_operation_id()
|
||||||
self.assertEqual(rma_1.sale_policy, 'received')
|
self.assertEqual(rma_1.sale_policy, "received")
|
||||||
self.assertEqual(rma_1.qty_to_sell, 0.0)
|
self.assertEqual(rma_1.qty_to_sell, 0.0)
|
||||||
# TODO: receive and check qty_to_sell is 20.0
|
# TODO: receive and check qty_to_sell is 20.0
|
||||||
# Ordered sale_policy:
|
# Ordered sale_policy:
|
||||||
rma_2 = self.rma_group.rma_line_ids.filtered(
|
rma_2 = self.rma_group.rma_line_ids.filtered(
|
||||||
lambda r: r.product_id == self.product_2)
|
lambda r: r.product_id == self.product_2
|
||||||
rma_2.write({
|
)
|
||||||
'operation_id': self.operation_2.id,
|
rma_2.write({"operation_id": self.operation_2.id})
|
||||||
})
|
|
||||||
rma_2._onchange_operation_id()
|
rma_2._onchange_operation_id()
|
||||||
self.assertEqual(rma_2.sale_policy, 'ordered')
|
self.assertEqual(rma_2.sale_policy, "ordered")
|
||||||
self.assertEqual(rma_2.qty_to_sell, 18.0)
|
self.assertEqual(rma_2.qty_to_sell, 18.0)
|
||||||
|
|
||||||
def test_03_rma_create_sale(self):
|
def test_03_rma_create_sale(self):
|
||||||
"""Generate a Sales Order from a customer RMA."""
|
"""Generate a Sales Order from a customer RMA."""
|
||||||
rma = self.rma_group.rma_line_ids.filtered(
|
rma = self.rma_group.rma_line_ids.filtered(
|
||||||
lambda r: r.product_id == self.product_2)
|
lambda r: r.product_id == self.product_2
|
||||||
|
)
|
||||||
self.assertEqual(rma.sales_count, 0)
|
self.assertEqual(rma.sales_count, 0)
|
||||||
self.assertEqual(rma.qty_to_sell, 18.0)
|
self.assertEqual(rma.qty_to_sell, 18.0)
|
||||||
self.assertEqual(rma.qty_sold, 0.0)
|
self.assertEqual(rma.qty_sold, 0.0)
|
||||||
make_sale = self.rma_make_sale_wiz.with_context({
|
make_sale = self.rma_make_sale_wiz.with_context(
|
||||||
'customer': True,
|
{"customer": True, "active_ids": rma.id, "active_model": "rma.order.line"}
|
||||||
'active_ids': rma.id,
|
).create({"partner_id": rma.partner_id.id})
|
||||||
'active_model': 'rma.order.line',
|
|
||||||
}).create({
|
|
||||||
'partner_id': rma.partner_id.id,
|
|
||||||
})
|
|
||||||
make_sale.make_sale_order()
|
make_sale.make_sale_order()
|
||||||
self.assertEqual(rma.sales_count, 1)
|
self.assertEqual(rma.sales_count, 1)
|
||||||
rma.sale_line_ids.order_id.action_confirm()
|
rma.sale_line_ids.order_id.action_confirm()
|
||||||
@@ -141,12 +144,10 @@ class TestRmaSale(common.SingleTransactionCase):
|
|||||||
|
|
||||||
def test_04_fill_rma_from_so_line(self):
|
def test_04_fill_rma_from_so_line(self):
|
||||||
"""Test filling a RMA (line) from a Sales Order line."""
|
"""Test filling a RMA (line) from a Sales Order line."""
|
||||||
so_line = self.so.order_line.filtered(
|
so_line = self.so.order_line.filtered(lambda r: r.product_id == self.product_1)
|
||||||
lambda r: r.product_id == self.product_1)
|
rma = self.rma_line_obj.new(
|
||||||
rma = self.rma_line_obj.new({
|
{"partner_id": self.so.partner_id.id, "sale_line_id": so_line.id}
|
||||||
'partner_id': self.so.partner_id.id,
|
)
|
||||||
'sale_line_id': so_line.id,
|
|
||||||
})
|
|
||||||
self.assertFalse(rma.product_id)
|
self.assertFalse(rma.product_id)
|
||||||
rma._onchange_sale_line_id()
|
rma._onchange_sale_line_id()
|
||||||
self.assertEqual(rma.product_id, self.product_1)
|
self.assertEqual(rma.product_id, self.product_1)
|
||||||
|
|||||||
@@ -6,90 +6,105 @@ from odoo.exceptions import ValidationError
|
|||||||
|
|
||||||
|
|
||||||
class RmaAddSale(models.TransientModel):
|
class RmaAddSale(models.TransientModel):
|
||||||
_name = 'rma_add_sale'
|
_name = "rma_add_sale"
|
||||||
_description = 'Wizard to add rma lines from SO lines'
|
_description = "Wizard to add rma lines from SO lines"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
res = super(RmaAddSale, self).default_get(fields_list)
|
res = super(RmaAddSale, self).default_get(fields_list)
|
||||||
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"]
|
||||||
if not rma_id:
|
if not rma_id:
|
||||||
return res
|
return res
|
||||||
assert active_model == 'rma.order', 'Bad context propagation'
|
assert active_model == "rma.order", "Bad context propagation"
|
||||||
|
|
||||||
rma = rma_obj.browse(rma_id)
|
rma = rma_obj.browse(rma_id)
|
||||||
res['rma_id'] = rma.id
|
res["rma_id"] = rma.id
|
||||||
res['partner_id'] = rma.partner_id.id
|
res["partner_id"] = rma.partner_id.id
|
||||||
res['sale_id'] = False
|
res["sale_id"] = False
|
||||||
res['sale_line_ids'] = False
|
res["sale_line_ids"] = False
|
||||||
return res
|
return res
|
||||||
|
|
||||||
rma_id = fields.Many2one(
|
rma_id = fields.Many2one(
|
||||||
comodel_name='rma.order', string='RMA Order', readonly=True)
|
comodel_name="rma.order", string="RMA Order", readonly=True
|
||||||
partner_id = fields.Many2one(comodel_name='res.partner', string='Partner',
|
)
|
||||||
readonly=True)
|
partner_id = fields.Many2one(
|
||||||
sale_id = fields.Many2one(comodel_name='sale.order', string='Order')
|
comodel_name="res.partner", string="Partner", readonly=True
|
||||||
sale_line_ids = fields.Many2many('sale.order.line',
|
)
|
||||||
'rma_add_sale_add_line_rel',
|
sale_id = fields.Many2one(comodel_name="sale.order", string="Order")
|
||||||
'sale_line_id', 'rma_add_sale_id',
|
sale_line_ids = fields.Many2many(
|
||||||
|
"sale.order.line",
|
||||||
|
"rma_add_sale_add_line_rel",
|
||||||
|
"sale_line_id",
|
||||||
|
"rma_add_sale_id",
|
||||||
readonly=False,
|
readonly=False,
|
||||||
string='Sale Lines')
|
string="Sale Lines",
|
||||||
|
)
|
||||||
|
|
||||||
def _prepare_rma_line_from_sale_order_line(self, line):
|
def _prepare_rma_line_from_sale_order_line(self, line):
|
||||||
operation = line.product_id.rma_customer_operation_id
|
operation = line.product_id.rma_customer_operation_id
|
||||||
if not operation:
|
if not operation:
|
||||||
operation = line.product_id.categ_id.rma_customer_operation_id
|
operation = line.product_id.categ_id.rma_customer_operation_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
|
||||||
|
)
|
||||||
if not operation:
|
if not operation:
|
||||||
raise ValidationError(_("Please define an operation first"))
|
raise ValidationError(_("Please define an operation first"))
|
||||||
if not operation.in_route_id or not operation.out_route_id:
|
if not operation.in_route_id or not operation.out_route_id:
|
||||||
route = self.env['stock.location.route'].search(
|
route = self.env["stock.location.route"].search(
|
||||||
[('rma_selectable', '=', True)], limit=1)
|
[("rma_selectable", "=", True)], limit=1
|
||||||
|
)
|
||||||
if not route:
|
if not route:
|
||||||
raise ValidationError(_("Please define an rma route"))
|
raise ValidationError(_("Please define an rma route"))
|
||||||
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||||
warehouse = self.env['stock.warehouse'].search(
|
warehouse = self.env["stock.warehouse"].search(
|
||||||
[('company_id', '=', self.rma_id.company_id.id),
|
[
|
||||||
('lot_rma_id', '!=', False)], limit=1)
|
("company_id", "=", self.rma_id.company_id.id),
|
||||||
|
("lot_rma_id", "!=", False),
|
||||||
|
],
|
||||||
|
limit=1,
|
||||||
|
)
|
||||||
if not warehouse:
|
if not warehouse:
|
||||||
raise ValidationError(_("Please define a warehouse with a "
|
raise ValidationError(
|
||||||
"default rma location."))
|
_("Please define a warehouse with a " "default rma location.")
|
||||||
|
)
|
||||||
data = {
|
data = {
|
||||||
'partner_id': self.partner_id.id,
|
"partner_id": self.partner_id.id,
|
||||||
'sale_line_id': line.id,
|
"sale_line_id": line.id,
|
||||||
'product_id': line.product_id.id,
|
"product_id": line.product_id.id,
|
||||||
'origin': line.order_id.name,
|
"origin": line.order_id.name,
|
||||||
'uom_id': line.product_uom.id,
|
"uom_id": line.product_uom.id,
|
||||||
'operation_id': operation.id,
|
"operation_id": operation.id,
|
||||||
'product_qty': line.product_uom_qty,
|
"product_qty": line.product_uom_qty,
|
||||||
'delivery_address_id': self.sale_id.partner_id.id,
|
"delivery_address_id": self.sale_id.partner_id.id,
|
||||||
'invoice_address_id': self.sale_id.partner_id.id,
|
"invoice_address_id": self.sale_id.partner_id.id,
|
||||||
'price_unit': line.currency_id.compute(
|
"price_unit": line.currency_id.compute(
|
||||||
line.price_unit, line.currency_id, round=False),
|
line.price_unit, line.currency_id, round=False
|
||||||
'rma_id': self.rma_id.id,
|
),
|
||||||
'in_route_id': operation.in_route_id.id or route.id,
|
"rma_id": self.rma_id.id,
|
||||||
'out_route_id': operation.out_route_id.id or route.id,
|
"in_route_id": operation.in_route_id.id or route.id,
|
||||||
'receipt_policy': operation.receipt_policy,
|
"out_route_id": operation.out_route_id.id or route.id,
|
||||||
'location_id': (operation.location_id.id or
|
"receipt_policy": operation.receipt_policy,
|
||||||
operation.in_warehouse_id.lot_rma_id.id or
|
"location_id": (
|
||||||
warehouse.lot_rma_id.id),
|
operation.location_id.id
|
||||||
'refund_policy': operation.refund_policy,
|
or operation.in_warehouse_id.lot_rma_id.id
|
||||||
'delivery_policy': operation.delivery_policy,
|
or warehouse.lot_rma_id.id
|
||||||
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
),
|
||||||
'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id,
|
"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,
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_rma_data(self):
|
def _get_rma_data(self):
|
||||||
data = {
|
data = {
|
||||||
'date_rma': fields.Datetime.now(),
|
"date_rma": fields.Datetime.now(),
|
||||||
'delivery_address_id': self.sale_id.partner_id.id,
|
"delivery_address_id": self.sale_id.partner_id.id,
|
||||||
'invoice_address_id': self.sale_id.partner_id.id
|
"invoice_address_id": self.sale_id.partner_id.id,
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -102,7 +117,7 @@ class RmaAddSale(models.TransientModel):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def add_lines(self):
|
def add_lines(self):
|
||||||
rma_line_obj = self.env['rma.order.line']
|
rma_line_obj = self.env["rma.order.line"]
|
||||||
existing_sale_lines = self._get_existing_sale_lines()
|
existing_sale_lines = self._get_existing_sale_lines()
|
||||||
for line in self.sale_line_ids:
|
for line in self.sale_line_ids:
|
||||||
# Load a PO line only once
|
# Load a PO line only once
|
||||||
@@ -112,4 +127,4 @@ class RmaAddSale(models.TransientModel):
|
|||||||
rma = self.rma_id
|
rma = self.rma_id
|
||||||
data_rma = self._get_rma_data()
|
data_rma = self._get_rma_data()
|
||||||
rma.write(data_rma)
|
rma.write(data_rma)
|
||||||
return {'type': 'ir.actions.act_window_close'}
|
return {"type": "ir.actions.act_window_close"}
|
||||||
|
|||||||
@@ -4,17 +4,16 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
|
|
||||||
class RmaMakePicking(models.TransientModel):
|
class RmaMakePicking(models.TransientModel):
|
||||||
_inherit = 'rma_make_picking.wizard'
|
_inherit = "rma_make_picking.wizard"
|
||||||
|
|
||||||
@api.returns('rma.order.line')
|
@api.returns("rma.order.line")
|
||||||
def _prepare_item(self, line):
|
def _prepare_item(self, line):
|
||||||
res = super(RmaMakePicking, self)._prepare_item(line)
|
res = super(RmaMakePicking, self)._prepare_item(line)
|
||||||
res['sale_line_id'] = line.sale_line_id.id
|
res["sale_line_id"] = line.sale_line_id.id
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
class RmaMakePickingItem(models.TransientModel):
|
class RmaMakePickingItem(models.TransientModel):
|
||||||
_inherit = "rma_make_picking.wizard.item"
|
_inherit = "rma_make_picking.wizard.item"
|
||||||
|
|
||||||
sale_line_id = fields.Many2one(
|
sale_line_id = fields.Many2one(comodel_name="sale.order.line", string="Sale Line")
|
||||||
comodel_name='sale.order.line', string='Sale Line')
|
|
||||||
|
|||||||
@@ -1,73 +1,83 @@
|
|||||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
|
|
||||||
import odoo.addons.decimal_precision as dp
|
|
||||||
from odoo import _, api, exceptions, fields, models
|
from odoo import _, api, exceptions, fields, models
|
||||||
|
|
||||||
|
import odoo.addons.decimal_precision as dp
|
||||||
|
|
||||||
|
|
||||||
class RmaLineMakeSaleOrder(models.TransientModel):
|
class RmaLineMakeSaleOrder(models.TransientModel):
|
||||||
_name = "rma.order.line.make.sale.order"
|
_name = "rma.order.line.make.sale.order"
|
||||||
_description = "Make Sales Order from RMA Line"
|
_description = "Make Sales Order from RMA Line"
|
||||||
|
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
comodel_name='res.partner', string='Customer', required=False,
|
comodel_name="res.partner",
|
||||||
domain=[('customer', '=', True)])
|
string="Customer",
|
||||||
|
required=False,
|
||||||
|
domain=[("customer", "=", True)],
|
||||||
|
)
|
||||||
item_ids = fields.One2many(
|
item_ids = fields.One2many(
|
||||||
comodel_name='rma.order.line.make.sale.order.item',
|
comodel_name="rma.order.line.make.sale.order.item",
|
||||||
inverse_name='wiz_id', string='Items')
|
inverse_name="wiz_id",
|
||||||
|
string="Items",
|
||||||
|
)
|
||||||
sale_order_id = fields.Many2one(
|
sale_order_id = fields.Many2one(
|
||||||
comodel_name='sale.order', string='Sales Order', required=False,
|
comodel_name="sale.order",
|
||||||
domain=[('state', '=', 'draft')])
|
string="Sales Order",
|
||||||
|
required=False,
|
||||||
|
domain=[("state", "=", "draft")],
|
||||||
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_item(self, line):
|
def _prepare_item(self, line):
|
||||||
return {
|
return {
|
||||||
'line_id': line.id,
|
"line_id": line.id,
|
||||||
'product_id': line.product_id.id,
|
"product_id": line.product_id.id,
|
||||||
'name': line.product_id.name,
|
"name": line.product_id.name,
|
||||||
'product_qty': line.qty_to_sell,
|
"product_qty": line.qty_to_sell,
|
||||||
'rma_id': line.rma_id.id,
|
"rma_id": line.rma_id.id,
|
||||||
'out_warehouse_id': line.out_warehouse_id.id,
|
"out_warehouse_id": line.out_warehouse_id.id,
|
||||||
'product_uom_id': line.uom_id.id,
|
"product_uom_id": line.uom_id.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
res = super(RmaLineMakeSaleOrder, self).default_get(
|
res = super(RmaLineMakeSaleOrder, self).default_get(fields_list)
|
||||||
fields_list)
|
rma_line_obj = self.env["rma.order.line"]
|
||||||
rma_line_obj = self.env['rma.order.line']
|
rma_line_ids = self.env.context["active_ids"] or []
|
||||||
rma_line_ids = self.env.context['active_ids'] or []
|
active_model = self.env.context["active_model"]
|
||||||
active_model = self.env.context['active_model']
|
|
||||||
|
|
||||||
if not rma_line_ids:
|
if not rma_line_ids:
|
||||||
return res
|
return res
|
||||||
assert active_model == 'rma.order.line', 'Bad context propagation'
|
assert active_model == "rma.order.line", "Bad context propagation"
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
lines = rma_line_obj.browse(rma_line_ids)
|
lines = rma_line_obj.browse(rma_line_ids)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
items.append([0, 0, self._prepare_item(line)])
|
items.append([0, 0, self._prepare_item(line)])
|
||||||
customers = lines.mapped('partner_id')
|
customers = lines.mapped("partner_id")
|
||||||
if len(customers) == 1:
|
if len(customers) == 1:
|
||||||
res['partner_id'] = customers.id
|
res["partner_id"] = customers.id
|
||||||
else:
|
else:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_('Only RMA lines from the same partner can be processed at '
|
_(
|
||||||
'the same time'))
|
"Only RMA lines from the same partner can be processed at "
|
||||||
res['item_ids'] = items
|
"the same time"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
res["item_ids"] = items
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_sale_order(self, out_warehouse, company, item):
|
def _prepare_sale_order(self, out_warehouse, company, item):
|
||||||
if not self.partner_id:
|
if not self.partner_id:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(_("Enter a customer."))
|
||||||
_('Enter a customer.'))
|
|
||||||
customer = self.partner_id
|
customer = self.partner_id
|
||||||
data = {
|
data = {
|
||||||
'origin': item.line_id.name,
|
"origin": item.line_id.name,
|
||||||
'partner_id': customer.id,
|
"partner_id": customer.id,
|
||||||
'warehouse_id': out_warehouse.id,
|
"warehouse_id": out_warehouse.id,
|
||||||
'company_id': company.id,
|
"company_id": company.id,
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -75,46 +85,44 @@ class RmaLineMakeSaleOrder(models.TransientModel):
|
|||||||
def _prepare_sale_order_line(self, so, item):
|
def _prepare_sale_order_line(self, so, item):
|
||||||
product = item.product_id
|
product = item.product_id
|
||||||
vals = {
|
vals = {
|
||||||
'name': product.name,
|
"name": product.name,
|
||||||
'order_id': so.id,
|
"order_id": so.id,
|
||||||
'product_id': product.id,
|
"product_id": product.id,
|
||||||
'product_uom': product.uom_po_id.id,
|
"product_uom": product.uom_po_id.id,
|
||||||
'product_uom_qty': item.product_qty,
|
"product_uom_qty": item.product_qty,
|
||||||
'rma_line_id': item.line_id.id
|
"rma_line_id": item.line_id.id,
|
||||||
}
|
}
|
||||||
if item.free_of_charge:
|
if item.free_of_charge:
|
||||||
vals['price_unit'] = 0.0
|
vals["price_unit"] = 0.0
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def make_sale_order(self):
|
def make_sale_order(self):
|
||||||
res = []
|
res = []
|
||||||
sale_obj = self.env['sale.order']
|
sale_obj = self.env["sale.order"]
|
||||||
so_line_obj = self.env['sale.order.line']
|
so_line_obj = self.env["sale.order.line"]
|
||||||
sale = False
|
sale = False
|
||||||
|
|
||||||
for item in self.item_ids:
|
for item in self.item_ids:
|
||||||
line = item.line_id
|
line = item.line_id
|
||||||
if item.product_qty <= 0.0:
|
if item.product_qty <= 0.0:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(_("Enter a positive quantity."))
|
||||||
_('Enter a positive quantity.'))
|
|
||||||
|
|
||||||
if self.sale_order_id:
|
if self.sale_order_id:
|
||||||
sale = self.sale_order_id
|
sale = self.sale_order_id
|
||||||
if not sale:
|
if not sale:
|
||||||
po_data = self._prepare_sale_order(
|
po_data = self._prepare_sale_order(
|
||||||
line.out_warehouse_id,
|
line.out_warehouse_id, line.company_id, item
|
||||||
line.company_id,
|
)
|
||||||
item)
|
|
||||||
sale = sale_obj.create(po_data)
|
sale = sale_obj.create(po_data)
|
||||||
|
|
||||||
so_line_data = self._prepare_sale_order_line(sale, item)
|
so_line_data = self._prepare_sale_order_line(sale, item)
|
||||||
so_line_obj.create(so_line_data)
|
so_line_obj.create(so_line_data)
|
||||||
res.append(sale.id)
|
res.append(sale.id)
|
||||||
|
|
||||||
action = self.env.ref('sale.action_orders')
|
action = self.env.ref("sale.action_orders")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
result['domain'] = "[('id','in', ["+','.join(map(str, res))+"])]"
|
result["domain"] = "[('id','in', [" + ",".join(map(str, res)) + "])]"
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@@ -123,18 +131,19 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
|
|||||||
_description = "RMA Line Make Sale Order Item"
|
_description = "RMA Line Make Sale Order Item"
|
||||||
|
|
||||||
wiz_id = fields.Many2one(
|
wiz_id = fields.Many2one(
|
||||||
comodel_name='rma.order.line.make.sale.order', string='Wizard')
|
comodel_name="rma.order.line.make.sale.order", string="Wizard"
|
||||||
line_id = fields.Many2one(
|
)
|
||||||
comodel_name='rma.order.line', string='RMA Line')
|
line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA Line")
|
||||||
rma_id = fields.Many2one(
|
rma_id = fields.Many2one(
|
||||||
comodel_name='rma.order', related='line_id.rma_id', readonly=False)
|
comodel_name="rma.order", related="line_id.rma_id", readonly=False
|
||||||
product_id = fields.Many2one(
|
)
|
||||||
comodel_name='product.product', string='Product')
|
product_id = fields.Many2one(comodel_name="product.product", string="Product")
|
||||||
name = fields.Char(string='Description')
|
name = fields.Char(string="Description")
|
||||||
product_qty = fields.Float(
|
product_qty = fields.Float(
|
||||||
string='Quantity to sell', digits=dp.get_precision('Product UoS'))
|
string="Quantity to sell", digits=dp.get_precision("Product UoS")
|
||||||
product_uom_id = fields.Many2one(
|
)
|
||||||
comodel_name='uom.uom', string='UoM')
|
product_uom_id = fields.Many2one(comodel_name="uom.uom", string="UoM")
|
||||||
out_warehouse_id = fields.Many2one(
|
out_warehouse_id = fields.Many2one(
|
||||||
comodel_name='stock.warehouse', string='Outbound Warehouse')
|
comodel_name="stock.warehouse", string="Outbound Warehouse"
|
||||||
free_of_charge = fields.Boolean(string='Free of Charge')
|
)
|
||||||
|
free_of_charge = fields.Boolean(string="Free of Charge")
|
||||||
|
|||||||
@@ -60,4 +60,3 @@
|
|||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ from odoo import api, fields, models
|
|||||||
class RmaRefund(models.TransientModel):
|
class RmaRefund(models.TransientModel):
|
||||||
_inherit = "rma.refund"
|
_inherit = "rma.refund"
|
||||||
|
|
||||||
@api.returns('rma.order.line')
|
@api.returns("rma.order.line")
|
||||||
def _prepare_item(self, line):
|
def _prepare_item(self, line):
|
||||||
res = super(RmaRefund, self)._prepare_item(line)
|
res = super(RmaRefund, self)._prepare_item(line)
|
||||||
res['sale_line_id'] = line.sale_line_id.id
|
res["sale_line_id"] = line.sale_line_id.id
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
@@ -17,4 +17,5 @@ class RmaRefundItem(models.TransientModel):
|
|||||||
_inherit = "rma.refund.item"
|
_inherit = "rma.refund.item"
|
||||||
|
|
||||||
sale_line_id = fields.Many2one(
|
sale_line_id = fields.Many2one(
|
||||||
comodel_name='sale.order.line', string='Sale Order Line')
|
comodel_name="sale.order.line", string="Sale Order Line"
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user