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:
@@ -2,36 +2,36 @@
|
|||||||
# 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 (Return Merchandise Authorization)',
|
"name": "RMA (Return Merchandise Authorization)",
|
||||||
'version': '12.0.2.3.0',
|
"version": "12.0.2.3.0",
|
||||||
'license': 'LGPL-3',
|
"license": "LGPL-3",
|
||||||
'category': 'RMA',
|
"category": "RMA",
|
||||||
'summary': 'Introduces the return merchandise authorization (RMA) process '
|
"summary": "Introduces the return merchandise authorization (RMA) process "
|
||||||
'in odoo',
|
"in odoo",
|
||||||
'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': ['stock', 'mail', 'web'],
|
"depends": ["stock", "mail", "web"],
|
||||||
'demo': ['demo/stock_demo.xml',
|
"demo": ["demo/stock_demo.xml"],
|
||||||
|
"data": [
|
||||||
|
"security/rma.xml",
|
||||||
|
"security/ir.model.access.csv",
|
||||||
|
"data/rma_sequence.xml",
|
||||||
|
"data/stock_data.xml",
|
||||||
|
"data/rma_operation.xml",
|
||||||
|
"report/rma_report.xml",
|
||||||
|
"report/rma_report_templates.xml",
|
||||||
|
"views/rma_order_view.xml",
|
||||||
|
"views/rma_operation_view.xml",
|
||||||
|
"views/rma_order_line_view.xml",
|
||||||
|
"views/stock_view.xml",
|
||||||
|
"views/stock_warehouse.xml",
|
||||||
|
"views/product_view.xml",
|
||||||
|
"views/res_partner_view.xml",
|
||||||
|
"wizards/rma_make_picking_view.xml",
|
||||||
|
"wizards/rma_add_stock_move_view.xml",
|
||||||
|
"wizards/stock_config_settings.xml",
|
||||||
|
"wizards/rma_order_line_make_supplier_rma_view.xml",
|
||||||
],
|
],
|
||||||
'data': ['security/rma.xml',
|
"installable": True,
|
||||||
'security/ir.model.access.csv',
|
"auto_install": False,
|
||||||
'data/rma_sequence.xml',
|
|
||||||
'data/stock_data.xml',
|
|
||||||
'data/rma_operation.xml',
|
|
||||||
'report/rma_report.xml',
|
|
||||||
'report/rma_report_templates.xml',
|
|
||||||
'views/rma_order_view.xml',
|
|
||||||
'views/rma_operation_view.xml',
|
|
||||||
'views/rma_order_line_view.xml',
|
|
||||||
'views/stock_view.xml',
|
|
||||||
'views/stock_warehouse.xml',
|
|
||||||
'views/product_view.xml',
|
|
||||||
'views/res_partner_view.xml',
|
|
||||||
'wizards/rma_make_picking_view.xml',
|
|
||||||
'wizards/rma_add_stock_move_view.xml',
|
|
||||||
'wizards/stock_config_settings.xml',
|
|
||||||
'wizards/rma_order_line_make_supplier_rma_view.xml',
|
|
||||||
],
|
|
||||||
'installable': True,
|
|
||||||
'auto_install': False,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,43 +5,52 @@ from odoo import fields, models
|
|||||||
|
|
||||||
|
|
||||||
class StockRule(models.Model):
|
class StockRule(models.Model):
|
||||||
_inherit = 'stock.rule'
|
_inherit = "stock.rule"
|
||||||
|
|
||||||
rma_line_id = fields.Many2one(
|
rma_line_id = fields.Many2one(
|
||||||
comodel_name='rma.order.line', string='RMA line',
|
comodel_name="rma.order.line", string="RMA line", ondelete="set null"
|
||||||
ondelete="set null",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_stock_move_values(self, product_id, product_qty, product_uom,
|
def _get_stock_move_values(
|
||||||
location_id, name, origin, values, group_id):
|
self,
|
||||||
res = super(StockRule, self)._get_stock_move_values(product_id,
|
product_id,
|
||||||
product_qty,
|
product_qty,
|
||||||
product_uom,
|
product_uom,
|
||||||
location_id,
|
location_id,
|
||||||
name, origin,
|
name,
|
||||||
values, group_id)
|
origin,
|
||||||
if 'rma_line_id' in values:
|
values,
|
||||||
line = self.env['rma.order.line'].browse(values.get('rma_line_id'))
|
group_id,
|
||||||
res['rma_line_id'] = line.id
|
):
|
||||||
|
res = super(StockRule, self)._get_stock_move_values(
|
||||||
|
product_id,
|
||||||
|
product_qty,
|
||||||
|
product_uom,
|
||||||
|
location_id,
|
||||||
|
name,
|
||||||
|
origin,
|
||||||
|
values,
|
||||||
|
group_id,
|
||||||
|
)
|
||||||
|
if "rma_line_id" in values:
|
||||||
|
line = self.env["rma.order.line"].browse(values.get("rma_line_id"))
|
||||||
|
res["rma_line_id"] = line.id
|
||||||
if line.delivery_address_id:
|
if line.delivery_address_id:
|
||||||
res['partner_id'] = line.delivery_address_id.id
|
res["partner_id"] = line.delivery_address_id.id
|
||||||
else:
|
else:
|
||||||
res['partner_id'] = line.rma_id.partner_id.id
|
res["partner_id"] = line.rma_id.partner_id.id
|
||||||
dest_loc = self.env["stock.location"].browse([
|
dest_loc = self.env["stock.location"].browse([res["location_dest_id"]])[0]
|
||||||
res["location_dest_id"]])[0]
|
|
||||||
if dest_loc.usage == "internal":
|
if dest_loc.usage == "internal":
|
||||||
res["price_unit"] = line.price_unit
|
res["price_unit"] = line.price_unit
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
class ProcurementGroup(models.Model):
|
class ProcurementGroup(models.Model):
|
||||||
_inherit = 'procurement.group'
|
_inherit = "procurement.group"
|
||||||
|
|
||||||
rma_id = fields.Many2one(
|
rma_id = fields.Many2one(
|
||||||
comodel_name='rma.order', string='RMA',
|
comodel_name="rma.order", string="RMA", ondelete="set null"
|
||||||
ondelete="set null",
|
|
||||||
)
|
)
|
||||||
rma_line_id = fields.Many2one(
|
rma_line_id = fields.Many2one(
|
||||||
comodel_name='rma.order.line', string='RMA line',
|
comodel_name="rma.order.line", string="RMA line", ondelete="set null"
|
||||||
ondelete="set null",
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ from odoo import fields, models
|
|||||||
|
|
||||||
|
|
||||||
class ProductTemplate(models.Model):
|
class ProductTemplate(models.Model):
|
||||||
_inherit = 'product.template'
|
_inherit = "product.template"
|
||||||
|
|
||||||
rma_customer_operation_id = fields.Many2one(
|
rma_customer_operation_id = fields.Many2one(
|
||||||
comodel_name="rma.operation", string="Default RMA Customer Operation")
|
comodel_name="rma.operation", string="Default RMA Customer Operation"
|
||||||
|
)
|
||||||
rma_supplier_operation_id = fields.Many2one(
|
rma_supplier_operation_id = fields.Many2one(
|
||||||
comodel_name="rma.operation", string="Default RMA Supplier Operation")
|
comodel_name="rma.operation", string="Default RMA Supplier Operation"
|
||||||
|
)
|
||||||
rma_approval_policy = fields.Selection(
|
rma_approval_policy = fields.Selection(
|
||||||
related="categ_id.rma_approval_policy", readonly=True)
|
related="categ_id.rma_approval_policy", readonly=True
|
||||||
|
)
|
||||||
|
|||||||
@@ -8,14 +8,19 @@ class ProductCategory(models.Model):
|
|||||||
_inherit = "product.category"
|
_inherit = "product.category"
|
||||||
|
|
||||||
rma_approval_policy = fields.Selection(
|
rma_approval_policy = fields.Selection(
|
||||||
selection=[('one_step', 'One step'), ('two_step', 'Two steps')],
|
selection=[("one_step", "One step"), ("two_step", "Two steps")],
|
||||||
string="RMA Approval Policy", required=True, default='one_step',
|
string="RMA Approval Policy",
|
||||||
|
required=True,
|
||||||
|
default="one_step",
|
||||||
help="Options: \n "
|
help="Options: \n "
|
||||||
"* One step: Always auto-approve RMAs that only contain "
|
"* One step: Always auto-approve RMAs that only contain "
|
||||||
"products within categories with this policy.\n"
|
"products within categories with this policy.\n"
|
||||||
"* Two steps: A RMA containing a product within a category with "
|
"* Two steps: A RMA containing a product within a category with "
|
||||||
"this policy will request the RMA manager approval.")
|
"this policy will request the RMA manager approval.",
|
||||||
|
)
|
||||||
rma_customer_operation_id = fields.Many2one(
|
rma_customer_operation_id = fields.Many2one(
|
||||||
comodel_name="rma.operation", string="Default RMA Customer Operation")
|
comodel_name="rma.operation", string="Default RMA Customer Operation"
|
||||||
|
)
|
||||||
rma_supplier_operation_id = fields.Many2one(
|
rma_supplier_operation_id = fields.Many2one(
|
||||||
comodel_name="rma.operation", string="Default RMA Supplier Operation")
|
comodel_name="rma.operation", string="Default RMA Supplier Operation"
|
||||||
|
)
|
||||||
|
|||||||
@@ -13,14 +13,13 @@ class ResPartner(models.Model):
|
|||||||
rec.rma_line_count = len(rec.rma_line_ids)
|
rec.rma_line_count = len(rec.rma_line_ids)
|
||||||
|
|
||||||
rma_line_ids = fields.One2many(
|
rma_line_ids = fields.One2many(
|
||||||
comodel_name="rma.order.line", string="RMAs",
|
comodel_name="rma.order.line", string="RMAs", inverse_name="partner_id"
|
||||||
inverse_name="partner_id",
|
|
||||||
)
|
)
|
||||||
rma_line_count = fields.Integer(compute="_compute_rma_line_count")
|
rma_line_count = fields.Integer(compute="_compute_rma_line_count")
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_open_partner_rma(self):
|
def action_open_partner_rma(self):
|
||||||
action = self.env.ref('rma.action_rma_customer_lines')
|
action = self.env.ref("rma.action_rma_customer_lines")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
result['context'] = {'search_default_partner_id': self.id}
|
result["context"] = {"search_default_partner_id": self.id}
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -5,77 +5,94 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
|
|
||||||
class RmaOperation(models.Model):
|
class RmaOperation(models.Model):
|
||||||
_name = 'rma.operation'
|
_name = "rma.operation"
|
||||||
_description = 'RMA Operation'
|
_description = "RMA Operation"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _default_warehouse_id(self):
|
def _default_warehouse_id(self):
|
||||||
company_id = self.env.user.company_id.id
|
company_id = self.env.user.company_id.id
|
||||||
warehouse = self.env['stock.warehouse'].search(
|
warehouse = self.env["stock.warehouse"].search(
|
||||||
[('company_id', '=', company_id)], limit=1)
|
[("company_id", "=", company_id)], limit=1
|
||||||
|
)
|
||||||
return warehouse
|
return warehouse
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _default_customer_location_id(self):
|
def _default_customer_location_id(self):
|
||||||
return self.env.ref('stock.stock_location_customers') or False
|
return self.env.ref("stock.stock_location_customers") or False
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _default_supplier_location_id(self):
|
def _default_supplier_location_id(self):
|
||||||
return self.env.ref('stock.stock_location_suppliers') or False
|
return self.env.ref("stock.stock_location_suppliers") or False
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _default_routes(self):
|
def _default_routes(self):
|
||||||
op_type = self.env.context.get('default_type')
|
op_type = self.env.context.get("default_type")
|
||||||
if op_type == 'customer':
|
if op_type == "customer":
|
||||||
return self.env.ref('rma.route_rma_customer')
|
return self.env.ref("rma.route_rma_customer")
|
||||||
elif op_type == 'supplier':
|
elif op_type == "supplier":
|
||||||
return self.env.ref('rma.route_rma_supplier')
|
return self.env.ref("rma.route_rma_supplier")
|
||||||
|
|
||||||
name = fields.Char('Description', required=True)
|
name = fields.Char("Description", required=True)
|
||||||
code = fields.Char('Code', required=True)
|
code = fields.Char("Code", required=True)
|
||||||
active = fields.Boolean(string='Active', default=True)
|
active = fields.Boolean(string="Active", default=True)
|
||||||
receipt_policy = fields.Selection([
|
receipt_policy = fields.Selection(
|
||||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
[
|
||||||
('delivered', 'Based on Delivered Quantities')],
|
("no", "Not required"),
|
||||||
string="Receipts Policy", default='no')
|
("ordered", "Based on Ordered Quantities"),
|
||||||
delivery_policy = fields.Selection([
|
("delivered", "Based on Delivered Quantities"),
|
||||||
('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'),
|
],
|
||||||
('received', 'Based on Received Quantities')],
|
string="Receipts Policy",
|
||||||
string="Delivery Policy", default='no')
|
default="no",
|
||||||
|
)
|
||||||
|
delivery_policy = fields.Selection(
|
||||||
|
[
|
||||||
|
("no", "Not required"),
|
||||||
|
("ordered", "Based on Ordered Quantities"),
|
||||||
|
("received", "Based on Received Quantities"),
|
||||||
|
],
|
||||||
|
string="Delivery Policy",
|
||||||
|
default="no",
|
||||||
|
)
|
||||||
in_route_id = fields.Many2one(
|
in_route_id = fields.Many2one(
|
||||||
comodel_name='stock.location.route', string='Inbound Route',
|
comodel_name="stock.location.route",
|
||||||
domain=[('rma_selectable', '=', True)],
|
string="Inbound Route",
|
||||||
|
domain=[("rma_selectable", "=", True)],
|
||||||
default=lambda self: self._default_routes(),
|
default=lambda self: self._default_routes(),
|
||||||
)
|
)
|
||||||
out_route_id = fields.Many2one(
|
out_route_id = fields.Many2one(
|
||||||
comodel_name='stock.location.route', string='Outbound Route',
|
comodel_name="stock.location.route",
|
||||||
domain=[('rma_selectable', '=', True)],
|
string="Outbound Route",
|
||||||
|
domain=[("rma_selectable", "=", True)],
|
||||||
default=lambda self: self._default_routes(),
|
default=lambda self: self._default_routes(),
|
||||||
)
|
)
|
||||||
customer_to_supplier = fields.Boolean(
|
customer_to_supplier = fields.Boolean(
|
||||||
string='The customer will send to the supplier',
|
string="The customer will send to the supplier"
|
||||||
)
|
)
|
||||||
supplier_to_customer = fields.Boolean(
|
supplier_to_customer = fields.Boolean(
|
||||||
string='The supplier will send to the customer',
|
string="The supplier will send to the customer"
|
||||||
)
|
)
|
||||||
in_warehouse_id = fields.Many2one(
|
in_warehouse_id = fields.Many2one(
|
||||||
comodel_name='stock.warehouse', string='Inbound Warehouse',
|
comodel_name="stock.warehouse",
|
||||||
|
string="Inbound Warehouse",
|
||||||
default=lambda self: self._default_warehouse_id(),
|
default=lambda self: self._default_warehouse_id(),
|
||||||
)
|
)
|
||||||
out_warehouse_id = fields.Many2one(
|
out_warehouse_id = fields.Many2one(
|
||||||
comodel_name='stock.warehouse', string='Outbound Warehouse',
|
comodel_name="stock.warehouse",
|
||||||
|
string="Outbound Warehouse",
|
||||||
default=lambda self: self._default_warehouse_id(),
|
default=lambda self: self._default_warehouse_id(),
|
||||||
)
|
)
|
||||||
location_id = fields.Many2one(
|
location_id = fields.Many2one("stock.location", "Send To This Company Location")
|
||||||
'stock.location', 'Send To This Company Location')
|
type = fields.Selection(
|
||||||
type = fields.Selection([
|
[("customer", "Customer"), ("supplier", "Supplier")],
|
||||||
('customer', 'Customer'), ('supplier', 'Supplier')],
|
string="Used in RMA of this type",
|
||||||
string="Used in RMA of this type", required=True)
|
required=True,
|
||||||
|
)
|
||||||
rma_line_ids = fields.One2many(
|
rma_line_ids = fields.One2many(
|
||||||
comodel_name='rma.order.line', inverse_name='operation_id',
|
comodel_name="rma.order.line", inverse_name="operation_id", string="RMA lines"
|
||||||
string='RMA lines',
|
|
||||||
)
|
)
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
comodel_name='res.company', string='Company', required=True,
|
comodel_name="res.company",
|
||||||
default=lambda self: self.env.user.company_id
|
string="Company",
|
||||||
|
required=True,
|
||||||
|
default=lambda self: self.env.user.company_id,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
# Copyright (C) 2017 Eficent Business and IT Consulting Services S.L.
|
# Copyright (C) 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.exceptions import UserError
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
class RmaOrder(models.Model):
|
class RmaOrder(models.Model):
|
||||||
_name = "rma.order"
|
_name = "rma.order"
|
||||||
_description = 'RMA Group'
|
_description = "RMA Group"
|
||||||
_inherit = ['mail.thread']
|
_inherit = ["mail.thread"]
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_default_type(self):
|
def _get_default_type(self):
|
||||||
if 'supplier' in self.env.context:
|
if "supplier" in self.env.context:
|
||||||
return "supplier"
|
return "supplier"
|
||||||
return "customer"
|
return "customer"
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ class RmaOrder(models.Model):
|
|||||||
picking_ids = []
|
picking_ids = []
|
||||||
for line in rec.rma_line_ids:
|
for line in rec.rma_line_ids:
|
||||||
for move in line.move_ids:
|
for move in line.move_ids:
|
||||||
if move.location_dest_id.usage == 'internal':
|
if move.location_dest_id.usage == "internal":
|
||||||
picking_ids.append(move.picking_id.id)
|
picking_ids.append(move.picking_id.id)
|
||||||
else:
|
else:
|
||||||
if line.customer_to_supplier:
|
if line.customer_to_supplier:
|
||||||
@@ -37,7 +38,7 @@ class RmaOrder(models.Model):
|
|||||||
for rec in self:
|
for rec in self:
|
||||||
for line in rec.rma_line_ids:
|
for line in rec.rma_line_ids:
|
||||||
for move in line.move_ids:
|
for move in line.move_ids:
|
||||||
if move.location_dest_id.usage in ('supplier', 'customer'):
|
if move.location_dest_id.usage in ("supplier", "customer"):
|
||||||
if not line.customer_to_supplier:
|
if not line.customer_to_supplier:
|
||||||
picking_ids.append(move.picking_id.id)
|
picking_ids.append(move.picking_id.id)
|
||||||
shipments = list(set(picking_ids))
|
shipments = list(set(picking_ids))
|
||||||
@@ -45,34 +46,36 @@ class RmaOrder(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_supplier_line_count(self):
|
def _compute_supplier_line_count(self):
|
||||||
self.supplier_line_count = len(self.rma_line_ids.filtered(
|
self.supplier_line_count = len(
|
||||||
lambda r: r.supplier_rma_line_ids))
|
self.rma_line_ids.filtered(lambda r: r.supplier_rma_line_ids)
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_line_count(self):
|
def _compute_line_count(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.line_count = len(rec._get_valid_lines())
|
rec.line_count = len(rec._get_valid_lines())
|
||||||
|
|
||||||
@api.depends('rma_line_ids', 'rma_line_ids.state')
|
@api.depends("rma_line_ids", "rma_line_ids.state")
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rma_line_done = self.env['rma.order.line'].search_count(
|
rma_line_done = self.env["rma.order.line"].search_count(
|
||||||
[('id', 'in', rec.rma_line_ids.ids), ('state', '=', 'done')])
|
[("id", "in", rec.rma_line_ids.ids), ("state", "=", "done")]
|
||||||
rma_line_approved = self.env['rma.order.line'].search_count(
|
)
|
||||||
[('id', 'in', rec.rma_line_ids.ids),
|
rma_line_approved = self.env["rma.order.line"].search_count(
|
||||||
('state', '=', 'approved')])
|
[("id", "in", rec.rma_line_ids.ids), ("state", "=", "approved")]
|
||||||
rma_line_to_approve = self.env['rma.order.line'].search_count(
|
)
|
||||||
[('id', 'in', rec.rma_line_ids.ids),
|
rma_line_to_approve = self.env["rma.order.line"].search_count(
|
||||||
('state', '=', 'to_approve')])
|
[("id", "in", rec.rma_line_ids.ids), ("state", "=", "to_approve")]
|
||||||
|
)
|
||||||
if rma_line_done != 0:
|
if rma_line_done != 0:
|
||||||
state = 'done'
|
state = "done"
|
||||||
elif rma_line_approved != 0:
|
elif rma_line_approved != 0:
|
||||||
state = 'approved'
|
state = "approved"
|
||||||
elif rma_line_to_approve != 0:
|
elif rma_line_to_approve != 0:
|
||||||
state = 'to_approve'
|
state = "to_approve"
|
||||||
else:
|
else:
|
||||||
state = 'draft'
|
state = "draft"
|
||||||
rec.state = state
|
rec.state = state
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -81,108 +84,114 @@ class RmaOrder(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _default_warehouse_id(self):
|
def _default_warehouse_id(self):
|
||||||
warehouse = self.env['stock.warehouse'].search(
|
warehouse = self.env["stock.warehouse"].search(
|
||||||
[('company_id', '=', self.env.user.company_id.id)], limit=1)
|
[("company_id", "=", self.env.user.company_id.id)], limit=1
|
||||||
|
)
|
||||||
return warehouse
|
return warehouse
|
||||||
|
|
||||||
name = fields.Char(
|
name = fields.Char(string="Group Number", index=True, copy=False)
|
||||||
string='Group Number', index=True, copy=False)
|
|
||||||
type = fields.Selection(
|
type = fields.Selection(
|
||||||
[('customer', 'Customer'), ('supplier', 'Supplier')],
|
[("customer", "Customer"), ("supplier", "Supplier")],
|
||||||
string="Type", required=True,
|
string="Type",
|
||||||
|
required=True,
|
||||||
default=lambda self: self._get_default_type(),
|
default=lambda self: self._get_default_type(),
|
||||||
readonly=True
|
readonly=True,
|
||||||
|
)
|
||||||
|
reference = fields.Char(
|
||||||
|
string="Partner Reference", help="The partner reference of this RMA order."
|
||||||
|
)
|
||||||
|
comment = fields.Text("Additional Information")
|
||||||
|
date_rma = fields.Datetime(
|
||||||
|
string="Order Date", index=True, default=lambda self: self._default_date_rma()
|
||||||
)
|
)
|
||||||
reference = fields.Char(string='Partner Reference',
|
|
||||||
help="The partner reference of this RMA order.")
|
|
||||||
comment = fields.Text('Additional Information')
|
|
||||||
date_rma = fields.Datetime(string='Order Date', index=True,
|
|
||||||
default=lambda self: self._default_date_rma(),)
|
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
comodel_name='res.partner', string='Partner', required=True)
|
comodel_name="res.partner", string="Partner", required=True
|
||||||
rma_line_ids = fields.One2many('rma.order.line', 'rma_id',
|
)
|
||||||
string='RMA lines')
|
rma_line_ids = fields.One2many("rma.order.line", "rma_id", string="RMA lines")
|
||||||
in_shipment_count = fields.Integer(compute='_compute_in_shipment_count',
|
in_shipment_count = fields.Integer(
|
||||||
string='# of Invoices')
|
compute="_compute_in_shipment_count", string="# of Invoices"
|
||||||
out_shipment_count = fields.Integer(compute='_compute_out_shipment_count',
|
)
|
||||||
string='# of Outgoing Shipments')
|
out_shipment_count = fields.Integer(
|
||||||
line_count = fields.Integer(compute='_compute_line_count',
|
compute="_compute_out_shipment_count", string="# of Outgoing Shipments"
|
||||||
string='# of Outgoing Shipments')
|
)
|
||||||
supplier_line_count = fields.Integer(
|
line_count = fields.Integer(
|
||||||
compute='_compute_supplier_line_count',
|
compute="_compute_line_count", string="# of Outgoing Shipments"
|
||||||
string='# of Supplier RMAs'
|
)
|
||||||
|
supplier_line_count = fields.Integer(
|
||||||
|
compute="_compute_supplier_line_count", string="# of Supplier RMAs"
|
||||||
|
)
|
||||||
|
company_id = fields.Many2one(
|
||||||
|
"res.company",
|
||||||
|
string="Company",
|
||||||
|
required=True,
|
||||||
|
default=lambda self: self.env.user.company_id,
|
||||||
)
|
)
|
||||||
company_id = fields.Many2one('res.company', string='Company',
|
|
||||||
required=True, default=lambda self:
|
|
||||||
self.env.user.company_id)
|
|
||||||
assigned_to = fields.Many2one(
|
assigned_to = fields.Many2one(
|
||||||
comodel_name='res.users', track_visibility='onchange',
|
comodel_name="res.users",
|
||||||
|
track_visibility="onchange",
|
||||||
default=lambda self: self.env.uid,
|
default=lambda self: self.env.uid,
|
||||||
)
|
)
|
||||||
requested_by = fields.Many2one(
|
requested_by = fields.Many2one(
|
||||||
comodel_name='res.users', track_visibility='onchange',
|
comodel_name="res.users",
|
||||||
|
track_visibility="onchange",
|
||||||
default=lambda self: self.env.uid,
|
default=lambda self: self.env.uid,
|
||||||
)
|
)
|
||||||
in_warehouse_id = fields.Many2one(
|
in_warehouse_id = fields.Many2one(
|
||||||
comodel_name='stock.warehouse',
|
comodel_name="stock.warehouse",
|
||||||
string='Inbound Warehouse',
|
string="Inbound Warehouse",
|
||||||
required=True,
|
required=True,
|
||||||
default=_default_warehouse_id,
|
default=_default_warehouse_id,
|
||||||
)
|
)
|
||||||
customer_to_supplier = fields.Boolean(
|
customer_to_supplier = fields.Boolean("The customer will send to the supplier")
|
||||||
'The customer will send to the supplier',
|
supplier_to_customer = fields.Boolean("The supplier will send to the customer")
|
||||||
)
|
|
||||||
supplier_to_customer = fields.Boolean(
|
|
||||||
'The supplier will send to the customer',
|
|
||||||
)
|
|
||||||
supplier_address_id = fields.Many2one(
|
supplier_address_id = fields.Many2one(
|
||||||
comodel_name='res.partner',
|
comodel_name="res.partner",
|
||||||
string='Supplier Address',
|
string="Supplier Address",
|
||||||
help="Address of the supplier in case of Customer RMA operation "
|
help="Address of the supplier in case of Customer RMA operation " "dropship.",
|
||||||
"dropship.")
|
)
|
||||||
customer_address_id = fields.Many2one(
|
customer_address_id = fields.Many2one(
|
||||||
comodel_name='res.partner',
|
comodel_name="res.partner",
|
||||||
string='Customer Address',
|
string="Customer Address",
|
||||||
help="Address of the customer in case of Supplier RMA operation "
|
help="Address of the customer in case of Supplier RMA operation " "dropship.",
|
||||||
"dropship.")
|
)
|
||||||
state = fields.Selection(
|
state = fields.Selection(
|
||||||
compute=_compute_state,
|
compute=_compute_state,
|
||||||
selection=[('draft', 'Draft'),
|
selection=[
|
||||||
('to_approve', 'To Approve'),
|
("draft", "Draft"),
|
||||||
('approved', 'Approved'),
|
("to_approve", "To Approve"),
|
||||||
('done', 'Done')],
|
("approved", "Approved"),
|
||||||
string='State', default='draft', store=True
|
("done", "Done"),
|
||||||
|
],
|
||||||
|
string="State",
|
||||||
|
default="draft",
|
||||||
|
store=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.constrains("partner_id", "rma_line_ids")
|
@api.constrains("partner_id", "rma_line_ids")
|
||||||
def _check_partner_id(self):
|
def _check_partner_id(self):
|
||||||
if self.rma_line_ids and self.partner_id != self.mapped(
|
if self.rma_line_ids and self.partner_id != self.mapped(
|
||||||
"rma_line_ids.partner_id"):
|
"rma_line_ids.partner_id"
|
||||||
raise UserError(_(
|
):
|
||||||
"Group partner and RMA's partner must be the same."))
|
raise UserError(_("Group partner and RMA's partner must be the same."))
|
||||||
if len(self.mapped("rma_line_ids.partner_id")) > 1:
|
if len(self.mapped("rma_line_ids.partner_id")) > 1:
|
||||||
raise UserError(_(
|
raise UserError(_("All grouped RMA's should have same partner."))
|
||||||
"All grouped RMA's should have same partner."))
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
if (self.env.context.get('supplier') or
|
if self.env.context.get("supplier") or vals.get("type") == "supplier":
|
||||||
vals.get('type') == 'supplier'):
|
vals["name"] = self.env["ir.sequence"].next_by_code("rma.order.supplier")
|
||||||
vals['name'] = self.env['ir.sequence'].next_by_code(
|
|
||||||
'rma.order.supplier')
|
|
||||||
else:
|
else:
|
||||||
vals['name'] = self.env['ir.sequence'].next_by_code(
|
vals["name"] = self.env["ir.sequence"].next_by_code("rma.order.customer")
|
||||||
'rma.order.customer')
|
|
||||||
return super(RmaOrder, self).create(vals)
|
return super(RmaOrder, self).create(vals)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_in_shipments(self):
|
def action_view_in_shipments(self):
|
||||||
action = self.env.ref('stock.action_picking_tree_all')
|
action = self.env.ref("stock.action_picking_tree_all")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
picking_ids = []
|
picking_ids = []
|
||||||
for line in self.rma_line_ids:
|
for line in self.rma_line_ids:
|
||||||
for move in line.move_ids:
|
for move in line.move_ids:
|
||||||
if move.location_dest_id.usage == 'internal':
|
if move.location_dest_id.usage == "internal":
|
||||||
picking_ids.append(move.picking_id.id)
|
picking_ids.append(move.picking_id.id)
|
||||||
else:
|
else:
|
||||||
if line.customer_to_supplier:
|
if line.customer_to_supplier:
|
||||||
@@ -191,32 +200,32 @@ class RmaOrder(models.Model):
|
|||||||
shipments = list(set(picking_ids))
|
shipments = list(set(picking_ids))
|
||||||
# choose the view_mode accordingly
|
# choose the view_mode accordingly
|
||||||
if len(shipments) > 1:
|
if len(shipments) > 1:
|
||||||
result['domain'] = [('id', 'in', shipments)]
|
result["domain"] = [("id", "in", shipments)]
|
||||||
else:
|
else:
|
||||||
res = self.env.ref('stock.view_picking_form', False)
|
res = self.env.ref("stock.view_picking_form", False)
|
||||||
result['views'] = [(res and res.id or False, 'form')]
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
result['res_id'] = shipments[0]
|
result["res_id"] = shipments[0]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_out_shipments(self):
|
def action_view_out_shipments(self):
|
||||||
action = self.env.ref('stock.action_picking_tree_all')
|
action = self.env.ref("stock.action_picking_tree_all")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
picking_ids = []
|
picking_ids = []
|
||||||
for line in self.rma_line_ids:
|
for line in self.rma_line_ids:
|
||||||
for move in line.move_ids:
|
for move in line.move_ids:
|
||||||
if move.location_dest_id.usage in ('supplier', 'customer'):
|
if move.location_dest_id.usage in ("supplier", "customer"):
|
||||||
if not line.customer_to_supplier:
|
if not line.customer_to_supplier:
|
||||||
picking_ids.append(move.picking_id.id)
|
picking_ids.append(move.picking_id.id)
|
||||||
if picking_ids:
|
if picking_ids:
|
||||||
shipments = list(set(picking_ids))
|
shipments = list(set(picking_ids))
|
||||||
# choose the view_mode accordingly
|
# choose the view_mode accordingly
|
||||||
if len(shipments) != 1:
|
if len(shipments) != 1:
|
||||||
result['domain'] = [('id', 'in', shipments)]
|
result["domain"] = [("id", "in", shipments)]
|
||||||
else:
|
else:
|
||||||
res = self.env.ref('stock.view_picking_form', False)
|
res = self.env.ref("stock.view_picking_form", False)
|
||||||
result['views'] = [(res and res.id or False, 'form')]
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
result['res_id'] = shipments[0]
|
result["res_id"] = shipments[0]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -228,56 +237,65 @@ class RmaOrder(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_lines(self):
|
def action_view_lines(self):
|
||||||
if self.type == 'customer':
|
if self.type == "customer":
|
||||||
action = self.env.ref('rma.action_rma_customer_lines')
|
action = self.env.ref("rma.action_rma_customer_lines")
|
||||||
res = self.env.ref('rma.view_rma_line_form', False)
|
res = self.env.ref("rma.view_rma_line_form", False)
|
||||||
else:
|
else:
|
||||||
action = self.env.ref('rma.action_rma_supplier_lines')
|
action = self.env.ref("rma.action_rma_supplier_lines")
|
||||||
res = self.env.ref('rma.view_rma_line_supplier_form', False)
|
res = self.env.ref("rma.view_rma_line_supplier_form", False)
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
lines = self._get_valid_lines()
|
lines = self._get_valid_lines()
|
||||||
# choose the view_mode accordingly
|
# choose the view_mode accordingly
|
||||||
if len(lines.ids) != 1:
|
if len(lines.ids) != 1:
|
||||||
result['domain'] = [('id', 'in', lines.ids)]
|
result["domain"] = [("id", "in", lines.ids)]
|
||||||
else:
|
else:
|
||||||
result['views'] = [(res and res.id or False, 'form')]
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
result['res_id'] = lines.id
|
result["res_id"] = lines.id
|
||||||
result['context'] = {}
|
result["context"] = {}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_view_supplier_lines(self):
|
def action_view_supplier_lines(self):
|
||||||
action = self.env.ref('rma.action_rma_supplier_lines')
|
action = self.env.ref("rma.action_rma_supplier_lines")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
lines = self.rma_line_ids
|
lines = self.rma_line_ids
|
||||||
for line_id in lines:
|
for line_id in lines:
|
||||||
related_lines = [line.id for line in line_id.supplier_rma_line_ids]
|
related_lines = [line.id for line in line_id.supplier_rma_line_ids]
|
||||||
# choose the view_mode accordingly
|
# choose the view_mode accordingly
|
||||||
if len(related_lines) != 1:
|
if len(related_lines) != 1:
|
||||||
result['domain'] = [('id', 'in', related_lines)]
|
result["domain"] = [("id", "in", related_lines)]
|
||||||
else:
|
else:
|
||||||
res = self.env.ref('rma.view_rma_line_supplier_form', False)
|
res = self.env.ref("rma.view_rma_line_supplier_form", False)
|
||||||
result['views'] = [(res and res.id or False, 'form')]
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
result['res_id'] = related_lines[0]
|
result["res_id"] = related_lines[0]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.onchange('in_warehouse_id')
|
@api.onchange("in_warehouse_id")
|
||||||
def _onchange_in_warehouse_id(self):
|
def _onchange_in_warehouse_id(self):
|
||||||
if self.in_warehouse_id and self.rma_line_ids:
|
if self.in_warehouse_id and self.rma_line_ids:
|
||||||
self.rma_line_ids.write(
|
self.rma_line_ids.write(
|
||||||
{'in_warehouse_id': self.in_warehouse_id.id,
|
{
|
||||||
'location_id': self.in_warehouse_id.lot_rma_id.id})
|
"in_warehouse_id": self.in_warehouse_id.id,
|
||||||
|
"location_id": self.in_warehouse_id.lot_rma_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@api.onchange('customer_to_supplier', 'supplier_address_id')
|
@api.onchange("customer_to_supplier", "supplier_address_id")
|
||||||
def _onchange_customer_to_supplier(self):
|
def _onchange_customer_to_supplier(self):
|
||||||
if self.type == 'customer' and self.rma_line_ids:
|
if self.type == "customer" and self.rma_line_ids:
|
||||||
self.rma_line_ids.write(
|
self.rma_line_ids.write(
|
||||||
{'customer_to_supplier': self.customer_to_supplier,
|
{
|
||||||
'supplier_address_id': self.supplier_address_id.id})
|
"customer_to_supplier": self.customer_to_supplier,
|
||||||
|
"supplier_address_id": self.supplier_address_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@api.onchange('supplier_to_customer', 'customer_address_id')
|
@api.onchange("supplier_to_customer", "customer_address_id")
|
||||||
def _onchange_supplier_to_customer(self):
|
def _onchange_supplier_to_customer(self):
|
||||||
if self.type == 'supplier' and self.rma_line_ids:
|
if self.type == "supplier" and self.rma_line_ids:
|
||||||
self.rma_line_ids.write(
|
self.rma_line_ids.write(
|
||||||
{'supplier_to_customer': self.supplier_to_customer,
|
{
|
||||||
'customer_address_id': self.customer_address_id.id})
|
"supplier_to_customer": self.supplier_to_customer,
|
||||||
|
"customer_address_id": self.customer_address_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -15,8 +15,11 @@ class StockPicking(models.Model):
|
|||||||
res = super(StockPicking, self).action_assign()
|
res = super(StockPicking, self).action_assign()
|
||||||
for picking in self:
|
for picking in self:
|
||||||
for move in picking.move_lines:
|
for move in picking.move_lines:
|
||||||
if (move.rma_line_id and move.state == 'confirmed' and
|
if (
|
||||||
move.location_id.usage == 'customer'):
|
move.rma_line_id
|
||||||
|
and move.state == "confirmed"
|
||||||
|
and move.location_id.usage == "customer"
|
||||||
|
):
|
||||||
move.force_assign()
|
move.force_assign()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@@ -24,15 +27,16 @@ class StockPicking(models.Model):
|
|||||||
class StockMove(models.Model):
|
class StockMove(models.Model):
|
||||||
_inherit = "stock.move"
|
_inherit = "stock.move"
|
||||||
|
|
||||||
rma_line_id = fields.Many2one('rma.order.line', string='RMA line',
|
rma_line_id = fields.Many2one(
|
||||||
ondelete='restrict')
|
"rma.order.line", string="RMA line", ondelete="restrict"
|
||||||
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
if vals.get('group_id'):
|
if vals.get("group_id"):
|
||||||
group = self.env['procurement.group'].browse(vals['group_id'])
|
group = self.env["procurement.group"].browse(vals["group_id"])
|
||||||
if group.rma_line_id:
|
if group.rma_line_id:
|
||||||
vals['rma_line_id'] = group.rma_line_id.id
|
vals["rma_line_id"] = group.rma_line_id.id
|
||||||
return super(StockMove, self).create(vals)
|
return super(StockMove, self).create(vals)
|
||||||
|
|
||||||
def _action_assign(self):
|
def _action_assign(self):
|
||||||
|
|||||||
@@ -8,41 +8,37 @@ class StockWarehouse(models.Model):
|
|||||||
_inherit = "stock.warehouse"
|
_inherit = "stock.warehouse"
|
||||||
|
|
||||||
lot_rma_id = fields.Many2one(
|
lot_rma_id = fields.Many2one(
|
||||||
comodel_name='stock.location', string='RMA Location',
|
comodel_name="stock.location", string="RMA Location"
|
||||||
) # not readonly to have the possibility to edit location and
|
) # not readonly to have the possibility to edit location and
|
||||||
# propagate to rma rules (add a auto-update when writing this field?)
|
# propagate to rma rules (add a auto-update when writing this field?)
|
||||||
rma_cust_out_type_id = fields.Many2one(
|
rma_cust_out_type_id = fields.Many2one(
|
||||||
comodel_name='stock.picking.type', string='RMA Customer out Type',
|
comodel_name="stock.picking.type", string="RMA Customer out Type", readonly=True
|
||||||
readonly=True,
|
|
||||||
)
|
)
|
||||||
rma_sup_out_type_id = fields.Many2one(
|
rma_sup_out_type_id = fields.Many2one(
|
||||||
comodel_name='stock.picking.type', string='RMA Supplier out Type',
|
comodel_name="stock.picking.type", string="RMA Supplier out Type", readonly=True
|
||||||
readonly=True,
|
|
||||||
)
|
)
|
||||||
rma_cust_in_type_id = fields.Many2one(
|
rma_cust_in_type_id = fields.Many2one(
|
||||||
comodel_name='stock.picking.type', string='RMA Customer in Type',
|
comodel_name="stock.picking.type", string="RMA Customer in Type", readonly=True
|
||||||
readonly=True,
|
|
||||||
)
|
)
|
||||||
rma_sup_in_type_id = fields.Many2one(
|
rma_sup_in_type_id = fields.Many2one(
|
||||||
comodel_name='stock.picking.type', string='RMA Supplier in Type',
|
comodel_name="stock.picking.type", string="RMA Supplier in Type", readonly=True
|
||||||
readonly=True,
|
|
||||||
)
|
)
|
||||||
rma_in_this_wh = fields.Boolean(
|
rma_in_this_wh = fields.Boolean(
|
||||||
string='RMA in this Warehouse',
|
string="RMA in this Warehouse",
|
||||||
help="If set, it will create RMA location, picking types and routes "
|
help="If set, it will create RMA location, picking types and routes "
|
||||||
"for this warehouse.",
|
"for this warehouse.",
|
||||||
)
|
)
|
||||||
rma_customer_in_pull_id = fields.Many2one(
|
rma_customer_in_pull_id = fields.Many2one(
|
||||||
comodel_name='stock.rule', string="RMA Customer In Rule",
|
comodel_name="stock.rule", string="RMA Customer In Rule"
|
||||||
)
|
)
|
||||||
rma_customer_out_pull_id = fields.Many2one(
|
rma_customer_out_pull_id = fields.Many2one(
|
||||||
comodel_name='stock.rule', string="RMA Customer Out Rule",
|
comodel_name="stock.rule", string="RMA Customer Out Rule"
|
||||||
)
|
)
|
||||||
rma_supplier_in_pull_id = fields.Many2one(
|
rma_supplier_in_pull_id = fields.Many2one(
|
||||||
comodel_name='stock.rule', string="RMA Supplier In Rule",
|
comodel_name="stock.rule", string="RMA Supplier In Rule"
|
||||||
)
|
)
|
||||||
rma_supplier_out_pull_id = fields.Many2one(
|
rma_supplier_out_pull_id = fields.Many2one(
|
||||||
comodel_name='stock.rule', string="RMA Supplier Out Rule",
|
comodel_name="stock.rule", string="RMA Supplier Out Rule"
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -51,7 +47,8 @@ class StockWarehouse(models.Model):
|
|||||||
self.rma_cust_out_type_id,
|
self.rma_cust_out_type_id,
|
||||||
self.rma_sup_out_type_id,
|
self.rma_sup_out_type_id,
|
||||||
self.rma_cust_in_type_id,
|
self.rma_cust_in_type_id,
|
||||||
self.rma_sup_in_type_id]
|
self.rma_sup_in_type_id,
|
||||||
|
]
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _rma_types_available(self):
|
def _rma_types_available(self):
|
||||||
@@ -64,17 +61,19 @@ class StockWarehouse(models.Model):
|
|||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
if 'rma_in_this_wh' in vals:
|
if "rma_in_this_wh" in vals:
|
||||||
if vals.get("rma_in_this_wh"):
|
if vals.get("rma_in_this_wh"):
|
||||||
for wh in self:
|
for wh in self:
|
||||||
# RMA location:
|
# RMA location:
|
||||||
if not wh.lot_rma_id:
|
if not wh.lot_rma_id:
|
||||||
wh.lot_rma_id = self.env['stock.location'].create({
|
wh.lot_rma_id = self.env["stock.location"].create(
|
||||||
'name': 'RMA',
|
{
|
||||||
'usage': 'internal',
|
"name": "RMA",
|
||||||
'location_id': wh.lot_stock_id.id,
|
"usage": "internal",
|
||||||
'company_id': wh.company_id.id,
|
"location_id": wh.lot_stock_id.id,
|
||||||
})
|
"company_id": wh.company_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
# RMA types
|
# RMA types
|
||||||
if not wh._rma_types_available():
|
if not wh._rma_types_available():
|
||||||
wh._create_rma_picking_types()
|
wh._create_rma_picking_types()
|
||||||
@@ -90,83 +89,89 @@ class StockWarehouse(models.Model):
|
|||||||
if type:
|
if type:
|
||||||
type.active = False
|
type.active = False
|
||||||
# Unlink rules:
|
# Unlink rules:
|
||||||
self.mapped('rma_customer_in_pull_id').unlink()
|
self.mapped("rma_customer_in_pull_id").unlink()
|
||||||
self.mapped('rma_customer_out_pull_id').unlink()
|
self.mapped("rma_customer_out_pull_id").unlink()
|
||||||
self.mapped('rma_supplier_in_pull_id').unlink()
|
self.mapped("rma_supplier_in_pull_id").unlink()
|
||||||
self.mapped('rma_supplier_out_pull_id').unlink()
|
self.mapped("rma_supplier_out_pull_id").unlink()
|
||||||
return super(StockWarehouse, self).write(vals)
|
return super(StockWarehouse, self).write(vals)
|
||||||
|
|
||||||
def _create_rma_picking_types(self):
|
def _create_rma_picking_types(self):
|
||||||
picking_type_obj = self.env['stock.picking.type']
|
picking_type_obj = self.env["stock.picking.type"]
|
||||||
customer_loc, supplier_loc = self._get_partner_locations()
|
customer_loc, supplier_loc = self._get_partner_locations()
|
||||||
for wh in self:
|
for wh in self:
|
||||||
other_pick_type = picking_type_obj.search(
|
other_pick_type = picking_type_obj.search(
|
||||||
[('warehouse_id', '=', wh.id)], order='sequence desc',
|
[("warehouse_id", "=", wh.id)], order="sequence desc", limit=1
|
||||||
limit=1)
|
)
|
||||||
color = other_pick_type.color if other_pick_type else 0
|
color = other_pick_type.color if other_pick_type else 0
|
||||||
max_sequence = other_pick_type and other_pick_type.sequence or 0
|
max_sequence = other_pick_type and other_pick_type.sequence or 0
|
||||||
# create rma_cust_out_type_id:
|
# create rma_cust_out_type_id:
|
||||||
rma_cust_out_type_id = picking_type_obj.create({
|
rma_cust_out_type_id = picking_type_obj.create(
|
||||||
'name': _('Customer RMA Deliveries'),
|
{
|
||||||
'warehouse_id': wh.id,
|
"name": _("Customer RMA Deliveries"),
|
||||||
'code': 'outgoing',
|
"warehouse_id": wh.id,
|
||||||
'use_create_lots': True,
|
"code": "outgoing",
|
||||||
'use_existing_lots': False,
|
"use_create_lots": True,
|
||||||
'sequence_id': self.env.ref(
|
"use_existing_lots": False,
|
||||||
'rma.seq_picking_type_rma_cust_out').id,
|
"sequence_id": self.env.ref("rma.seq_picking_type_rma_cust_out").id,
|
||||||
'default_location_src_id': wh.lot_rma_id.id,
|
"default_location_src_id": wh.lot_rma_id.id,
|
||||||
'default_location_dest_id': customer_loc.id,
|
"default_location_dest_id": customer_loc.id,
|
||||||
'sequence': max_sequence,
|
"sequence": max_sequence,
|
||||||
'color': color,
|
"color": color,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
# create rma_sup_out_type_id:
|
# create rma_sup_out_type_id:
|
||||||
rma_sup_out_type_id = picking_type_obj.create({
|
rma_sup_out_type_id = picking_type_obj.create(
|
||||||
'name': _('Supplier RMA Deliveries'),
|
{
|
||||||
'warehouse_id': wh.id,
|
"name": _("Supplier RMA Deliveries"),
|
||||||
'code': 'outgoing',
|
"warehouse_id": wh.id,
|
||||||
'use_create_lots': True,
|
"code": "outgoing",
|
||||||
'use_existing_lots': False,
|
"use_create_lots": True,
|
||||||
'sequence_id': self.env.ref(
|
"use_existing_lots": False,
|
||||||
'rma.seq_picking_type_rma_sup_out').id,
|
"sequence_id": self.env.ref("rma.seq_picking_type_rma_sup_out").id,
|
||||||
'default_location_src_id': wh.lot_rma_id.id,
|
"default_location_src_id": wh.lot_rma_id.id,
|
||||||
'default_location_dest_id': supplier_loc.id,
|
"default_location_dest_id": supplier_loc.id,
|
||||||
'sequence': max_sequence,
|
"sequence": max_sequence,
|
||||||
'color': color,
|
"color": color,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
# create rma_cust_in_type_id:
|
# create rma_cust_in_type_id:
|
||||||
rma_cust_in_type_id = picking_type_obj.create({
|
rma_cust_in_type_id = picking_type_obj.create(
|
||||||
'name': _('Customer RMA Receipts'),
|
{
|
||||||
'warehouse_id': wh.id,
|
"name": _("Customer RMA Receipts"),
|
||||||
'code': 'incoming',
|
"warehouse_id": wh.id,
|
||||||
'use_create_lots': True,
|
"code": "incoming",
|
||||||
'use_existing_lots': False,
|
"use_create_lots": True,
|
||||||
'sequence_id': self.env.ref(
|
"use_existing_lots": False,
|
||||||
'rma.seq_picking_type_rma_cust_in').id,
|
"sequence_id": self.env.ref("rma.seq_picking_type_rma_cust_in").id,
|
||||||
'default_location_src_id': customer_loc.id,
|
"default_location_src_id": customer_loc.id,
|
||||||
'default_location_dest_id': wh.lot_rma_id.id,
|
"default_location_dest_id": wh.lot_rma_id.id,
|
||||||
'sequence': max_sequence,
|
"sequence": max_sequence,
|
||||||
'color': color,
|
"color": color,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
# create rma_sup_in_type_id:
|
# create rma_sup_in_type_id:
|
||||||
rma_sup_in_type_id = picking_type_obj.create({
|
rma_sup_in_type_id = picking_type_obj.create(
|
||||||
'name': _('Supplier RMA Receipts'),
|
{
|
||||||
'warehouse_id': wh.id,
|
"name": _("Supplier RMA Receipts"),
|
||||||
'code': 'incoming',
|
"warehouse_id": wh.id,
|
||||||
'use_create_lots': True,
|
"code": "incoming",
|
||||||
'use_existing_lots': False,
|
"use_create_lots": True,
|
||||||
'sequence_id': self.env.ref(
|
"use_existing_lots": False,
|
||||||
'rma.seq_picking_type_rma_sup_in').id,
|
"sequence_id": self.env.ref("rma.seq_picking_type_rma_sup_in").id,
|
||||||
'default_location_src_id': supplier_loc.id,
|
"default_location_src_id": supplier_loc.id,
|
||||||
'default_location_dest_id': wh.lot_rma_id.id,
|
"default_location_dest_id": wh.lot_rma_id.id,
|
||||||
'sequence': max_sequence,
|
"sequence": max_sequence,
|
||||||
'color': color,
|
"color": color,
|
||||||
})
|
}
|
||||||
wh.write({
|
)
|
||||||
'rma_cust_out_type_id': rma_cust_out_type_id.id,
|
wh.write(
|
||||||
'rma_sup_out_type_id': rma_sup_out_type_id.id,
|
{
|
||||||
'rma_cust_in_type_id': rma_cust_in_type_id.id,
|
"rma_cust_out_type_id": rma_cust_out_type_id.id,
|
||||||
'rma_sup_in_type_id': rma_sup_in_type_id.id,
|
"rma_sup_out_type_id": rma_sup_out_type_id.id,
|
||||||
})
|
"rma_cust_in_type_id": rma_cust_in_type_id.id,
|
||||||
|
"rma_sup_in_type_id": rma_sup_in_type_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -174,93 +179,87 @@ class StockWarehouse(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
rma_rules = dict()
|
rma_rules = dict()
|
||||||
customer_loc, supplier_loc = self._get_partner_locations()
|
customer_loc, supplier_loc = self._get_partner_locations()
|
||||||
rma_rules['rma_customer_in'] = {
|
rma_rules["rma_customer_in"] = {
|
||||||
'name': self._format_rulename(self,
|
"name": self._format_rulename(self, customer_loc, self.lot_rma_id.name),
|
||||||
customer_loc,
|
"action": "pull",
|
||||||
self.lot_rma_id.name),
|
"warehouse_id": self.id,
|
||||||
'action': 'pull',
|
"company_id": self.company_id.id,
|
||||||
'warehouse_id': self.id,
|
"location_src_id": customer_loc.id,
|
||||||
'company_id': self.company_id.id,
|
"location_id": self.lot_rma_id.id,
|
||||||
'location_src_id': customer_loc.id,
|
"procure_method": "make_to_stock",
|
||||||
'location_id': self.lot_rma_id.id,
|
"route_id": self.env.ref("rma.route_rma_customer").id,
|
||||||
'procure_method': 'make_to_stock',
|
"picking_type_id": self.rma_cust_in_type_id.id,
|
||||||
'route_id': self.env.ref('rma.route_rma_customer').id,
|
"active": True,
|
||||||
'picking_type_id': self.rma_cust_in_type_id.id,
|
|
||||||
'active': True,
|
|
||||||
}
|
}
|
||||||
rma_rules['rma_customer_out'] = {
|
rma_rules["rma_customer_out"] = {
|
||||||
'name': self._format_rulename(self,
|
"name": self._format_rulename(self, self.lot_rma_id, customer_loc.name),
|
||||||
self.lot_rma_id,
|
"action": "pull",
|
||||||
customer_loc.name),
|
"warehouse_id": self.id,
|
||||||
'action': 'pull',
|
"company_id": self.company_id.id,
|
||||||
'warehouse_id': self.id,
|
"location_src_id": self.lot_rma_id.id,
|
||||||
'company_id': self.company_id.id,
|
"location_id": customer_loc.id,
|
||||||
'location_src_id': self.lot_rma_id.id,
|
"procure_method": "make_to_stock",
|
||||||
'location_id': customer_loc.id,
|
"route_id": self.env.ref("rma.route_rma_customer").id,
|
||||||
'procure_method': 'make_to_stock',
|
"picking_type_id": self.rma_cust_out_type_id.id,
|
||||||
'route_id': self.env.ref('rma.route_rma_customer').id,
|
"active": True,
|
||||||
'picking_type_id': self.rma_cust_out_type_id.id,
|
|
||||||
'active': True,
|
|
||||||
}
|
}
|
||||||
rma_rules['rma_supplier_in'] = {
|
rma_rules["rma_supplier_in"] = {
|
||||||
'name': self._format_rulename(self,
|
"name": self._format_rulename(self, supplier_loc, self.lot_rma_id.name),
|
||||||
supplier_loc,
|
"action": "pull",
|
||||||
self.lot_rma_id.name),
|
"warehouse_id": self.id,
|
||||||
'action': 'pull',
|
"company_id": self.company_id.id,
|
||||||
'warehouse_id': self.id,
|
"location_src_id": supplier_loc.id,
|
||||||
'company_id': self.company_id.id,
|
"location_id": self.lot_rma_id.id,
|
||||||
'location_src_id': supplier_loc.id,
|
"procure_method": "make_to_stock",
|
||||||
'location_id': self.lot_rma_id.id,
|
"route_id": self.env.ref("rma.route_rma_supplier").id,
|
||||||
'procure_method': 'make_to_stock',
|
"picking_type_id": self.rma_sup_in_type_id.id,
|
||||||
'route_id': self.env.ref('rma.route_rma_supplier').id,
|
"active": True,
|
||||||
'picking_type_id': self.rma_sup_in_type_id.id,
|
|
||||||
'active': True,
|
|
||||||
}
|
}
|
||||||
rma_rules['rma_supplier_out'] = {
|
rma_rules["rma_supplier_out"] = {
|
||||||
'name': self._format_rulename(self,
|
"name": self._format_rulename(self, self.lot_rma_id, supplier_loc.name),
|
||||||
self.lot_rma_id,
|
"action": "pull",
|
||||||
supplier_loc.name),
|
"warehouse_id": self.id,
|
||||||
'action': 'pull',
|
"company_id": self.company_id.id,
|
||||||
'warehouse_id': self.id,
|
"location_src_id": self.lot_rma_id.id,
|
||||||
'company_id': self.company_id.id,
|
"location_id": supplier_loc.id,
|
||||||
'location_src_id': self.lot_rma_id.id,
|
"procure_method": "make_to_stock",
|
||||||
'location_id': supplier_loc.id,
|
"route_id": self.env.ref("rma.route_rma_supplier").id,
|
||||||
'procure_method': 'make_to_stock',
|
"picking_type_id": self.rma_sup_out_type_id.id,
|
||||||
'route_id': self.env.ref('rma.route_rma_supplier').id,
|
"active": True,
|
||||||
'picking_type_id': self.rma_sup_out_type_id.id,
|
|
||||||
'active': True,
|
|
||||||
}
|
}
|
||||||
return rma_rules
|
return rma_rules
|
||||||
|
|
||||||
def _create_or_update_rma_pull(self):
|
def _create_or_update_rma_pull(self):
|
||||||
rule_obj = self.env['stock.rule']
|
rule_obj = self.env["stock.rule"]
|
||||||
for wh in self:
|
for wh in self:
|
||||||
rules_dict = wh.get_rma_rules_dict()
|
rules_dict = wh.get_rma_rules_dict()
|
||||||
if wh.rma_customer_in_pull_id:
|
if wh.rma_customer_in_pull_id:
|
||||||
wh.rma_customer_in_pull_id.write(rules_dict['rma_customer_in'])
|
wh.rma_customer_in_pull_id.write(rules_dict["rma_customer_in"])
|
||||||
else:
|
else:
|
||||||
wh.rma_customer_in_pull_id = rule_obj.create(
|
wh.rma_customer_in_pull_id = rule_obj.create(
|
||||||
rules_dict['rma_customer_in'])
|
rules_dict["rma_customer_in"]
|
||||||
|
)
|
||||||
|
|
||||||
if wh.rma_customer_out_pull_id:
|
if wh.rma_customer_out_pull_id:
|
||||||
wh.rma_customer_out_pull_id.write(
|
wh.rma_customer_out_pull_id.write(rules_dict["rma_customer_out"])
|
||||||
rules_dict['rma_customer_out'])
|
|
||||||
else:
|
else:
|
||||||
wh.rma_customer_out_pull_id = rule_obj.create(
|
wh.rma_customer_out_pull_id = rule_obj.create(
|
||||||
rules_dict['rma_customer_out'])
|
rules_dict["rma_customer_out"]
|
||||||
|
)
|
||||||
|
|
||||||
if wh.rma_supplier_in_pull_id:
|
if wh.rma_supplier_in_pull_id:
|
||||||
wh.rma_supplier_in_pull_id.write(rules_dict['rma_supplier_in'])
|
wh.rma_supplier_in_pull_id.write(rules_dict["rma_supplier_in"])
|
||||||
else:
|
else:
|
||||||
wh.rma_supplier_in_pull_id = rule_obj.create(
|
wh.rma_supplier_in_pull_id = rule_obj.create(
|
||||||
rules_dict['rma_supplier_in'])
|
rules_dict["rma_supplier_in"]
|
||||||
|
)
|
||||||
|
|
||||||
if wh.rma_supplier_out_pull_id:
|
if wh.rma_supplier_out_pull_id:
|
||||||
wh.rma_supplier_out_pull_id.write(
|
wh.rma_supplier_out_pull_id.write(rules_dict["rma_supplier_out"])
|
||||||
rules_dict['rma_supplier_out'])
|
|
||||||
else:
|
else:
|
||||||
wh.rma_supplier_out_pull_id = rule_obj.create(
|
wh.rma_supplier_out_pull_id = rule_obj.create(
|
||||||
rules_dict['rma_supplier_out'])
|
rules_dict["rma_supplier_out"]
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# © 2017 Eficent Business and IT Consulting Services S.L.
|
# © 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.tests import common
|
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
class TestRma(common.SavepointCase):
|
class TestRma(common.SavepointCase):
|
||||||
@@ -12,153 +12,181 @@ class TestRma(common.SavepointCase):
|
|||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TestRma, cls).setUpClass()
|
super(TestRma, cls).setUpClass()
|
||||||
|
|
||||||
cls.rma_make_picking = cls.env['rma_make_picking.wizard']
|
cls.rma_make_picking = cls.env["rma_make_picking.wizard"]
|
||||||
cls.make_supplier_rma = cls.env["rma.order.line.make.supplier.rma"]
|
cls.make_supplier_rma = cls.env["rma.order.line.make.supplier.rma"]
|
||||||
cls.rma_add_stock_move = cls.env['rma_add_stock_move']
|
cls.rma_add_stock_move = cls.env["rma_add_stock_move"]
|
||||||
cls.stockpicking = cls.env['stock.picking']
|
cls.stockpicking = cls.env["stock.picking"]
|
||||||
cls.rma = cls.env['rma.order']
|
cls.rma = cls.env["rma.order"]
|
||||||
cls.rma_line = cls.env['rma.order.line']
|
cls.rma_line = cls.env["rma.order.line"]
|
||||||
cls.rma_op = cls.env['rma.operation']
|
cls.rma_op = cls.env["rma.operation"]
|
||||||
cls.rma_cust_replace_op_id = cls.env.ref(
|
cls.rma_cust_replace_op_id = cls.env.ref("rma.rma_operation_customer_replace")
|
||||||
'rma.rma_operation_customer_replace')
|
cls.rma_sup_replace_op_id = cls.env.ref("rma.rma_operation_supplier_replace")
|
||||||
cls.rma_sup_replace_op_id = cls.env.ref(
|
cls.rma_ds_replace_op_id = cls.env.ref("rma.rma_operation_ds_replace")
|
||||||
'rma.rma_operation_supplier_replace')
|
cls.product_id = cls.env.ref("product.product_product_4")
|
||||||
cls.rma_ds_replace_op_id = cls.env.ref(
|
cls.product_1 = cls.env.ref("product.product_product_25")
|
||||||
'rma.rma_operation_ds_replace')
|
cls.product_2 = cls.env.ref("product.product_product_22")
|
||||||
cls.product_id = cls.env.ref('product.product_product_4')
|
cls.product_3 = cls.env.ref("product.product_product_20")
|
||||||
cls.product_1 = cls.env.ref('product.product_product_25')
|
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
|
||||||
cls.product_2 = cls.env.ref('product.product_product_22')
|
|
||||||
cls.product_3 = cls.env.ref('product.product_product_20')
|
|
||||||
cls.uom_unit = cls.env.ref('uom.product_uom_unit')
|
|
||||||
# assign an operation
|
# assign an operation
|
||||||
cls.product_1.write(
|
cls.product_1.write(
|
||||||
{'rma_customer_operation_id': cls.rma_cust_replace_op_id.id,
|
{
|
||||||
'rma_supplier_operation_id': cls.rma_sup_replace_op_id.id})
|
"rma_customer_operation_id": cls.rma_cust_replace_op_id.id,
|
||||||
|
"rma_supplier_operation_id": cls.rma_sup_replace_op_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
cls.product_2.write(
|
cls.product_2.write(
|
||||||
{'rma_customer_operation_id': cls.rma_cust_replace_op_id.id,
|
{
|
||||||
'rma_supplier_operation_id': cls.rma_sup_replace_op_id.id})
|
"rma_customer_operation_id": cls.rma_cust_replace_op_id.id,
|
||||||
|
"rma_supplier_operation_id": cls.rma_sup_replace_op_id.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
cls.product_3.write(
|
cls.product_3.write(
|
||||||
{'rma_customer_operation_id': cls.rma_cust_replace_op_id.id,
|
{
|
||||||
'rma_supplier_operation_id': cls.rma_sup_replace_op_id.id})
|
"rma_customer_operation_id": cls.rma_cust_replace_op_id.id,
|
||||||
cls.partner_id = cls.env.ref('base.res_partner_2')
|
"rma_supplier_operation_id": cls.rma_sup_replace_op_id.id,
|
||||||
cls.stock_location = cls.env.ref('stock.stock_location_stock')
|
}
|
||||||
wh = cls.env.ref('stock.warehouse0')
|
)
|
||||||
|
cls.partner_id = cls.env.ref("base.res_partner_2")
|
||||||
|
cls.stock_location = cls.env.ref("stock.stock_location_stock")
|
||||||
|
wh = cls.env.ref("stock.warehouse0")
|
||||||
cls.stock_rma_location = wh.lot_rma_id
|
cls.stock_rma_location = wh.lot_rma_id
|
||||||
cls.customer_location = cls.env.ref(
|
cls.customer_location = cls.env.ref("stock.stock_location_customers")
|
||||||
'stock.stock_location_customers')
|
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers")
|
||||||
cls.supplier_location = cls.env.ref(
|
cls.product_uom_id = cls.env.ref("uom.product_uom_unit")
|
||||||
'stock.stock_location_suppliers')
|
|
||||||
cls.product_uom_id = cls.env.ref('uom.product_uom_unit')
|
|
||||||
# Customer RMA:
|
# Customer RMA:
|
||||||
products2move = [(cls.product_1, 3), (cls.product_2, 5),
|
products2move = [(cls.product_1, 3), (cls.product_2, 5), (cls.product_3, 2)]
|
||||||
(cls.product_3, 2)]
|
|
||||||
cls.rma_customer_id = cls._create_rma_from_move(
|
cls.rma_customer_id = cls._create_rma_from_move(
|
||||||
products2move, 'customer', cls.env.ref('base.res_partner_2'),
|
products2move, "customer", cls.env.ref("base.res_partner_2"), dropship=False
|
||||||
dropship=False)
|
)
|
||||||
# Dropship:
|
# Dropship:
|
||||||
cls.rma_droship_id = cls._create_rma_from_move(
|
cls.rma_droship_id = cls._create_rma_from_move(
|
||||||
products2move, 'customer', cls.env.ref('base.res_partner_2'),
|
products2move,
|
||||||
|
"customer",
|
||||||
|
cls.env.ref("base.res_partner_2"),
|
||||||
dropship=True,
|
dropship=True,
|
||||||
supplier_address_id=cls.env.ref('base.res_partner_3'))
|
supplier_address_id=cls.env.ref("base.res_partner_3"),
|
||||||
|
)
|
||||||
# Supplier RMA:
|
# Supplier RMA:
|
||||||
cls.rma_supplier_id = cls._create_rma_from_move(
|
cls.rma_supplier_id = cls._create_rma_from_move(
|
||||||
products2move, 'supplier', cls.env.ref('base.res_partner_2'),
|
products2move, "supplier", cls.env.ref("base.res_partner_2"), dropship=False
|
||||||
dropship=False)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _create_picking(cls, partner):
|
def _create_picking(cls, partner):
|
||||||
return cls.stockpicking.create({
|
return cls.stockpicking.create(
|
||||||
'partner_id': partner.id,
|
{
|
||||||
'picking_type_id': cls.env.ref('stock.picking_type_in').id,
|
"partner_id": partner.id,
|
||||||
'location_id': cls.stock_location.id,
|
"picking_type_id": cls.env.ref("stock.picking_type_in").id,
|
||||||
'location_dest_id': cls.supplier_location.id
|
"location_id": cls.stock_location.id,
|
||||||
})
|
"location_dest_id": cls.supplier_location.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _create_rma_from_move(cls, products2move, type, partner, dropship,
|
def _create_rma_from_move(
|
||||||
supplier_address_id=None):
|
cls, products2move, type, partner, dropship, supplier_address_id=None
|
||||||
|
):
|
||||||
picking_in = cls._create_picking(partner)
|
picking_in = cls._create_picking(partner)
|
||||||
|
|
||||||
moves = []
|
moves = []
|
||||||
if type == 'customer':
|
if type == "customer":
|
||||||
for item in products2move:
|
for item in products2move:
|
||||||
move_values = cls._prepare_move(
|
move_values = cls._prepare_move(
|
||||||
item[0], item[1], cls.stock_location,
|
item[0],
|
||||||
cls.customer_location, picking_in)
|
item[1],
|
||||||
moves.append(cls.env['stock.move'].create(move_values))
|
cls.stock_location,
|
||||||
|
cls.customer_location,
|
||||||
|
picking_in,
|
||||||
|
)
|
||||||
|
moves.append(cls.env["stock.move"].create(move_values))
|
||||||
else:
|
else:
|
||||||
for item in products2move:
|
for item in products2move:
|
||||||
move_values = cls._prepare_move(
|
move_values = cls._prepare_move(
|
||||||
item[0], item[1], cls.supplier_location,
|
item[0],
|
||||||
cls.stock_rma_location, picking_in)
|
item[1],
|
||||||
moves.append(cls.env['stock.move'].create(move_values))
|
cls.supplier_location,
|
||||||
|
cls.stock_rma_location,
|
||||||
|
picking_in,
|
||||||
|
)
|
||||||
|
moves.append(cls.env["stock.move"].create(move_values))
|
||||||
# Create the RMA from the stock_move
|
# Create the RMA from the stock_move
|
||||||
rma_id = cls.rma.create(
|
rma_id = cls.rma.create(
|
||||||
{
|
{
|
||||||
'reference': '0001',
|
"reference": "0001",
|
||||||
'type': type,
|
"type": type,
|
||||||
'partner_id': partner.id,
|
"partner_id": partner.id,
|
||||||
'company_id': cls.env.ref('base.main_company').id
|
"company_id": cls.env.ref("base.main_company").id,
|
||||||
})
|
|
||||||
for move in moves:
|
|
||||||
if type == 'customer':
|
|
||||||
wizard = cls.rma_add_stock_move.new(
|
|
||||||
{'stock_move_id': move.id, 'customer': True,
|
|
||||||
'active_ids': rma_id.id,
|
|
||||||
'rma_id': rma_id.id,
|
|
||||||
'partner_id': move.partner_id.id,
|
|
||||||
'active_model': 'rma.order',
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard.with_context({
|
for move in moves:
|
||||||
'stock_move_id': move.id, 'customer': True,
|
if type == "customer":
|
||||||
'active_ids': rma_id.id,
|
wizard = cls.rma_add_stock_move.new(
|
||||||
'partner_id': move.partner_id.id,
|
{
|
||||||
'active_model': 'rma.order',
|
"stock_move_id": move.id,
|
||||||
}).default_get([str(move.id),
|
"customer": True,
|
||||||
str(cls.partner_id.id)])
|
"active_ids": rma_id.id,
|
||||||
data = wizard.with_context(customer=1).\
|
"rma_id": rma_id.id,
|
||||||
_prepare_rma_line_from_stock_move(move)
|
"partner_id": move.partner_id.id,
|
||||||
|
"active_model": "rma.order",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
wizard.with_context(
|
||||||
|
{
|
||||||
|
"stock_move_id": move.id,
|
||||||
|
"customer": True,
|
||||||
|
"active_ids": rma_id.id,
|
||||||
|
"partner_id": move.partner_id.id,
|
||||||
|
"active_model": "rma.order",
|
||||||
|
}
|
||||||
|
).default_get([str(move.id), str(cls.partner_id.id)])
|
||||||
|
data = wizard.with_context(
|
||||||
|
customer=1
|
||||||
|
)._prepare_rma_line_from_stock_move(move)
|
||||||
wizard.add_lines()
|
wizard.add_lines()
|
||||||
|
|
||||||
if move.product_id.rma_customer_operation_id:
|
if move.product_id.rma_customer_operation_id:
|
||||||
move.product_id.rma_customer_operation_id.in_route_id = \
|
move.product_id.rma_customer_operation_id.in_route_id = False
|
||||||
False
|
|
||||||
move.product_id.categ_id.rma_customer_operation_id = False
|
move.product_id.categ_id.rma_customer_operation_id = False
|
||||||
move.product_id.rma_customer_operation_id = False
|
move.product_id.rma_customer_operation_id = False
|
||||||
wizard._prepare_rma_line_from_stock_move(move)
|
wizard._prepare_rma_line_from_stock_move(move)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
wizard = cls.rma_add_stock_move.new(
|
wizard = cls.rma_add_stock_move.new(
|
||||||
{'stock_move_id': move.id, 'supplier': True,
|
{
|
||||||
'active_ids': rma_id.id,
|
"stock_move_id": move.id,
|
||||||
'rma_id': rma_id.id,
|
"supplier": True,
|
||||||
'partner_id': move.partner_id.id,
|
"active_ids": rma_id.id,
|
||||||
'active_model': 'rma.order',
|
"rma_id": rma_id.id,
|
||||||
|
"partner_id": move.partner_id.id,
|
||||||
|
"active_model": "rma.order",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
wizard.with_context({
|
wizard.with_context(
|
||||||
'stock_move_id': move.id, 'supplier': True,
|
{
|
||||||
'active_ids': rma_id.id,
|
"stock_move_id": move.id,
|
||||||
'partner_id': move.partner_id.id,
|
"supplier": True,
|
||||||
'active_model': 'rma.order',
|
"active_ids": rma_id.id,
|
||||||
}).default_get([str(move.id),
|
"partner_id": move.partner_id.id,
|
||||||
str(cls.partner_id.id)])
|
"active_model": "rma.order",
|
||||||
data = wizard.with_context(customer=1).\
|
}
|
||||||
_prepare_rma_line_from_stock_move(move)
|
).default_get([str(move.id), str(cls.partner_id.id)])
|
||||||
|
data = wizard.with_context(
|
||||||
|
customer=1
|
||||||
|
)._prepare_rma_line_from_stock_move(move)
|
||||||
wizard.add_lines()
|
wizard.add_lines()
|
||||||
|
|
||||||
if move.product_id.rma_customer_operation_id:
|
if move.product_id.rma_customer_operation_id:
|
||||||
move.product_id.rma_customer_operation_id.in_route_id = \
|
move.product_id.rma_customer_operation_id.in_route_id = False
|
||||||
False
|
|
||||||
move.product_id.categ_id.rma_supplier_operation_id = False
|
move.product_id.categ_id.rma_supplier_operation_id = False
|
||||||
move.product_id.rma_supplier_operation_id = False
|
move.product_id.rma_supplier_operation_id = False
|
||||||
wizard._prepare_rma_line_from_stock_move(move)
|
wizard._prepare_rma_line_from_stock_move(move)
|
||||||
|
|
||||||
if dropship:
|
if dropship:
|
||||||
data.update(customer_to_supplier=dropship,
|
data.update(
|
||||||
|
customer_to_supplier=dropship,
|
||||||
operation_id=cls.rma_ds_replace_op_id.id,
|
operation_id=cls.rma_ds_replace_op_id.id,
|
||||||
supplier_address_id=supplier_address_id.id)
|
supplier_address_id=supplier_address_id.id,
|
||||||
|
)
|
||||||
cls.line = cls.rma_line.create(data)
|
cls.line = cls.rma_line.create(data)
|
||||||
cls.line.action_rma_to_approve()
|
cls.line.action_rma_to_approve()
|
||||||
cls.line.action_rma_approve()
|
cls.line.action_rma_approve()
|
||||||
@@ -178,68 +206,71 @@ class TestRma(common.SavepointCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _prepare_move(cls, product, qty, src, dest, picking_in):
|
def _prepare_move(cls, product, qty, src, dest, picking_in):
|
||||||
res = {
|
res = {
|
||||||
'partner_id': cls.partner_id.id,
|
"partner_id": cls.partner_id.id,
|
||||||
'product_id': product.id,
|
"product_id": product.id,
|
||||||
'name': product.partner_ref,
|
"name": product.partner_ref,
|
||||||
'state': 'confirmed',
|
"state": "confirmed",
|
||||||
'product_uom': cls.product_uom_id.id or product.uom_id.id,
|
"product_uom": cls.product_uom_id.id or product.uom_id.id,
|
||||||
'product_uom_qty': qty,
|
"product_uom_qty": qty,
|
||||||
'origin': 'Test RMA',
|
"origin": "Test RMA",
|
||||||
'location_id': src.id,
|
"location_id": src.id,
|
||||||
'location_dest_id': dest.id,
|
"location_dest_id": dest.id,
|
||||||
'picking_id': picking_in.id
|
"picking_id": picking_in.id,
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def test_01_rma_order_line(self):
|
def test_01_rma_order_line(self):
|
||||||
for line in self.rma_customer_id.rma_line_ids:
|
for line in self.rma_customer_id.rma_line_ids:
|
||||||
line.with_context({'default_rma_id': line.rma_id.id
|
line.with_context(
|
||||||
})._default_warehouse_id()
|
{"default_rma_id": line.rma_id.id}
|
||||||
|
)._default_warehouse_id()
|
||||||
line._default_location_id()
|
line._default_location_id()
|
||||||
line.with_context({'partner_id': line.rma_id.partner_id.id
|
line.with_context(
|
||||||
})._default_delivery_address()
|
{"partner_id": line.rma_id.partner_id.id}
|
||||||
|
)._default_delivery_address()
|
||||||
line._compute_in_shipment_count()
|
line._compute_in_shipment_count()
|
||||||
line._compute_out_shipment_count()
|
line._compute_out_shipment_count()
|
||||||
|
|
||||||
data = {'reference_move_id': line.reference_move_id.id}
|
data = {"reference_move_id": line.reference_move_id.id}
|
||||||
new_line = self.rma_line.new(data)
|
new_line = self.rma_line.new(data)
|
||||||
new_line._onchange_reference_move_id()
|
new_line._onchange_reference_move_id()
|
||||||
|
|
||||||
# check assert if call reference_move_id onchange
|
# check assert if call reference_move_id onchange
|
||||||
self.assertEquals(new_line.product_id,
|
self.assertEquals(new_line.product_id, line.reference_move_id.product_id)
|
||||||
line.reference_move_id.product_id)
|
self.assertEquals(
|
||||||
self.assertEquals(new_line.product_qty,
|
new_line.product_qty, line.reference_move_id.product_uom_qty
|
||||||
line.reference_move_id.product_uom_qty)
|
)
|
||||||
self.assertEquals(new_line.location_id.location_id,
|
self.assertEquals(
|
||||||
line.reference_move_id.location_id)
|
new_line.location_id.location_id, line.reference_move_id.location_id
|
||||||
self.assertEquals(new_line.origin,
|
)
|
||||||
line.reference_move_id.picking_id.name)
|
self.assertEquals(new_line.origin, line.reference_move_id.picking_id.name)
|
||||||
self.assertEquals(new_line.delivery_address_id,
|
self.assertEquals(
|
||||||
line.reference_move_id.picking_partner_id)
|
new_line.delivery_address_id, line.reference_move_id.picking_partner_id
|
||||||
self.assertEquals(new_line.qty_to_receive,
|
)
|
||||||
line.reference_move_id.product_uom_qty)
|
self.assertEquals(
|
||||||
|
new_line.qty_to_receive, line.reference_move_id.product_uom_qty
|
||||||
|
)
|
||||||
|
|
||||||
line.action_rma_to_approve()
|
line.action_rma_to_approve()
|
||||||
line.action_rma_draft()
|
line.action_rma_draft()
|
||||||
line.action_rma_done()
|
line.action_rma_done()
|
||||||
|
|
||||||
data = {'product_id': line.product_id.id}
|
data = {"product_id": line.product_id.id}
|
||||||
new_line = self.rma_line.new(data)
|
new_line = self.rma_line.new(data)
|
||||||
new_line._onchange_product_id()
|
new_line._onchange_product_id()
|
||||||
|
|
||||||
data = {'operation_id': line.operation_id.id}
|
data = {"operation_id": line.operation_id.id}
|
||||||
new_line = self.rma_line.new(data)
|
new_line = self.rma_line.new(data)
|
||||||
new_line._onchange_operation_id()
|
new_line._onchange_operation_id()
|
||||||
|
|
||||||
# check assert if call operation_id onchange
|
# check assert if call operation_id onchange
|
||||||
self.assertEquals(new_line.operation_id.receipt_policy,
|
self.assertEquals(new_line.operation_id.receipt_policy, line.receipt_policy)
|
||||||
line.receipt_policy)
|
|
||||||
|
|
||||||
data = {'customer_to_supplier': line.customer_to_supplier}
|
data = {"customer_to_supplier": line.customer_to_supplier}
|
||||||
new_line = self.rma_line.new(data)
|
new_line = self.rma_line.new(data)
|
||||||
new_line._onchange_receipt_policy()
|
new_line._onchange_receipt_policy()
|
||||||
|
|
||||||
data = {'lot_id': line.lot_id.id}
|
data = {"lot_id": line.lot_id.id}
|
||||||
new_line = self.rma_line.new(data)
|
new_line = self.rma_line.new(data)
|
||||||
new_line._onchange_lot_id()
|
new_line._onchange_lot_id()
|
||||||
|
|
||||||
@@ -248,155 +279,112 @@ class TestRma(common.SavepointCase):
|
|||||||
self.rma_customer_id.action_view_supplier_lines()
|
self.rma_customer_id.action_view_supplier_lines()
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
line.rma_id.partner_id = self.partner_id.id
|
line.rma_id.partner_id = self.partner_id.id
|
||||||
self.rma_customer_id.rma_line_ids[0].\
|
self.rma_customer_id.rma_line_ids[0].partner_id = self.env.ref(
|
||||||
partner_id = self.env.ref('base.res_partner_3').id
|
"base.res_partner_3"
|
||||||
|
).id
|
||||||
self.rma_customer_id.action_view_supplier_lines()
|
self.rma_customer_id.action_view_supplier_lines()
|
||||||
|
|
||||||
def test_02_customer_rma(self):
|
def test_02_customer_rma(self):
|
||||||
wizard = self.rma_make_picking.with_context({
|
wizard = self.rma_make_picking.with_context(
|
||||||
'active_ids': self.rma_customer_id.rma_line_ids.ids,
|
{
|
||||||
'active_model': 'rma.order.line',
|
"active_ids": self.rma_customer_id.rma_line_ids.ids,
|
||||||
'picking_type': 'incoming',
|
"active_model": "rma.order.line",
|
||||||
'active_id': 1
|
"picking_type": "incoming",
|
||||||
}).create({})
|
"active_id": 1,
|
||||||
|
}
|
||||||
|
).create({})
|
||||||
wizard._create_picking()
|
wizard._create_picking()
|
||||||
res = self.rma_customer_id.rma_line_ids.action_view_in_shipments()
|
res = self.rma_customer_id.rma_line_ids.action_view_in_shipments()
|
||||||
self.assertTrue('res_id' in res,
|
self.assertTrue("res_id" in res, "Incorrect number of pickings created")
|
||||||
"Incorrect number of pickings created")
|
picking = self.env["stock.picking"].browse(res["res_id"])
|
||||||
picking = self.env['stock.picking'].browse(res['res_id'])
|
self.assertEquals(len(picking), 1, "Incorrect number of pickings created")
|
||||||
self.assertEquals(len(picking), 1,
|
|
||||||
"Incorrect number of pickings created")
|
|
||||||
moves = picking.move_lines
|
moves = picking.move_lines
|
||||||
self.assertEquals(len(moves), 3,
|
self.assertEquals(len(moves), 3, "Incorrect number of moves created")
|
||||||
"Incorrect number of moves created")
|
|
||||||
for line in self.rma_customer_id.rma_line_ids:
|
for line in self.rma_customer_id.rma_line_ids:
|
||||||
# common qtys for all products
|
# common qtys for all products
|
||||||
self.assertEquals(line.qty_received, 0,
|
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 0,
|
self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||||
"Wrong qty to deliver")
|
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_outgoing, 0,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
self.assertEquals(line.qty_delivered, 0,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
# product specific
|
# product specific
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_to_receive, 3,
|
self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_incoming, 3, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 3,
|
|
||||||
"Wrong qty incoming")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_to_receive, 5,
|
self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_incoming, 5, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 5,
|
|
||||||
"Wrong qty incoming")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_to_receive, 2,
|
self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_incoming, 2, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 2,
|
|
||||||
"Wrong qty incoming")
|
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
for mv in picking.move_lines:
|
for mv in picking.move_lines:
|
||||||
mv.quantity_done = mv.product_uom_qty
|
mv.quantity_done = mv.product_uom_qty
|
||||||
picking.action_done()
|
picking.action_done()
|
||||||
for line in self.rma_customer_id.rma_line_ids:
|
for line in self.rma_customer_id.rma_line_ids:
|
||||||
self.assertEquals(line.qty_to_receive, 0,
|
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to_receive")
|
||||||
"Wrong qty to_receive")
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||||
"Wrong qty incoming")
|
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_outgoing, 0,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
self.assertEquals(line.qty_delivered, 0,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_received, 3,
|
self.assertEquals(line.qty_received, 3, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_to_deliver, 3, "Wrong qty to_deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 3,
|
|
||||||
"Wrong qty to_deliver")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_received, 5,
|
self.assertEquals(line.qty_received, 5, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_to_deliver, 5, "Wrong qty to_deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 5,
|
|
||||||
"Wrong qty to_deliver")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_received, 2,
|
self.assertEquals(line.qty_received, 2, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_to_deliver, 2, "Wrong qty to_deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 2,
|
|
||||||
"Wrong qty to_deliver")
|
|
||||||
|
|
||||||
wizard = self.rma_make_picking.with_context({
|
wizard = self.rma_make_picking.with_context(
|
||||||
'active_id': 1,
|
{
|
||||||
'active_ids': self.rma_customer_id.rma_line_ids.ids,
|
"active_id": 1,
|
||||||
'active_model': 'rma.order.line',
|
"active_ids": self.rma_customer_id.rma_line_ids.ids,
|
||||||
'picking_type': 'outgoing',
|
"active_model": "rma.order.line",
|
||||||
}).create({})
|
"picking_type": "outgoing",
|
||||||
|
}
|
||||||
|
).create({})
|
||||||
wizard._create_picking()
|
wizard._create_picking()
|
||||||
res = self.rma_customer_id.rma_line_ids.action_view_out_shipments()
|
res = self.rma_customer_id.rma_line_ids.action_view_out_shipments()
|
||||||
self.assertTrue('res_id' in res,
|
self.assertTrue("res_id" in res, "Incorrect number of pickings created")
|
||||||
"Incorrect number of pickings created")
|
picking = self.env["stock.picking"].browse(res["res_id"])
|
||||||
picking = self.env['stock.picking'].browse(res['res_id'])
|
|
||||||
moves = picking.move_lines
|
moves = picking.move_lines
|
||||||
self.assertEquals(len(moves), 3,
|
self.assertEquals(len(moves), 3, "Incorrect number of moves created")
|
||||||
"Incorrect number of moves created")
|
|
||||||
for line in self.rma_customer_id.rma_line_ids:
|
for line in self.rma_customer_id.rma_line_ids:
|
||||||
self.assertEquals(line.qty_to_receive, 0,
|
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||||
"Wrong qty incoming")
|
|
||||||
self.assertEquals(line.qty_delivered, 0,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_to_deliver, 3,
|
self.assertEquals(line.qty_to_deliver, 3, "Wrong qty to deliver")
|
||||||
"Wrong qty to deliver")
|
self.assertEquals(line.qty_outgoing, 3, "Wrong qty outgoing")
|
||||||
self.assertEquals(line.qty_outgoing, 3,
|
self.assertEquals(line.qty_received, 3, "Wrong qty received")
|
||||||
"Wrong qty outgoing")
|
|
||||||
self.assertEquals(line.qty_received, 3,
|
|
||||||
"Wrong qty received")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_received, 5,
|
self.assertEquals(line.qty_received, 5, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_to_deliver, 5, "Wrong qty to deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 5,
|
self.assertEquals(line.qty_outgoing, 5, "Wrong qty outgoing")
|
||||||
"Wrong qty to deliver")
|
|
||||||
self.assertEquals(line.qty_outgoing, 5,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_received, 2,
|
self.assertEquals(line.qty_received, 2, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_to_deliver, 2, "Wrong qty to deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 2,
|
self.assertEquals(line.qty_outgoing, 2, "Wrong qty outgoing")
|
||||||
"Wrong qty to deliver")
|
|
||||||
self.assertEquals(line.qty_outgoing, 2,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
for mv in picking.move_lines:
|
for mv in picking.move_lines:
|
||||||
mv.quantity_done = mv.product_uom_qty
|
mv.quantity_done = mv.product_uom_qty
|
||||||
picking.action_done()
|
picking.action_done()
|
||||||
for line in self.rma_customer_id.rma_line_ids:
|
for line in self.rma_customer_id.rma_line_ids:
|
||||||
self.assertEquals(line.qty_to_receive, 0,
|
self.assertEquals(line.qty_to_receive, 0, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||||
"Wrong qty incoming")
|
self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing")
|
||||||
self.assertEquals(line.qty_to_deliver, 0,
|
|
||||||
"Wrong qty to deliver")
|
|
||||||
self.assertEquals(line.qty_outgoing, 0,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_received, 3,
|
self.assertEquals(line.qty_received, 3, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_delivered, 3, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_delivered, 3,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_received, 5,
|
self.assertEquals(line.qty_received, 5, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_delivered, 5, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_delivered, 5,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_received, 2,
|
self.assertEquals(line.qty_received, 2, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_delivered, 2, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_delivered, 2,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
self.line.action_rma_done()
|
self.line.action_rma_done()
|
||||||
self.assertEquals(self.line.state, 'done',
|
self.assertEquals(self.line.state, "done", "Wrong State")
|
||||||
"Wrong State")
|
|
||||||
self.rma_customer_id.action_view_in_shipments()
|
self.rma_customer_id.action_view_in_shipments()
|
||||||
self.rma_customer_id.action_view_out_shipments()
|
self.rma_customer_id.action_view_out_shipments()
|
||||||
self.rma_customer_id.action_view_lines()
|
self.rma_customer_id.action_view_lines()
|
||||||
@@ -407,204 +395,165 @@ class TestRma(common.SavepointCase):
|
|||||||
line.action_rma_to_approve()
|
line.action_rma_to_approve()
|
||||||
line.action_rma_approve()
|
line.action_rma_approve()
|
||||||
line._onchange_operation_id()
|
line._onchange_operation_id()
|
||||||
wizard = self.rma_make_picking.with_context({
|
wizard = self.rma_make_picking.with_context(
|
||||||
'active_id': 1,
|
{
|
||||||
'active_ids': self.rma_droship_id.rma_line_ids.ids,
|
"active_id": 1,
|
||||||
'active_model': 'rma.order.line',
|
"active_ids": self.rma_droship_id.rma_line_ids.ids,
|
||||||
'picking_type': 'incoming',
|
"active_model": "rma.order.line",
|
||||||
}).create({})
|
"picking_type": "incoming",
|
||||||
|
}
|
||||||
|
).create({})
|
||||||
wizard._create_picking()
|
wizard._create_picking()
|
||||||
res = self.rma_droship_id.rma_line_ids.action_view_in_shipments()
|
res = self.rma_droship_id.rma_line_ids.action_view_in_shipments()
|
||||||
self.assertTrue('res_id' in res,
|
self.assertTrue("res_id" in res, "Incorrect number of pickings created")
|
||||||
"Incorrect number of pickings created")
|
picking = self.env["stock.picking"].browse(res["res_id"])
|
||||||
picking = self.env['stock.picking'].browse(res['res_id'])
|
self.assertEquals(len(picking), 1, "Incorrect number of pickings created")
|
||||||
self.assertEquals(len(picking), 1,
|
|
||||||
"Incorrect number of pickings created")
|
|
||||||
moves = picking.move_lines
|
moves = picking.move_lines
|
||||||
self.assertEquals(len(moves), 3,
|
self.assertEquals(len(moves), 3, "Incorrect number of moves created")
|
||||||
"Incorrect number of moves created")
|
wizard = self.make_supplier_rma.with_context(
|
||||||
wizard = self.make_supplier_rma.with_context({
|
{
|
||||||
'active_ids': self.rma_droship_id.rma_line_ids.ids,
|
"active_ids": self.rma_droship_id.rma_line_ids.ids,
|
||||||
'active_model': 'rma.order.line',
|
"active_model": "rma.order.line",
|
||||||
'active_id': 1
|
"active_id": 1,
|
||||||
}).create({})
|
}
|
||||||
|
).create({})
|
||||||
res = wizard.make_supplier_rma()
|
res = wizard.make_supplier_rma()
|
||||||
supplier_rma = self.rma.browse(res['res_id'])
|
supplier_rma = self.rma.browse(res["res_id"])
|
||||||
for line in supplier_rma.rma_line_ids:
|
for line in supplier_rma.rma_line_ids:
|
||||||
# common qtys for all products
|
# common qtys for all products
|
||||||
self.assertEquals(line.qty_received, 0,
|
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_outgoing, 0, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_outgoing, 0,
|
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||||
"Wrong qty incoming")
|
|
||||||
self.assertEquals(line.qty_delivered, 0,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
# product specific
|
# product specific
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_to_deliver, 3,
|
self.assertEquals(line.qty_to_deliver, 3, "Wrong qty to deliver")
|
||||||
"Wrong qty to deliver")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_to_deliver, 5,
|
self.assertEquals(line.qty_to_deliver, 5, "Wrong qty to deliver")
|
||||||
"Wrong qty to deliver")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_to_deliver, 2,
|
self.assertEquals(line.qty_to_deliver, 2, "Wrong qty to deliver")
|
||||||
"Wrong qty to deliver")
|
|
||||||
|
|
||||||
for line in self.rma_droship_id.rma_line_ids:
|
for line in self.rma_droship_id.rma_line_ids:
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_to_supplier_rma, 0,
|
self.assertEquals(
|
||||||
"Wrong qty to supplier rma")
|
line.qty_to_supplier_rma, 0, "Wrong qty to supplier rma"
|
||||||
self.assertEquals(line.qty_in_supplier_rma, 3,
|
)
|
||||||
"Wrong qty in supplier rma")
|
self.assertEquals(
|
||||||
|
line.qty_in_supplier_rma, 3, "Wrong qty in supplier rma"
|
||||||
|
)
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_to_supplier_rma, 0,
|
self.assertEquals(
|
||||||
"Wrong qty to supplier rma")
|
line.qty_to_supplier_rma, 0, "Wrong qty to supplier rma"
|
||||||
self.assertEquals(line.qty_in_supplier_rma, 5,
|
)
|
||||||
"Wrong qty in supplier rma")
|
self.assertEquals(
|
||||||
|
line.qty_in_supplier_rma, 5, "Wrong qty in supplier rma"
|
||||||
|
)
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_to_supplier_rma, 0,
|
self.assertEquals(
|
||||||
"Wrong qty to supplier rma")
|
line.qty_to_supplier_rma, 0, "Wrong qty to supplier rma"
|
||||||
self.assertEquals(line.qty_in_supplier_rma, 2,
|
)
|
||||||
"Wrong qty in supplier rma")
|
self.assertEquals(
|
||||||
|
line.qty_in_supplier_rma, 2, "Wrong qty in supplier rma"
|
||||||
|
)
|
||||||
for line in self.rma_droship_id.rma_line_ids:
|
for line in self.rma_droship_id.rma_line_ids:
|
||||||
line.action_rma_done()
|
line.action_rma_done()
|
||||||
self.assertEquals(line.state, 'done',
|
self.assertEquals(line.state, "done", "Wrong State")
|
||||||
"Wrong State")
|
|
||||||
|
|
||||||
# Supplier RMA
|
# Supplier RMA
|
||||||
def test_04_supplier_rma(self):
|
def test_04_supplier_rma(self):
|
||||||
wizard = self.rma_make_picking.with_context({
|
wizard = self.rma_make_picking.with_context(
|
||||||
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
|
{
|
||||||
'active_model': 'rma.order.line',
|
"active_ids": self.rma_supplier_id.rma_line_ids.ids,
|
||||||
'picking_type': 'outgoing',
|
"active_model": "rma.order.line",
|
||||||
'active_id': 1
|
"picking_type": "outgoing",
|
||||||
}).create({})
|
"active_id": 1,
|
||||||
|
}
|
||||||
|
).create({})
|
||||||
wizard._create_picking()
|
wizard._create_picking()
|
||||||
res = self.rma_supplier_id.rma_line_ids.action_view_out_shipments()
|
res = self.rma_supplier_id.rma_line_ids.action_view_out_shipments()
|
||||||
self.assertTrue('res_id' in res,
|
self.assertTrue("res_id" in res, "Incorrect number of pickings created")
|
||||||
"Incorrect number of pickings created")
|
picking = self.env["stock.picking"].browse(res["res_id"])
|
||||||
picking = self.env['stock.picking'].browse(res['res_id'])
|
|
||||||
moves = picking.move_lines
|
moves = picking.move_lines
|
||||||
self.assertEquals(len(moves), 3,
|
self.assertEquals(len(moves), 3, "Incorrect number of moves created")
|
||||||
"Incorrect number of moves created")
|
|
||||||
for line in self.rma_supplier_id.rma_line_ids:
|
for line in self.rma_supplier_id.rma_line_ids:
|
||||||
# common qtys for all products
|
# common qtys for all products
|
||||||
self.assertEquals(line.qty_received, 0,
|
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered")
|
||||||
"Wrong qty incoming")
|
|
||||||
self.assertEquals(line.qty_delivered, 0,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
# product specific
|
# product specific
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_to_receive, 3,
|
self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_to_deliver, 3, "Wrong qty to deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 3,
|
self.assertEquals(line.qty_outgoing, 3, "Wrong qty outgoing")
|
||||||
"Wrong qty to deliver")
|
|
||||||
self.assertEquals(line.qty_outgoing, 3,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_to_receive, 5,
|
self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_to_deliver, 5, "Wrong qty to deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 5,
|
self.assertEquals(line.qty_outgoing, 5, "Wrong qty outgoing")
|
||||||
"Wrong qty to deliver")
|
|
||||||
self.assertEquals(line.qty_outgoing, 5,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_to_receive, 2,
|
self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_to_deliver, 2, "Wrong qty to deliver")
|
||||||
self.assertEquals(line.qty_to_deliver, 2,
|
self.assertEquals(line.qty_outgoing, 2, "Wrong qty outgoing")
|
||||||
"Wrong qty to deliver")
|
|
||||||
self.assertEquals(line.qty_outgoing, 2,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
|
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
for mv in picking.move_lines:
|
for mv in picking.move_lines:
|
||||||
mv.quantity_done = mv.product_uom_qty
|
mv.quantity_done = mv.product_uom_qty
|
||||||
picking.action_done()
|
picking.action_done()
|
||||||
for line in self.rma_supplier_id.rma_line_ids:
|
for line in self.rma_supplier_id.rma_line_ids:
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
"Wrong qty incoming")
|
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||||
self.assertEquals(line.qty_received, 0,
|
|
||||||
"Wrong qty received")
|
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_delivered, 3,
|
self.assertEquals(line.qty_delivered, 3, "Wrong qty delivered")
|
||||||
"Wrong qty delivered")
|
self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive")
|
||||||
self.assertEquals(line.qty_to_receive, 3,
|
|
||||||
"Wrong qty to receive")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_delivered, 5,
|
self.assertEquals(line.qty_delivered, 5, "Wrong qty delivered")
|
||||||
"Wrong qty delivered")
|
self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive")
|
||||||
self.assertEquals(line.qty_to_receive, 5,
|
|
||||||
"Wrong qty to receive")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_delivered, 2,
|
self.assertEquals(line.qty_delivered, 2, "Wrong qty delivered")
|
||||||
"Wrong qty delivered")
|
self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive")
|
||||||
self.assertEquals(line.qty_to_receive, 2,
|
wizard = self.rma_make_picking.with_context(
|
||||||
"Wrong qty to receive")
|
{
|
||||||
wizard = self.rma_make_picking.with_context({
|
"active_id": 1,
|
||||||
'active_id': 1,
|
"active_ids": self.rma_supplier_id.rma_line_ids.ids,
|
||||||
'active_ids': self.rma_supplier_id.rma_line_ids.ids,
|
"active_model": "rma.order.line",
|
||||||
'active_model': 'rma.order.line',
|
"picking_type": "incoming",
|
||||||
'picking_type': 'incoming',
|
}
|
||||||
}).create({})
|
).create({})
|
||||||
wizard._create_picking()
|
wizard._create_picking()
|
||||||
res = self.rma_supplier_id.rma_line_ids.action_view_in_shipments()
|
res = self.rma_supplier_id.rma_line_ids.action_view_in_shipments()
|
||||||
self.assertTrue('res_id' in res,
|
self.assertTrue("res_id" in res, "Incorrect number of pickings created")
|
||||||
"Incorrect number of pickings created")
|
pickings = self.env["stock.picking"].browse(res["res_id"])
|
||||||
pickings = self.env['stock.picking'].browse(res['res_id'])
|
self.assertEquals(len(pickings), 1, "Incorrect number of pickings created")
|
||||||
self.assertEquals(len(pickings), 1,
|
|
||||||
"Incorrect number of pickings created")
|
|
||||||
picking_out = pickings[0]
|
picking_out = pickings[0]
|
||||||
moves = picking_out.move_lines
|
moves = picking_out.move_lines
|
||||||
self.assertEquals(len(moves), 3,
|
self.assertEquals(len(moves), 3, "Incorrect number of moves created")
|
||||||
"Incorrect number of moves created")
|
|
||||||
for line in self.rma_supplier_id.rma_line_ids:
|
for line in self.rma_supplier_id.rma_line_ids:
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
"Wrong qty incoming")
|
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||||
self.assertEquals(line.qty_received, 0,
|
self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||||
"Wrong qty received")
|
|
||||||
self.assertEquals(line.qty_to_deliver, 0,
|
|
||||||
"Wrong qty to deliver")
|
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_to_receive, 3,
|
self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
|
||||||
"Wrong qty incoming")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_to_receive, 5,
|
self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_to_receive, 2,
|
self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
|
||||||
picking_out.action_assign()
|
picking_out.action_assign()
|
||||||
for mv in picking.move_lines:
|
for mv in picking.move_lines:
|
||||||
mv.quantity_done = mv.product_uom_qty
|
mv.quantity_done = mv.product_uom_qty
|
||||||
picking_out.action_done()
|
picking_out.action_done()
|
||||||
for line in self.rma_supplier_id.rma_line_ids[0]:
|
for line in self.rma_supplier_id.rma_line_ids[0]:
|
||||||
self.assertEquals(line.qty_to_receive, 3,
|
self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive")
|
||||||
"Wrong qty to receive")
|
self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming")
|
||||||
self.assertEquals(line.qty_incoming, 0,
|
self.assertEquals(line.qty_to_deliver, 0, "Wrong qty to deliver")
|
||||||
"Wrong qty incoming")
|
self.assertEquals(line.qty_outgoing, 3, "Wrong qty outgoing")
|
||||||
self.assertEquals(line.qty_to_deliver, 0,
|
|
||||||
"Wrong qty to deliver")
|
|
||||||
self.assertEquals(line.qty_outgoing, 3,
|
|
||||||
"Wrong qty outgoing")
|
|
||||||
if line.product_id == self.product_1:
|
if line.product_id == self.product_1:
|
||||||
self.assertEquals(line.qty_received, 0,
|
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_delivered, 3, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_delivered, 3,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
if line.product_id == self.product_2:
|
if line.product_id == self.product_2:
|
||||||
self.assertEquals(line.qty_received, 0,
|
self.assertEquals(line.qty_received, 0, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_delivered, 5, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_delivered, 5,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
if line.product_id == self.product_3:
|
if line.product_id == self.product_3:
|
||||||
self.assertEquals(line.qty_received, 2,
|
self.assertEquals(line.qty_received, 2, "Wrong qty received")
|
||||||
"Wrong qty received")
|
self.assertEquals(line.qty_delivered, 2, "Wrong qty delivered")
|
||||||
self.assertEquals(line.qty_delivered, 2,
|
|
||||||
"Wrong qty delivered")
|
|
||||||
for line in self.rma_supplier_id.rma_line_ids:
|
for line in self.rma_supplier_id.rma_line_ids:
|
||||||
line.action_rma_done()
|
line.action_rma_done()
|
||||||
self.assertEquals(line.state, 'done',
|
self.assertEquals(line.state, "done", "Wrong State")
|
||||||
"Wrong State")
|
|
||||||
|
|||||||
@@ -20,4 +20,3 @@
|
|||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
||||||
|
|||||||
@@ -1,89 +1,101 @@
|
|||||||
# Copyright (C) 2017 Eficent Business and IT Consulting Services S.L.
|
# Copyright (C) 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
|
||||||
|
|
||||||
|
|
||||||
class RmaAddStockMove(models.TransientModel):
|
class RmaAddStockMove(models.TransientModel):
|
||||||
_name = 'rma_add_stock_move'
|
_name = "rma_add_stock_move"
|
||||||
_description = 'Wizard to add rma lines from pickings'
|
_description = "Wizard to add rma lines from pickings"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
res = super(RmaAddStockMove, self).default_get(fields_list)
|
res = super(RmaAddStockMove, 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['move_ids'] = False
|
res["move_ids"] = False
|
||||||
return res
|
return res
|
||||||
|
|
||||||
rma_id = fields.Many2one(
|
rma_id = fields.Many2one(
|
||||||
comodel_name='rma.order', string='RMA Order',
|
comodel_name="rma.order", string="RMA Order", readonly=True, ondelete="cascade"
|
||||||
readonly=True, ondelete='cascade',
|
|
||||||
)
|
)
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
comodel_name='res.partner', string='Partner',
|
comodel_name="res.partner", string="Partner", readonly=True
|
||||||
readonly=True,
|
|
||||||
)
|
)
|
||||||
move_ids = fields.Many2many(
|
move_ids = fields.Many2many(
|
||||||
comodel_name='stock.move', string='Stock Moves',
|
comodel_name="stock.move",
|
||||||
|
string="Stock Moves",
|
||||||
domain="[('state', '=', 'done')]",
|
domain="[('state', '=', 'done')]",
|
||||||
)
|
)
|
||||||
|
|
||||||
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
|
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
|
||||||
if self.env.context.get('customer'):
|
if self.env.context.get("customer"):
|
||||||
operation = sm.product_id.rma_customer_operation_id or \
|
operation = (
|
||||||
sm.product_id.categ_id.rma_customer_operation_id
|
sm.product_id.rma_customer_operation_id
|
||||||
|
or sm.product_id.categ_id.rma_customer_operation_id
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
operation = sm.product_id.rma_supplier_operation_id or \
|
operation = (
|
||||||
sm.product_id.categ_id.rma_supplier_operation_id
|
sm.product_id.rma_supplier_operation_id
|
||||||
|
or sm.product_id.categ_id.rma_supplier_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(_(
|
raise ValidationError(
|
||||||
"Please define a warehouse with a 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,
|
||||||
'reference_move_id': sm.id,
|
"reference_move_id": sm.id,
|
||||||
'product_id': sm.product_id.id,
|
"product_id": sm.product_id.id,
|
||||||
'lot_id': lot and lot.id or False,
|
"lot_id": lot and lot.id or False,
|
||||||
'origin': sm.picking_id.name or sm.name,
|
"origin": sm.picking_id.name or sm.name,
|
||||||
'uom_id': sm.product_uom.id,
|
"uom_id": sm.product_uom.id,
|
||||||
'operation_id': operation.id,
|
"operation_id": operation.id,
|
||||||
'product_qty': sm.product_uom_qty,
|
"product_qty": sm.product_uom_qty,
|
||||||
'delivery_address_id': sm.picking_id.partner_id.id,
|
"delivery_address_id": sm.picking_id.partner_id.id,
|
||||||
'rma_id': self.rma_id.id,
|
"rma_id": self.rma_id.id,
|
||||||
'receipt_policy': operation.receipt_policy,
|
"receipt_policy": operation.receipt_policy,
|
||||||
'delivery_policy': operation.delivery_policy,
|
"delivery_policy": operation.delivery_policy,
|
||||||
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
"in_warehouse_id": operation.in_warehouse_id.id or warehouse.id,
|
||||||
'out_warehouse_id': operation.out_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,
|
"in_route_id": operation.in_route_id.id or route.id,
|
||||||
'out_route_id': operation.out_route_id.id or route.id,
|
"out_route_id": operation.out_route_id.id or route.id,
|
||||||
'location_id': (operation.location_id.id or
|
"location_id": (
|
||||||
operation.in_warehouse_id.lot_rma_id.id or
|
operation.location_id.id
|
||||||
warehouse.lot_rma_id.id)
|
or operation.in_warehouse_id.lot_rma_id.id
|
||||||
|
or warehouse.lot_rma_id.id
|
||||||
|
),
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -96,20 +108,19 @@ class RmaAddStockMove(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_stock_moves = self._get_existing_stock_moves()
|
existing_stock_moves = self._get_existing_stock_moves()
|
||||||
for sm in self.move_ids:
|
for sm in self.move_ids:
|
||||||
if sm not in existing_stock_moves:
|
if sm not in existing_stock_moves:
|
||||||
if sm.product_id.tracking == 'none':
|
if sm.product_id.tracking == "none":
|
||||||
data = self._prepare_rma_line_from_stock_move(sm,
|
data = self._prepare_rma_line_from_stock_move(sm, lot=False)
|
||||||
lot=False)
|
rma_line_obj.with_context(default_rma_id=self.rma_id.id).create(
|
||||||
rma_line_obj.with_context(
|
data
|
||||||
default_rma_id=self.rma_id.id).create(data)
|
)
|
||||||
else:
|
else:
|
||||||
lot_ids = [x.lot_id.id for x in sm.move_line_ids if
|
lot_ids = [x.lot_id.id for x in sm.move_line_ids if x.lot_id]
|
||||||
x.lot_id]
|
data = self._prepare_rma_line_from_stock_move(sm, lot=lot_ids[0])
|
||||||
data = self._prepare_rma_line_from_stock_move(
|
rma_line_obj.with_context(default_rma_id=self.rma_id.id).create(
|
||||||
sm, lot=lot_ids[0])
|
data
|
||||||
rma_line_obj.with_context(
|
)
|
||||||
default_rma_id=self.rma_id.id).create(data)
|
return {"type": "ir.actions.act_window_close"}
|
||||||
return {'type': 'ir.actions.act_window_close'}
|
|
||||||
|
|||||||
@@ -2,26 +2,29 @@
|
|||||||
# 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 time
|
import time
|
||||||
from odoo import models, fields, api, _
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError, ValidationError
|
from odoo.exceptions import UserError, ValidationError
|
||||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DT_FORMAT
|
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT as DT_FORMAT
|
||||||
|
|
||||||
import odoo.addons.decimal_precision as dp
|
import odoo.addons.decimal_precision as dp
|
||||||
|
|
||||||
|
|
||||||
class RmaMakePicking(models.TransientModel):
|
class RmaMakePicking(models.TransientModel):
|
||||||
_name = 'rma_make_picking.wizard'
|
_name = "rma_make_picking.wizard"
|
||||||
_description = 'Wizard to create pickings from rma lines'
|
_description = "Wizard to create pickings from rma lines"
|
||||||
|
|
||||||
@api.returns('rma.order.line')
|
@api.returns("rma.order.line")
|
||||||
def _prepare_item(self, line):
|
def _prepare_item(self, line):
|
||||||
values = {'product_id': line.product_id.id,
|
values = {
|
||||||
'product_qty': line.product_qty,
|
"product_id": line.product_id.id,
|
||||||
'uom_id': line.uom_id.id,
|
"product_qty": line.product_qty,
|
||||||
'qty_to_receive': line.qty_to_receive,
|
"uom_id": line.uom_id.id,
|
||||||
'qty_to_deliver': line.qty_to_deliver,
|
"qty_to_receive": line.qty_to_receive,
|
||||||
'line_id': line.id,
|
"qty_to_deliver": line.qty_to_deliver,
|
||||||
'rma_id': line.rma_id and line.rma_id.id or False,
|
"line_id": line.id,
|
||||||
'wiz_id': self.env.context['active_id'],
|
"rma_id": line.rma_id and line.rma_id.id or False,
|
||||||
|
"wiz_id": self.env.context["active_id"],
|
||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@@ -33,46 +36,47 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
"""
|
"""
|
||||||
context = self._context.copy()
|
context = self._context.copy()
|
||||||
res = super(RmaMakePicking, self).default_get(fields_list)
|
res = super(RmaMakePicking, self).default_get(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', \
|
assert active_model == "rma.order.line", "Bad context propagation"
|
||||||
'Bad context propagation'
|
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
lines = rma_line_obj.browse(rma_line_ids)
|
lines = rma_line_obj.browse(rma_line_ids)
|
||||||
if len(lines.mapped('partner_id')) > 1:
|
if len(lines.mapped("partner_id")) > 1:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_('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 "
|
||||||
|
"the same time"
|
||||||
|
)
|
||||||
|
)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
items.append([0, 0, self._prepare_item(line)])
|
items.append([0, 0, self._prepare_item(line)])
|
||||||
res['item_ids'] = items
|
res["item_ids"] = items
|
||||||
context.update({'items_ids': items})
|
context.update({"items_ids": items})
|
||||||
return res
|
return res
|
||||||
|
|
||||||
item_ids = fields.One2many(
|
item_ids = fields.One2many("rma_make_picking.wizard.item", "wiz_id", string="Items")
|
||||||
'rma_make_picking.wizard.item',
|
|
||||||
'wiz_id', string='Items')
|
|
||||||
|
|
||||||
def find_procurement_group(self, item):
|
def find_procurement_group(self, item):
|
||||||
if item.line_id.rma_id:
|
if item.line_id.rma_id:
|
||||||
return self.env['procurement.group'].search([
|
return self.env["procurement.group"].search(
|
||||||
('rma_id', '=', item.line_id.rma_id.id)])
|
[("rma_id", "=", item.line_id.rma_id.id)]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return self.env['procurement.group'].search([
|
return self.env["procurement.group"].search(
|
||||||
('rma_line_id', '=', item.line_id.id)])
|
[("rma_line_id", "=", item.line_id.id)]
|
||||||
|
)
|
||||||
|
|
||||||
def _get_procurement_group_data(self, item):
|
def _get_procurement_group_data(self, item):
|
||||||
group_data = {
|
group_data = {
|
||||||
'partner_id': item.line_id.partner_id.id,
|
"partner_id": item.line_id.partner_id.id,
|
||||||
'name': item.line_id.rma_id.name or item.line_id.name,
|
"name": item.line_id.rma_id.name or item.line_id.name,
|
||||||
'rma_id': item.line_id.rma_id and item.line_id.rma_id.id or False,
|
"rma_id": item.line_id.rma_id and item.line_id.rma_id.id or False,
|
||||||
'rma_line_id': item.line_id.id if not item.line_id.rma_id else
|
"rma_line_id": item.line_id.id if not item.line_id.rma_id else False,
|
||||||
False,
|
|
||||||
}
|
}
|
||||||
return group_data
|
return group_data
|
||||||
|
|
||||||
@@ -87,34 +91,31 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
elif item.line_id.partner_id:
|
elif item.line_id.partner_id:
|
||||||
delivery_address = item.line_id.partner_id
|
delivery_address = item.line_id.partner_id
|
||||||
else:
|
else:
|
||||||
raise ValidationError(_('Unknown delivery address'))
|
raise ValidationError(_("Unknown delivery address"))
|
||||||
return delivery_address
|
return delivery_address
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_address_location(self, delivery_address_id, type):
|
def _get_address_location(self, delivery_address_id, type):
|
||||||
if type == 'supplier':
|
if type == "supplier":
|
||||||
return delivery_address_id.property_stock_supplier
|
return delivery_address_id.property_stock_supplier
|
||||||
elif type == 'customer':
|
elif type == "customer":
|
||||||
return delivery_address_id.property_stock_customer
|
return delivery_address_id.property_stock_customer
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_procurement_data(self, item, group, qty, picking_type):
|
def _get_procurement_data(self, item, group, qty, picking_type):
|
||||||
line = item.line_id
|
line = item.line_id
|
||||||
delivery_address_id = self._get_address(item)
|
delivery_address_id = self._get_address(item)
|
||||||
if picking_type == 'incoming':
|
if picking_type == "incoming":
|
||||||
if line.customer_to_supplier:
|
if line.customer_to_supplier:
|
||||||
location = self._get_address_location(
|
location = self._get_address_location(delivery_address_id, "supplier")
|
||||||
delivery_address_id, 'supplier')
|
|
||||||
elif line.supplier_to_customer:
|
elif line.supplier_to_customer:
|
||||||
location = self._get_address_location(
|
location = self._get_address_location(delivery_address_id, "customer")
|
||||||
delivery_address_id, 'customer')
|
|
||||||
else:
|
else:
|
||||||
location = line.location_id
|
location = line.location_id
|
||||||
warehouse = line.in_warehouse_id
|
warehouse = line.in_warehouse_id
|
||||||
route = line.in_route_id
|
route = line.in_route_id
|
||||||
else:
|
else:
|
||||||
location = self._get_address_location(
|
location = self._get_address_location(delivery_address_id, line.type)
|
||||||
delivery_address_id, line.type)
|
|
||||||
warehouse = line.out_warehouse_id
|
warehouse = line.out_warehouse_id
|
||||||
route = line.out_route_id
|
route = line.out_route_id
|
||||||
if not route:
|
if not route:
|
||||||
@@ -122,18 +123,18 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
if not warehouse:
|
if not warehouse:
|
||||||
raise ValidationError(_("No warehouse specified"))
|
raise ValidationError(_("No warehouse specified"))
|
||||||
procurement_data = {
|
procurement_data = {
|
||||||
'name': line.rma_id and line.rma_id.name or line.name,
|
"name": line.rma_id and line.rma_id.name or line.name,
|
||||||
'group_id': group,
|
"group_id": group,
|
||||||
'origin': line.name,
|
"origin": line.name,
|
||||||
'warehouse_id': warehouse,
|
"warehouse_id": warehouse,
|
||||||
'date_planned': time.strftime(DT_FORMAT),
|
"date_planned": time.strftime(DT_FORMAT),
|
||||||
'product_id': item.product_id,
|
"product_id": item.product_id,
|
||||||
'product_qty': qty,
|
"product_qty": qty,
|
||||||
'partner_id': delivery_address_id.id,
|
"partner_id": delivery_address_id.id,
|
||||||
'product_uom': line.product_id.product_tmpl_id.uom_id.id,
|
"product_uom": line.product_id.product_tmpl_id.uom_id.id,
|
||||||
'location_id': location,
|
"location_id": location,
|
||||||
'rma_line_id': line.id,
|
"rma_line_id": line.id,
|
||||||
'route_ids': route
|
"route_ids": route,
|
||||||
}
|
}
|
||||||
return procurement_data
|
return procurement_data
|
||||||
|
|
||||||
@@ -143,47 +144,41 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
group = self.find_procurement_group(item)
|
group = self.find_procurement_group(item)
|
||||||
if not group:
|
if not group:
|
||||||
pg_data = self._get_procurement_group_data(item)
|
pg_data = self._get_procurement_group_data(item)
|
||||||
group = self.env['procurement.group'].create(pg_data)
|
group = self.env["procurement.group"].create(pg_data)
|
||||||
if picking_type == 'incoming':
|
if picking_type == "incoming":
|
||||||
qty = item.qty_to_receive
|
qty = item.qty_to_receive
|
||||||
else:
|
else:
|
||||||
qty = item.qty_to_deliver
|
qty = item.qty_to_deliver
|
||||||
values = self._get_procurement_data(item, group, qty, picking_type)
|
values = self._get_procurement_data(item, group, qty, picking_type)
|
||||||
# create picking
|
# create picking
|
||||||
try:
|
try:
|
||||||
self.env['procurement.group'].run(
|
self.env["procurement.group"].run(
|
||||||
item.line_id.product_id,
|
item.line_id.product_id,
|
||||||
qty,
|
qty,
|
||||||
item.line_id.product_id.product_tmpl_id.uom_id,
|
item.line_id.product_id.product_tmpl_id.uom_id,
|
||||||
values.get('location_id'),
|
values.get("location_id"),
|
||||||
values.get('origin'),
|
values.get("origin"),
|
||||||
values.get('origin'),
|
values.get("origin"),
|
||||||
values
|
values,
|
||||||
)
|
)
|
||||||
except UserError as error:
|
except UserError as error:
|
||||||
errors.append(error.name)
|
errors.append(error.name)
|
||||||
if errors:
|
if errors:
|
||||||
raise UserError('\n'.join(errors))
|
raise UserError("\n".join(errors))
|
||||||
return values.get('origin')
|
return values.get("origin")
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _create_picking(self):
|
def _create_picking(self):
|
||||||
"""Method called when the user clicks on create picking"""
|
"""Method called when the user clicks on create picking"""
|
||||||
picking_type = self.env.context.get('picking_type')
|
picking_type = self.env.context.get("picking_type")
|
||||||
for item in self.item_ids:
|
for item in self.item_ids:
|
||||||
line = item.line_id
|
line = item.line_id
|
||||||
if line.state != 'approved':
|
if line.state != "approved":
|
||||||
raise ValidationError(
|
raise ValidationError(_("RMA %s is not approved") % line.name)
|
||||||
_('RMA %s is not approved') %
|
if line.receipt_policy == "no" and picking_type == "incoming":
|
||||||
line.name)
|
raise ValidationError(_("No shipments needed for this operation"))
|
||||||
if line.receipt_policy == 'no' and picking_type == \
|
if line.delivery_policy == "no" and picking_type == "outgoing":
|
||||||
'incoming':
|
raise ValidationError(_("No deliveries needed for this operation"))
|
||||||
raise ValidationError(
|
|
||||||
_('No shipments needed for this operation'))
|
|
||||||
if line.delivery_policy == 'no' and picking_type == \
|
|
||||||
'outgoing':
|
|
||||||
raise ValidationError(
|
|
||||||
_('No deliveries needed for this operation'))
|
|
||||||
procurement = self._create_procurement(item, picking_type)
|
procurement = self._create_procurement(item, picking_type)
|
||||||
return procurement
|
return procurement
|
||||||
|
|
||||||
@@ -192,67 +187,63 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
if pickings and procurements:
|
if pickings and procurements:
|
||||||
action = procurements.do_view_pickings()
|
action = procurements.do_view_pickings()
|
||||||
else:
|
else:
|
||||||
action = self.env.ref(
|
action = self.env.ref("procurement.procurement_order_action_exceptions")
|
||||||
'procurement.procurement_order_action_exceptions')
|
|
||||||
action = action.read()[0]
|
action = action.read()[0]
|
||||||
if procurements:
|
if procurements:
|
||||||
# choose the view_mode accordingly
|
# choose the view_mode accordingly
|
||||||
if len(procurements.ids) <= 1:
|
if len(procurements.ids) <= 1:
|
||||||
res = self.env.ref('procurement.procurement_form_view',
|
res = self.env.ref("procurement.procurement_form_view", False)
|
||||||
False)
|
action["views"] = [(res and res.id or False, "form")]
|
||||||
action['views'] = [(res and res.id or False, 'form')]
|
action["res_id"] = procurements.ids[0]
|
||||||
action['res_id'] = procurements.ids[0]
|
|
||||||
else:
|
else:
|
||||||
action['domain'] = [('id', 'in', procurements.ids)]
|
action["domain"] = [("id", "in", procurements.ids)]
|
||||||
return action
|
return action
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_create_picking(self):
|
def action_create_picking(self):
|
||||||
procurement = self._create_picking()
|
procurement = self._create_picking()
|
||||||
action = self.env.ref('stock.do_view_pickings')
|
action = self.env.ref("stock.do_view_pickings")
|
||||||
action = action.read()[0]
|
action = action.read()[0]
|
||||||
if procurement:
|
if procurement:
|
||||||
pickings = self.env['stock.picking'].search(
|
pickings = (
|
||||||
[('origin', '=', procurement)]).ids
|
self.env["stock.picking"].search([("origin", "=", procurement)]).ids
|
||||||
|
)
|
||||||
if len(pickings) > 1:
|
if len(pickings) > 1:
|
||||||
action['domain'] = [('id', 'in', pickings)]
|
action["domain"] = [("id", "in", pickings)]
|
||||||
else:
|
else:
|
||||||
form = self.env.ref('stock.view_picking_form', False)
|
form = self.env.ref("stock.view_picking_form", False)
|
||||||
action['views'] = [(form and form.id or False, 'form')]
|
action["views"] = [(form and form.id or False, "form")]
|
||||||
action['res_id'] = pickings and pickings[0]
|
action["res_id"] = pickings and pickings[0]
|
||||||
return action
|
return action
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_cancel(self):
|
def action_cancel(self):
|
||||||
return {'type': 'ir.actions.act_window_close'}
|
return {"type": "ir.actions.act_window_close"}
|
||||||
|
|
||||||
|
|
||||||
class RmaMakePickingItem(models.TransientModel):
|
class RmaMakePickingItem(models.TransientModel):
|
||||||
_name = "rma_make_picking.wizard.item"
|
_name = "rma_make_picking.wizard.item"
|
||||||
_description = "Items to receive"
|
_description = "Items to receive"
|
||||||
|
|
||||||
wiz_id = fields.Many2one(
|
wiz_id = fields.Many2one("rma_make_picking.wizard", string="Wizard", required=True)
|
||||||
'rma_make_picking.wizard',
|
line_id = fields.Many2one(
|
||||||
string='Wizard', required=True)
|
"rma.order.line", string="RMA order Line", readonly=True, ondelete="cascade"
|
||||||
line_id = fields.Many2one('rma.order.line',
|
)
|
||||||
string='RMA order Line',
|
rma_id = fields.Many2one(
|
||||||
readonly=True,
|
"rma.order", related="line_id.rma_id", string="RMA Group", readonly=True
|
||||||
ondelete='cascade')
|
)
|
||||||
rma_id = fields.Many2one('rma.order',
|
product_id = fields.Many2one("product.product", string="Product", readonly=True)
|
||||||
related='line_id.rma_id',
|
|
||||||
string='RMA Group',
|
|
||||||
readonly=True)
|
|
||||||
product_id = fields.Many2one('product.product', string='Product',
|
|
||||||
readonly=True)
|
|
||||||
product_qty = fields.Float(
|
product_qty = fields.Float(
|
||||||
related='line_id.product_qty',
|
related="line_id.product_qty",
|
||||||
string='Quantity Ordered', copy=False,
|
string="Quantity Ordered",
|
||||||
digits=dp.get_precision('Product Unit of Measure'), readonly=True)
|
copy=False,
|
||||||
|
digits=dp.get_precision("Product Unit of Measure"),
|
||||||
|
readonly=True,
|
||||||
|
)
|
||||||
qty_to_receive = fields.Float(
|
qty_to_receive = fields.Float(
|
||||||
string='Quantity to Receive',
|
string="Quantity to Receive", digits=dp.get_precision("Product Unit of Measure")
|
||||||
digits=dp.get_precision('Product Unit of Measure'))
|
)
|
||||||
qty_to_deliver = fields.Float(
|
qty_to_deliver = fields.Float(
|
||||||
string='Quantity To Deliver',
|
string="Quantity To Deliver", digits=dp.get_precision("Product Unit of Measure")
|
||||||
digits=dp.get_precision('Product Unit of Measure'))
|
)
|
||||||
uom_id = fields.Many2one('uom.uom', string='Unit of Measure',
|
uom_id = fields.Many2one("uom.uom", string="Unit of Measure", readonly=True)
|
||||||
readonly=True)
|
|
||||||
|
|||||||
@@ -1,86 +1,94 @@
|
|||||||
# 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, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
import odoo.addons.decimal_precision as dp
|
||||||
|
|
||||||
|
|
||||||
class RmaLineMakeSupplierRma(models.TransientModel):
|
class RmaLineMakeSupplierRma(models.TransientModel):
|
||||||
_name = "rma.order.line.make.supplier.rma"
|
_name = "rma.order.line.make.supplier.rma"
|
||||||
_description = "RMA Line Make Supplier RMA"
|
_description = "RMA Line Make Supplier RMA"
|
||||||
|
|
||||||
partner_id = fields.Many2one(
|
partner_id = fields.Many2one(
|
||||||
comodel_name='res.partner', string='Supplier',
|
comodel_name="res.partner",
|
||||||
domain=[('supplier', '=', True)], required=True,
|
string="Supplier",
|
||||||
|
domain=[("supplier", "=", True)],
|
||||||
|
required=True,
|
||||||
)
|
)
|
||||||
item_ids = fields.One2many(
|
item_ids = fields.One2many(
|
||||||
comodel_name='rma.order.line.make.supplier.rma.item',
|
comodel_name="rma.order.line.make.supplier.rma.item",
|
||||||
inverse_name='wiz_id', string='Items',
|
inverse_name="wiz_id",
|
||||||
|
string="Items",
|
||||||
)
|
)
|
||||||
supplier_rma_id = fields.Many2one(
|
supplier_rma_id = fields.Many2one(
|
||||||
comodel_name='rma.order', string='Supplier RMA Order Group',
|
comodel_name="rma.order", string="Supplier RMA Order Group"
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_default_operation(self):
|
def _get_default_operation(self):
|
||||||
"""Dropshipping is the most common use case of this wizard, thus
|
"""Dropshipping is the most common use case of this wizard, thus
|
||||||
trying to default to a dropshipping operation first."""
|
trying to default to a dropshipping operation first."""
|
||||||
operation = self.env['rma.operation'].search([
|
operation = self.env["rma.operation"].search(
|
||||||
('type', '=', 'supplier'),
|
[("type", "=", "supplier"), ("supplier_to_customer", "=", True)], limit=1
|
||||||
('supplier_to_customer', '=', True)], limit=1)
|
)
|
||||||
if not operation:
|
if not operation:
|
||||||
operation = self.env['rma.operation'].search(
|
operation = self.env["rma.operation"].search(
|
||||||
[('type', '=', 'supplier')], limit=1)
|
[("type", "=", "supplier")], limit=1
|
||||||
|
)
|
||||||
return operation
|
return operation
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_item(self, line):
|
def _prepare_item(self, line):
|
||||||
operation = self._get_default_operation()
|
operation = self._get_default_operation()
|
||||||
return {
|
return {
|
||||||
'line_id': line.id,
|
"line_id": line.id,
|
||||||
'product_id': line.product_id.id,
|
"product_id": line.product_id.id,
|
||||||
'name': line.name,
|
"name": line.name,
|
||||||
'product_qty': line.qty_to_supplier_rma,
|
"product_qty": line.qty_to_supplier_rma,
|
||||||
'uom_id': line.uom_id.id,
|
"uom_id": line.uom_id.id,
|
||||||
'operation_id': operation.id if operation else False,
|
"operation_id": operation.id if operation else False,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
res = super(RmaLineMakeSupplierRma, self).default_get(
|
res = super(RmaLineMakeSupplierRma, 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)])
|
||||||
suppliers = lines.mapped(
|
suppliers = lines.mapped(
|
||||||
lambda r: r.supplier_address_id.parent_id or r.supplier_address_id)
|
lambda r: r.supplier_address_id.parent_id or r.supplier_address_id
|
||||||
|
)
|
||||||
if len(suppliers) > 1:
|
if len(suppliers) > 1:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_('Only RMA lines from the same supplier can be '
|
_(
|
||||||
'processed at the same time'))
|
"Only RMA lines from the same supplier can be "
|
||||||
res['partner_id'] = suppliers.id
|
"processed at the same time"
|
||||||
res['item_ids'] = items
|
)
|
||||||
|
)
|
||||||
|
res["partner_id"] = suppliers.id
|
||||||
|
res["item_ids"] = items
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _prepare_supplier_rma(self, company):
|
def _prepare_supplier_rma(self, company):
|
||||||
if not self.partner_id:
|
if not self.partner_id:
|
||||||
raise ValidationError(_('Enter a supplier.'))
|
raise ValidationError(_("Enter a supplier."))
|
||||||
return {
|
return {
|
||||||
'partner_id': self.partner_id.id,
|
"partner_id": self.partner_id.id,
|
||||||
'delivery_address_id': self.partner_id.id,
|
"delivery_address_id": self.partner_id.id,
|
||||||
'type': 'supplier',
|
"type": "supplier",
|
||||||
'company_id': company.id,
|
"company_id": company.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -90,55 +98,61 @@ class RmaLineMakeSupplierRma(models.TransientModel):
|
|||||||
else:
|
else:
|
||||||
operation = self._get_default_operation()
|
operation = self._get_default_operation()
|
||||||
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(
|
raise ValidationError(
|
||||||
_("Please define a warehouse with a 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,
|
||||||
'type': 'supplier',
|
"type": "supplier",
|
||||||
'origin': item.line_id.rma_id.name,
|
"origin": item.line_id.rma_id.name,
|
||||||
'customer_address_id':
|
"customer_address_id": item.line_id.delivery_address_id.id
|
||||||
item.line_id.delivery_address_id.id or
|
or item.line_id.partner_id.id,
|
||||||
item.line_id.partner_id.id,
|
"product_id": item.line_id.product_id.id,
|
||||||
'product_id': item.line_id.product_id.id,
|
"customer_rma_id": item.line_id.id,
|
||||||
'customer_rma_id': item.line_id.id,
|
"product_qty": item.product_qty,
|
||||||
'product_qty': item.product_qty,
|
"rma_id": rma.id if rma else False,
|
||||||
'rma_id': rma.id if rma else False,
|
"uom_id": item.line_id.uom_id.id,
|
||||||
'uom_id': item.line_id.uom_id.id,
|
"operation_id": operation.id,
|
||||||
'operation_id': operation.id,
|
"receipt_policy": operation.receipt_policy,
|
||||||
'receipt_policy': operation.receipt_policy,
|
"delivery_policy": operation.delivery_policy,
|
||||||
'delivery_policy': operation.delivery_policy,
|
"supplier_to_customer": operation.supplier_to_customer,
|
||||||
'supplier_to_customer': operation.supplier_to_customer,
|
"in_warehouse_id": operation.in_warehouse_id.id or warehouse.id,
|
||||||
'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id,
|
"out_warehouse_id": operation.out_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,
|
||||||
'in_route_id': operation.in_route_id.id or route.id,
|
"out_route_id": operation.out_route_id.id or route.id,
|
||||||
'out_route_id': operation.out_route_id.id or route.id,
|
"location_id": (
|
||||||
'location_id': (operation.location_id.id or
|
operation.location_id.id
|
||||||
operation.in_warehouse_id.lot_rma_id.id or
|
or operation.in_warehouse_id.lot_rma_id.id
|
||||||
warehouse.lot_rma_id.id)
|
or warehouse.lot_rma_id.id
|
||||||
|
),
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def make_supplier_rma(self):
|
def make_supplier_rma(self):
|
||||||
self = self.with_context(supplier=True, customer=False)
|
self = self.with_context(supplier=True, customer=False)
|
||||||
rma_obj = self.env['rma.order']
|
rma_obj = self.env["rma.order"]
|
||||||
rma_line_obj = self.env['rma.order.line']
|
rma_line_obj = self.env["rma.order.line"]
|
||||||
rma = False
|
rma = 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 ValidationError(
|
raise ValidationError(_("Enter a positive quantity."))
|
||||||
_('Enter a positive quantity.'))
|
|
||||||
|
|
||||||
if self.supplier_rma_id:
|
if self.supplier_rma_id:
|
||||||
rma = self.supplier_rma_id
|
rma = self.supplier_rma_id
|
||||||
@@ -150,25 +164,25 @@ class RmaLineMakeSupplierRma(models.TransientModel):
|
|||||||
rma_line = rma_line_obj.create(rma_line_data)
|
rma_line = rma_line_obj.create(rma_line_data)
|
||||||
if rma:
|
if rma:
|
||||||
return {
|
return {
|
||||||
'name': _('Supplier RMA'),
|
"name": _("Supplier RMA"),
|
||||||
'view_type': 'form',
|
"view_type": "form",
|
||||||
'view_mode': 'form',
|
"view_mode": "form",
|
||||||
'res_model': 'rma.order',
|
"res_model": "rma.order",
|
||||||
'view_id': False,
|
"view_id": False,
|
||||||
'res_id': rma.id,
|
"res_id": rma.id,
|
||||||
'context': {'supplier': True, 'customer': False},
|
"context": {"supplier": True, "customer": False},
|
||||||
'type': 'ir.actions.act_window'
|
"type": "ir.actions.act_window",
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
'name': _('Supplier RMA Line'),
|
"name": _("Supplier RMA Line"),
|
||||||
'view_type': 'form',
|
"view_type": "form",
|
||||||
'view_mode': 'form',
|
"view_mode": "form",
|
||||||
'res_model': 'rma.order.line',
|
"res_model": "rma.order.line",
|
||||||
'view_id': False,
|
"view_id": False,
|
||||||
'res_id': rma_line.id,
|
"res_id": rma_line.id,
|
||||||
'context': {'supplier': True, 'customer': False},
|
"context": {"supplier": True, "customer": False},
|
||||||
'type': 'ir.actions.act_window'
|
"type": "ir.actions.act_window",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,22 +191,28 @@ class RmaLineMakeRmaOrderItem(models.TransientModel):
|
|||||||
_description = "RMA Line Make Supplier RMA Item"
|
_description = "RMA Line Make Supplier RMA Item"
|
||||||
|
|
||||||
wiz_id = fields.Many2one(
|
wiz_id = fields.Many2one(
|
||||||
'rma.order.line.make.supplier.rma',
|
"rma.order.line.make.supplier.rma",
|
||||||
string='Wizard', required=True, ondelete='cascade',
|
string="Wizard",
|
||||||
readonly=True)
|
|
||||||
line_id = fields.Many2one('rma.order.line',
|
|
||||||
string='RMA Line',
|
|
||||||
required=True,
|
required=True,
|
||||||
ondelete='cascade')
|
ondelete="cascade",
|
||||||
rma_id = fields.Many2one('rma.order', related='line_id.rma_id',
|
readonly=True,
|
||||||
string='RMA Order', readonly=True)
|
)
|
||||||
product_id = fields.Many2one('product.product',
|
line_id = fields.Many2one(
|
||||||
related='line_id.product_id', readony=True)
|
"rma.order.line", string="RMA Line", required=True, ondelete="cascade"
|
||||||
name = fields.Char(related='line_id.name', readonly=True)
|
)
|
||||||
uom_id = fields.Many2one('uom.uom', string='UoM', readonly=True)
|
rma_id = fields.Many2one(
|
||||||
product_qty = fields.Float(string='Quantity',
|
"rma.order", related="line_id.rma_id", string="RMA Order", readonly=True
|
||||||
digits=dp.get_precision('Product UoS'))
|
)
|
||||||
operation_id = fields.Many2one(
|
product_id = fields.Many2one(
|
||||||
comodel_name="rma.operation", string="Operation",
|
"product.product", related="line_id.product_id", readony=True
|
||||||
domain=[('type', '=', 'supplier')],
|
)
|
||||||
|
name = fields.Char(related="line_id.name", readonly=True)
|
||||||
|
uom_id = fields.Many2one("uom.uom", string="UoM", readonly=True)
|
||||||
|
product_qty = fields.Float(
|
||||||
|
string="Quantity", digits=dp.get_precision("Product UoS")
|
||||||
|
)
|
||||||
|
operation_id = fields.Many2one(
|
||||||
|
comodel_name="rma.operation",
|
||||||
|
string="Operation",
|
||||||
|
domain=[("type", "=", "supplier")],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,23 +1,31 @@
|
|||||||
# Copyright (C) 2017 Eficent Business and IT Consulting Services S.L.
|
# Copyright (C) 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 models, fields
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class StockConfigSettings(models.TransientModel):
|
class StockConfigSettings(models.TransientModel):
|
||||||
_inherit = 'res.config.settings'
|
_inherit = "res.config.settings"
|
||||||
|
|
||||||
group_rma_delivery_address = fields.Selection([
|
group_rma_delivery_address = fields.Selection(
|
||||||
(0, "Invoicing and shipping addresses are always the same "
|
[
|
||||||
"(Example: services companies)"),
|
(
|
||||||
(1, 'Display 3 fields on rma: partner, invoice address, delivery '
|
0,
|
||||||
'address')
|
"Invoicing and shipping addresses are always the same "
|
||||||
], "Addresses",
|
"(Example: services companies)",
|
||||||
implied_group='rma.group_rma_delivery_invoice_address')
|
),
|
||||||
|
(
|
||||||
group_rma_lines = fields.Selection([
|
1,
|
||||||
(0, "Do not group RMA lines"),
|
"Display 3 fields on rma: partner, invoice address, delivery "
|
||||||
(1, 'Group RMA lines in one RMA group')
|
"address",
|
||||||
], "Grouping",
|
),
|
||||||
implied_group='rma.group_rma_groups',
|
],
|
||||||
|
"Addresses",
|
||||||
|
implied_group="rma.group_rma_delivery_invoice_address",
|
||||||
|
)
|
||||||
|
|
||||||
|
group_rma_lines = fields.Selection(
|
||||||
|
[(0, "Do not group RMA lines"), (1, "Group RMA lines in one RMA group")],
|
||||||
|
"Grouping",
|
||||||
|
implied_group="rma.group_rma_groups",
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user