[IMP] rma_sale: black, isort, prettier

This commit is contained in:
Ernesto Tejeda
2020-10-28 15:32:43 -04:00
committed by Chafique
parent 612b8b8923
commit 0cbca17df5
13 changed files with 415 additions and 324 deletions

View File

@@ -10,10 +10,7 @@
"author": "Tecnativa, Odoo Community Association (OCA)", "author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["ernestotejeda"], "maintainers": ["ernestotejeda"],
"license": "AGPL-3", "license": "AGPL-3",
"depends": [ "depends": ["rma", "sale_stock",],
"rma",
"sale_stock",
],
"data": [ "data": [
"views/assets.xml", "views/assets.xml",
"views/report_rma.xml", "views/report_rma.xml",

View File

@@ -5,9 +5,8 @@ from odoo.addons.rma.controllers.main import PortalRma
class PortalRma(PortalRma): class PortalRma(PortalRma):
def _get_filter_domain(self, kw): def _get_filter_domain(self, kw):
res = super()._get_filter_domain(kw) res = super()._get_filter_domain(kw)
if 'sale_id' in kw: if "sale_id" in kw:
res.append(('order_id', '=', int(kw['sale_id']))) res.append(("order_id", "=", int(kw["sale_id"])))
return res return res

View File

@@ -1,42 +1,48 @@
# Copyright 2020 Tecnativa - Ernesto Tejeda # Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import http, _ from odoo import _, http
from odoo.exceptions import AccessError, MissingError from odoo.exceptions import AccessError, MissingError
from odoo.http import request from odoo.http import request
from odoo.addons.sale.controllers.portal import CustomerPortal from odoo.addons.sale.controllers.portal import CustomerPortal
class CustomerPortal(CustomerPortal): class CustomerPortal(CustomerPortal):
@http.route(['/my/orders/<int:order_id>/requestrma'], type='http', @http.route(
auth="public", methods=['POST'], website=True) ["/my/orders/<int:order_id>/requestrma"],
type="http",
auth="public",
methods=["POST"],
website=True,
)
def request_rma(self, order_id, access_token=None, **post): def request_rma(self, order_id, access_token=None, **post):
try: try:
order_sudo = self._document_check_access('sale.order', order_id, order_sudo = self._document_check_access(
access_token=access_token) "sale.order", order_id, access_token=access_token
)
except (AccessError, MissingError): except (AccessError, MissingError):
return request.redirect('/my') return request.redirect("/my")
order_obj = request.env['sale.order'] order_obj = request.env["sale.order"]
wizard_obj = request.env['sale.order.rma.wizard'] wizard_obj = request.env["sale.order.rma.wizard"]
# Set wizard line vals # Set wizard line vals
mapped_vals = {} mapped_vals = {}
for name, value in post.items(): for name, value in post.items():
row, field_name = name.split('-', 1) row, field_name = name.split("-", 1)
mapped_vals.setdefault(row, {}).update({field_name: value}) mapped_vals.setdefault(row, {}).update({field_name: value})
# If no operation is filled, no RMA will be created # If no operation is filled, no RMA will be created
line_vals = [ line_vals = [
(0, 0, vals) for vals in mapped_vals.values() (0, 0, vals) for vals in mapped_vals.values() if vals.get("operation_id")
if vals.get("operation_id")] ]
# Create wizard an generate rmas # Create wizard an generate rmas
order = order_obj.browse(order_id).sudo() order = order_obj.browse(order_id).sudo()
location_id = order.warehouse_id.rma_loc_id.id location_id = order.warehouse_id.rma_loc_id.id
wizard = wizard_obj.with_context(active_id=order_id).create({ wizard = wizard_obj.with_context(active_id=order_id).create(
'line_ids': line_vals, {"line_ids": line_vals, "location_id": location_id}
'location_id': location_id )
})
rma = wizard.sudo().create_rma() rma = wizard.sudo().create_rma()
for rec in rma: for rec in rma:
rec.origin += _(' (Portal)') rec.origin += _(" (Portal)")
# Add the user as follower of the created RMAs so they can # Add the user as follower of the created RMAs so they can
# later view them. # later view them.
rma.message_subscribe([request.env.user.partner_id.id]) rma.message_subscribe([request.env.user.partner_id.id])

View File

@@ -8,69 +8,64 @@ class Rma(models.Model):
_inherit = "rma" _inherit = "rma"
order_id = fields.Many2one( order_id = fields.Many2one(
comodel_name='sale.order', comodel_name="sale.order",
string='Sale Order', string="Sale Order",
domain="[" domain="["
" ('partner_id', 'child_of', commercial_partner_id)," " ('partner_id', 'child_of', commercial_partner_id),"
" ('state', 'in', ['sale', 'done'])," " ('state', 'in', ['sale', 'done']),"
"]", "]",
readonly=True, readonly=True,
states={'draft': [('readonly', False)]}, states={"draft": [("readonly", False)]},
) )
allowed_picking_ids = fields.Many2many( allowed_picking_ids = fields.Many2many(
comodel_name='stock.picking', comodel_name="stock.picking", compute="_compute_allowed_picking_ids",
compute="_compute_allowed_picking_ids",
)
picking_id = fields.Many2one(
domain="[('id', 'in', allowed_picking_ids)]",
) )
picking_id = fields.Many2one(domain="[('id', 'in', allowed_picking_ids)]",)
allowed_move_ids = fields.Many2many( allowed_move_ids = fields.Many2many(
comodel_name='sale.order.line', comodel_name="sale.order.line", compute="_compute_allowed_move_ids",
compute="_compute_allowed_move_ids",
)
move_id = fields.Many2one(
domain="[('id', 'in', allowed_move_ids)]",
) )
move_id = fields.Many2one(domain="[('id', 'in', allowed_move_ids)]",)
allowed_product_ids = fields.Many2many( allowed_product_ids = fields.Many2many(
comodel_name='product.product', comodel_name="product.product", compute="_compute_allowed_product_ids",
compute="_compute_allowed_product_ids",
)
product_id = fields.Many2one(
domain="[('id', 'in', allowed_product_ids)]",
) )
product_id = fields.Many2one(domain="[('id', 'in', allowed_product_ids)]",)
@api.depends('partner_id', 'order_id') @api.depends("partner_id", "order_id")
def _compute_allowed_picking_ids(self): def _compute_allowed_picking_ids(self):
domain = [('state', '=', 'done'), domain = [("state", "=", "done"), ("picking_type_id.code", "=", "outgoing")]
('picking_type_id.code', '=', 'outgoing')]
for rec in self: for rec in self:
# if rec.partner_id: # if rec.partner_id:
commercial_partner = rec.partner_id.commercial_partner_id commercial_partner = rec.partner_id.commercial_partner_id
domain.append(('partner_id', 'child_of', commercial_partner.id)) domain.append(("partner_id", "child_of", commercial_partner.id))
if rec.order_id: if rec.order_id:
domain.append(('sale_id', '=', rec.order_id.id)) domain.append(("sale_id", "=", rec.order_id.id))
rec.allowed_picking_ids = self.env['stock.picking'].search(domain) rec.allowed_picking_ids = self.env["stock.picking"].search(domain)
@api.depends('order_id', 'picking_id') @api.depends("order_id", "picking_id")
def _compute_allowed_move_ids(self): def _compute_allowed_move_ids(self):
for rec in self: for rec in self:
if rec.order_id: if rec.order_id:
order_move = rec.order_id.order_line.mapped('move_ids') order_move = rec.order_id.order_line.mapped("move_ids")
rec.allowed_move_ids = order_move.filtered( rec.allowed_move_ids = order_move.filtered(
lambda r: r.picking_id == self.picking_id).ids lambda r: r.picking_id == self.picking_id
).ids
else: else:
rec.allowed_move_ids = self.picking_id.move_lines.ids rec.allowed_move_ids = self.picking_id.move_lines.ids
@api.depends('order_id') @api.depends("order_id")
def _compute_allowed_product_ids(self): def _compute_allowed_product_ids(self):
for rec in self: for rec in self:
if rec.order_id: if rec.order_id:
order_product = rec.order_id.order_line.mapped('product_id') order_product = rec.order_id.order_line.mapped("product_id")
rec.allowed_product_ids = order_product.filtered( rec.allowed_product_ids = order_product.filtered(
lambda r: r.type in ['consu', 'product']).ids lambda r: r.type in ["consu", "product"]
).ids
else: else:
rec.allowed_product_ids = self.env['product.product'].search( rec.allowed_product_ids = (
[('type', 'in', ['consu', 'product'])]).ids self.env["product.product"]
.search([("type", "in", ["consu", "product"])])
.ids
)
@api.onchange("partner_id") @api.onchange("partner_id")
def _onchange_partner_id(self): def _onchange_partner_id(self):
@@ -78,7 +73,7 @@ class Rma(models.Model):
self.order_id = False self.order_id = False
return res return res
@api.onchange('order_id') @api.onchange("order_id")
def _onchange_order_id(self): def _onchange_order_id(self):
self.product_id = self.picking_id = False self.product_id = self.picking_id = False

View File

@@ -10,64 +10,63 @@ class SaleOrder(models.Model):
# RMAs that were created from a sale order # RMAs that were created from a sale order
rma_ids = fields.One2many( rma_ids = fields.One2many(
comodel_name='rma', comodel_name="rma", inverse_name="order_id", string="RMAs", copy=False,
inverse_name='order_id',
string='RMAs',
copy=False,
)
rma_count = fields.Integer(
string='RMA count',
compute='_compute_rma_count',
) )
rma_count = fields.Integer(string="RMA count", compute="_compute_rma_count",)
def _compute_rma_count(self): def _compute_rma_count(self):
rma_data = self.env['rma'].read_group( rma_data = self.env["rma"].read_group(
[('order_id', 'in', self.ids)], ['order_id'], ['order_id']) [("order_id", "in", self.ids)], ["order_id"], ["order_id"]
mapped_data = dict( )
[(r['order_id'][0], r['order_id_count']) for r in rma_data]) mapped_data = {r["order_id"][0]: r["order_id_count"] for r in rma_data}
for record in self: for record in self:
record.rma_count = mapped_data.get(record.id, 0) record.rma_count = mapped_data.get(record.id, 0)
def action_create_rma(self): def action_create_rma(self):
self.ensure_one() self.ensure_one()
if self.state not in ['sale', 'done']: if self.state not in ["sale", "done"]:
raise ValidationError(_("You may only create RMAs from a " raise ValidationError(
"confirmed or done sale order.")) _("You may only create RMAs from a " "confirmed or done sale order.")
wizard_obj = self.env['sale.order.rma.wizard'] )
line_vals = [(0, 0, { wizard_obj = self.env["sale.order.rma.wizard"]
'product_id': data['product'].id, line_vals = [
'quantity': data['quantity'], (
'uom_id': data['uom'].id, 0,
'picking_id': data['picking'] and data['picking'].id, 0,
}) for data in self.get_delivery_rma_data()] {
wizard = wizard_obj.with_context(active_id=self.id).create({ "product_id": data["product"].id,
'line_ids': line_vals, "quantity": data["quantity"],
'location_id': self.warehouse_id.rma_loc_id.id "uom_id": data["uom"].id,
}) "picking_id": data["picking"] and data["picking"].id,
},
)
for data in self.get_delivery_rma_data()
]
wizard = wizard_obj.with_context(active_id=self.id).create(
{"line_ids": line_vals, "location_id": self.warehouse_id.rma_loc_id.id}
)
return { return {
'name': _('Create RMA'), "name": _("Create RMA"),
'type': 'ir.actions.act_window', "type": "ir.actions.act_window",
'view_type': 'form', "view_type": "form",
'view_mode': 'form', "view_mode": "form",
'res_model': 'sale.order.rma.wizard', "res_model": "sale.order.rma.wizard",
'res_id': wizard.id, "res_id": wizard.id,
'target': 'new', "target": "new",
} }
def action_view_rma(self): def action_view_rma(self):
self.ensure_one() self.ensure_one()
action = self.env.ref('rma.rma_action').read()[0] action = self.env.ref("rma.rma_action").read()[0]
rma = self.rma_ids rma = self.rma_ids
if len(rma) == 1: if len(rma) == 1:
action.update( action.update(
res_id=rma.id, res_id=rma.id, view_mode="form", views=[],
view_mode="form",
views=[],
) )
else: else:
action['domain'] = [('id', 'in', rma.ids)] action["domain"] = [("id", "in", rma.ids)]
# reset context to show all related rma without default filters # reset context to show all related rma without default filters
action['context'] = {} action["context"] = {}
return action return action
def get_delivery_rma_data(self): def get_delivery_rma_data(self):
@@ -83,19 +82,23 @@ class SaleOrderLine(models.Model):
def get_delivery_move(self): def get_delivery_move(self):
self.ensure_one() self.ensure_one()
return self.move_ids.filtered(lambda r: ( return self.move_ids.filtered(
self.product_id == r.product_id lambda r: (
and r.state == 'done' self.product_id == r.product_id
and not r.scrapped and r.state == "done"
and r.location_dest_id.usage == "customer" and not r.scrapped
and (not r.origin_returned_move_id and r.location_dest_id.usage == "customer"
or (r.origin_returned_move_id and r.to_refund)) and (
)) not r.origin_returned_move_id
or (r.origin_returned_move_id and r.to_refund)
)
)
)
def prepare_sale_rma_data(self): def prepare_sale_rma_data(self):
self.ensure_one() self.ensure_one()
product = self.product_id product = self.product_id
if self.product_id.type != 'product': if self.product_id.type != "product":
return {} return {}
moves = self.get_delivery_move() moves = self.get_delivery_move()
data = [] data = []
@@ -103,20 +106,24 @@ class SaleOrderLine(models.Model):
for move in moves: for move in moves:
qty = move.product_uom_qty qty = move.product_uom_qty
move_dest = move.move_dest_ids.filtered( move_dest = move.move_dest_ids.filtered(
lambda r: r.state in ['partially_available', lambda r: r.state in ["partially_available", "assigned", "done"]
'assigned', 'done']) )
qty -= sum(move_dest.mapped('product_uom_qty')) qty -= sum(move_dest.mapped("product_uom_qty"))
data.append({ data.append(
'product': product, {
'quantity': qty, "product": product,
'uom': move.product_uom, "quantity": qty,
'picking': move.picking_id, "uom": move.product_uom,
}) "picking": move.picking_id,
}
)
else: else:
data.append({ data.append(
'product': product, {
'quantity': self.qty_delivered, "product": product,
'uom': self.product_uom, "quantity": self.qty_delivered,
'picking': False, "uom": self.product_uom,
}) "picking": False,
}
)
return data return data

View File

@@ -8,21 +8,17 @@ class TestRmaSale(SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(TestRmaSale, cls).setUpClass() super(TestRmaSale, cls).setUpClass()
cls.res_partner = cls.env['res.partner'] cls.res_partner = cls.env["res.partner"]
cls.product_product = cls.env['product.product'] cls.product_product = cls.env["product.product"]
cls.sale_order = cls.env['sale.order'] cls.sale_order = cls.env["sale.order"]
cls.product_1 = cls.product_product.create({ cls.product_1 = cls.product_product.create(
'name': 'Product test 1', {"name": "Product test 1", "type": "product",}
'type': 'product', )
}) cls.product_2 = cls.product_product.create(
cls.product_2 = cls.product_product.create({ {"name": "Product test 2", "type": "product",}
'name': 'Product test 2', )
'type': 'product', cls.partner = cls.res_partner.create({"name": "Partner test",})
})
cls.partner = cls.res_partner.create({
'name': 'Partner test',
})
order_form = Form(cls.sale_order) order_form = Form(cls.sale_order)
order_form.partner_id = cls.partner order_form.partner_id = cls.partner
with order_form.order_line.new() as line_form: with order_form.order_line.new() as line_form:
@@ -33,13 +29,14 @@ class TestRmaSale(SavepointCase):
# Maybe other modules create additional lines in the create # Maybe other modules create additional lines in the create
# method in sale.order model, so let's find the correct line. # method in sale.order model, so let's find the correct line.
cls.order_line = cls.sale_order.order_line.filtered( cls.order_line = cls.sale_order.order_line.filtered(
lambda r: r.product_id == cls.product_1) lambda r: r.product_id == cls.product_1
)
cls.order_out_picking = cls.sale_order.picking_ids cls.order_out_picking = cls.sale_order.picking_ids
cls.order_out_picking.move_lines.quantity_done = 5 cls.order_out_picking.move_lines.quantity_done = 5
cls.order_out_picking.button_validate() cls.order_out_picking.button_validate()
def test_create_rma_with_so(self): def test_create_rma_with_so(self):
rma_form = Form(self.env['rma']) rma_form = Form(self.env["rma"])
rma_form.partner_id = self.partner rma_form.partner_id = self.partner
rma_form.order_id = self.sale_order rma_form.order_id = self.sale_order
rma_form.product_id = self.product_1 rma_form.product_id = self.product_1
@@ -51,9 +48,9 @@ class TestRmaSale(SavepointCase):
def test_create_rma_from_so(self): def test_create_rma_from_so(self):
order = self.sale_order order = self.sale_order
wizard_id = order.action_create_rma()['res_id'] wizard_id = order.action_create_rma()["res_id"]
wizard = self.env['sale.order.rma.wizard'].browse(wizard_id) wizard = self.env["sale.order.rma.wizard"].browse(wizard_id)
rma = self.env['rma'].browse(wizard.create_and_open_rma()['res_id']) rma = self.env["rma"].browse(wizard.create_and_open_rma()["res_id"])
self.assertEqual(rma.partner_id, order.partner_id) self.assertEqual(rma.partner_id, order.partner_id)
self.assertEqual(rma.order_id, order) self.assertEqual(rma.order_id, order)
self.assertEqual(rma.picking_id, self.order_out_picking) self.assertEqual(rma.picking_id, self.order_out_picking)
@@ -61,7 +58,7 @@ class TestRmaSale(SavepointCase):
self.assertEqual(rma.product_id, self.product_1) self.assertEqual(rma.product_id, self.product_1)
self.assertEqual(rma.product_uom_qty, self.order_line.product_uom_qty) self.assertEqual(rma.product_uom_qty, self.order_line.product_uom_qty)
self.assertEqual(rma.product_uom, self.order_line.product_uom) self.assertEqual(rma.product_uom, self.order_line.product_uom)
self.assertEqual(rma.state, 'confirmed') self.assertEqual(rma.state, "confirmed")
self.assertEqual( self.assertEqual(
rma.reception_move_id.origin_returned_move_id, rma.reception_move_id.origin_returned_move_id,
self.order_out_picking.move_lines, self.order_out_picking.move_lines,
@@ -72,10 +69,7 @@ class TestRmaSale(SavepointCase):
) )
# Refund the RMA # Refund the RMA
user = self.env["res.users"].create( user = self.env["res.users"].create(
{ {"login": "test_refund_with_so", "name": "Test",}
"login": "test_refund_with_so",
"name": "Test",
}
) )
order.user_id = user.id order.user_id = user.id
rma.action_confirm() rma.action_confirm()

View File

@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<template id="assets_frontend" inherit_id="web.assets_frontend" name="Request RMA"> <template id="assets_frontend" inherit_id="web.assets_frontend" name="Request RMA">
<xpath expr="//link[last()]" position="after"> <xpath expr="//link[last()]" position="after">
<link rel="stylesheet" type="text/scss" href="/rma_sale/static/src/scss/rma_sale.scss"/> <link
rel="stylesheet"
type="text/scss"
href="/rma_sale/static/src/scss/rma_sale.scss"
/>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>

View File

@@ -4,13 +4,13 @@
<xpath expr="//div[@t-if='doc.picking_id']" position="before"> <xpath expr="//div[@t-if='doc.picking_id']" position="before">
<div t-if="doc.order_id" class="col-auto mw-100 mb-2"> <div t-if="doc.order_id" class="col-auto mw-100 mb-2">
<strong>Sale order:</strong> <strong>Sale order:</strong>
<p class="m-0" t-field="doc.order_id"/> <p class="m-0" t-field="doc.order_id" />
</div> </div>
</xpath> </xpath>
<xpath expr="//div[@t-if='doc.user_id']" position="before"> <xpath expr="//div[@t-if='doc.user_id']" position="before">
<div t-if="doc.operation_id" class="col-auto mw-100 mb-2"> <div t-if="doc.operation_id" class="col-auto mw-100 mb-2">
<strong>Requested operation:</strong> <strong>Requested operation:</strong>
<p class="m-0" t-field="doc.operation_id"/> <p class="m-0" t-field="doc.operation_id" />
</div> </div>
</xpath> </xpath>
</template> </template>

View File

@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2020 Tecnativa - Ernesto Tejeda <!-- Copyright 2020 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo> <odoo>
<record id="rma_view_form" model="ir.ui.view"> <record id="rma_view_form" model="ir.ui.view">
<field name="name">rma.view.form</field> <field name="name">rma.view.form</field>
<field name="model">rma</field> <field name="model">rma</field>
<field name="inherit_id" ref="rma.rma_view_form"/> <field name="inherit_id" ref="rma.rma_view_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="partner_invoice_id" position="after"> <field name="partner_invoice_id" position="after">
<field name="order_id" options="{'no_create': True}"/> <field name="order_id" options="{'no_create': True}" />
</field> </field>
<sheet> <sheet>
<field name="allowed_picking_ids" invisible="1"/> <field name="allowed_picking_ids" invisible="1" />
<field name="allowed_move_ids" invisible="1"/> <field name="allowed_move_ids" invisible="1" />
<field name="allowed_product_ids" invisible="1"/> <field name="allowed_product_ids" invisible="1" />
</sheet> </sheet>
</field> </field>
</record> </record>

View File

@@ -1,37 +1,80 @@
<odoo> <odoo>
<template id="sale_order_portal_template" name="Request RMA" inherit_id="sale.sale_order_portal_template"> <template
<xpath expr="//div[hasclass('o_portal_sale_sidebar')]//div[hasclass('o_download_pdf')]/.." position="after"> id="sale_order_portal_template"
<li t-if="sale_order.state in ['sale', 'done']" class="list-group-item flex-grow-1" id="li-request-rma"> name="Request RMA"
<a role="button" class="btn btn-secondary btn-block mb8" data-toggle="modal" data-target="#modal-request-rma" href="#"> inherit_id="sale.sale_order_portal_template"
<i class="fa fa-reply"/> Request RMAs >
<xpath
expr="//div[hasclass('o_portal_sale_sidebar')]//div[hasclass('o_download_pdf')]/.."
position="after"
>
<li
t-if="sale_order.state in ['sale', 'done']"
class="list-group-item flex-grow-1"
id="li-request-rma"
>
<a
role="button"
class="btn btn-secondary btn-block mb8"
data-toggle="modal"
data-target="#modal-request-rma"
href="#"
>
<i class="fa fa-reply" /> Request RMAs
</a> </a>
</li> </li>
</xpath> </xpath>
<xpath expr="//div[@id='modaldecline']" position="after"> <xpath expr="//div[@id='modaldecline']" position="after">
<div role="dialog" class="modal fade" id="modal-request-rma"> <div role="dialog" class="modal fade" id="modal-request-rma">
<div class="modal-dialog" style="max-width: 1000px;"> <div class="modal-dialog" style="max-width: 1000px;">
<form id="form-request-rma" method="POST" t-attf-action="/my/orders/#{sale_order.id}/requestrma?access_token=#{sale_order.access_token}" class="modal-content"> <form
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/> id="form-request-rma"
method="POST"
t-attf-action="/my/orders/#{sale_order.id}/requestrma?access_token=#{sale_order.access_token}"
class="modal-content"
>
<input
type="hidden"
name="csrf_token"
t-att-value="request.csrf_token()"
/>
<header class="modal-header"> <header class="modal-header">
<h4 class="modal-title">Request RMAs</h4> <h4 class="modal-title">Request RMAs</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">&amp;times;</button> <button
type="button"
class="close"
data-dismiss="modal"
aria-label="Close"
>&amp;times;</button>
</header> </header>
<main class="modal-body" id="modal-body-request-rma"> <main class="modal-body" id="modal-body-request-rma">
<div class="alert alert-info mb-2 mb-sm-1" role="alert"> <div class="alert alert-info mb-2 mb-sm-1" role="alert">
<span> <span>
You're about to perform an RMA request. Our team will process it an will reach you once it's validated. Keep in mind that: You're about to perform an RMA request. Our team will process it an will reach you once it's validated. Keep in mind that:
<ul> <ul>
<li>Select the product quantity and the requested operation</li> <li
<li>Use the comment button to add relevant information regarding the RMA, like returned serial numbers or a description of the issue</li> >Select the product quantity and the requested operation</li>
<li>If no requested operation is set, the RMA won't be correctly fulfilled</li> <li
<li>You can only return as much product units as you received for this order</li> >Use the comment button to add relevant information regarding the RMA, like returned serial numbers or a description of the issue</li>
<li>The limit will decrease when the units in other RMAs are confirmed</li> <li
<li>You can send a message in every RMA sent</li> >If no requested operation is set, the RMA won't be correctly fulfilled</li>
</ul> <li
>You can only return as much product units as you received for this order</li>
<li
>The limit will decrease when the units in other RMAs are confirmed</li>
<li
>You can send a message in every RMA sent</li>
</ul>
</span> </span>
</div> </div>
<t t-set="data_list" t-value="sale_order.get_delivery_rma_data()"/> <t
<t t-set="operations" t-value="sale_order.env['rma.operation'].search([])"/> t-set="data_list"
t-value="sale_order.get_delivery_rma_data()"
/>
<t
t-set="operations"
t-value="sale_order.env['rma.operation'].search([])"
/>
<table class="table table-sm" id="request-rma-table"> <table class="table table-sm" id="request-rma-table">
<thead class="bg-100"> <thead class="bg-100">
<tr> <tr>
@@ -47,40 +90,65 @@
<t t-if="data['quantity'] > 0"> <t t-if="data['quantity'] > 0">
<tr> <tr>
<td class="text-left"> <td class="text-left">
<span t-esc="data['product'].display_name"/> <span
<input type="hidden" t-esc="data['product'].display_name"
t-attf-name="#{data_index}-product_id" />
t-att-value="data['product'].id"/> <input
type="hidden"
t-attf-name="#{data_index}-product_id"
t-att-value="data['product'].id"
/>
</td> </td>
<td class="text-right"> <td class="text-right">
<div id="delivery-rma-qty"> <div id="delivery-rma-qty">
<input type="number" <input
t-attf-name="#{data_index}-quantity" type="number"
class="o_input text-right" t-attf-name="#{data_index}-quantity"
placeholder="0" class="o_input text-right"
min="0" placeholder="0"
t-att-max="data['quantity']" min="0"
t-att-value="0" t-att-max="data['quantity']"
style="max-width: 60px;"/> t-att-value="0"
<span t-esc="data['uom'].name" groups="uom.group_uom"/> style="max-width: 60px;"
<input type="hidden" />
t-attf-name="#{data_index}-uom_id" <span
t-att-value="data['uom'].id"/> t-esc="data['uom'].name"
groups="uom.group_uom"
/>
<input
type="hidden"
t-attf-name="#{data_index}-uom_id"
t-att-value="data['uom'].id"
/>
</div> </div>
</td> </td>
<td class="text-left"> <td class="text-left">
<span t-if="data['picking']" t-esc="data['picking'].name"/> <span
<input type="hidden" t-if="data['picking']"
t-attf-name="#{data_index}-picking_id" t-esc="data['picking'].name"
t-att-value="data['picking'].id"/> />
<input
type="hidden"
t-attf-name="#{data_index}-picking_id"
t-att-value="data['picking'].id"
/>
</td> </td>
<td class="text-left"> <td class="text-left">
<select t-attf-name="#{data_index}-operation_id" <select
class="form-control"> t-attf-name="#{data_index}-operation_id"
class="form-control"
>
<option value="">---</option> <option value="">---</option>
<t t-foreach="operations" t-as="operation"> <t
<option t-att-value="operation.id"> t-foreach="operations"
<t t-esc="operation.name" /> t-as="operation"
>
<option
t-att-value="operation.id"
>
<t
t-esc="operation.name"
/>
</option> </option>
</t> </t>
</select> </select>
@@ -88,13 +156,18 @@
<td> <td>
<button <button
class="btn btn-primary fa fa-comments" class="btn btn-primary fa fa-comments"
type="button" data-toggle="collapse" type="button"
data-toggle="collapse"
t-attf-data-target="#comment-#{data_index}" t-attf-data-target="#comment-#{data_index}"
aria-expanded="false" aria-expanded="false"
t-attf-aria-controls="comment-#{data_index}" /> t-attf-aria-controls="comment-#{data_index}"
/>
</td> </td>
</tr> </tr>
<tr class="collapse" t-attf-id="comment-#{data_index}"> <tr
class="collapse"
t-attf-id="comment-#{data_index}"
>
<td colspan="5"> <td colspan="5">
<textarea <textarea
class="form-control o_website_form_input" class="form-control o_website_form_input"
@@ -109,19 +182,35 @@
</table> </table>
</main> </main>
<footer class="modal-footer"> <footer class="modal-footer">
<button type="submit" t-att-id="sale_order.id" class="btn btn-primary"><i class="fa fa-check"></i> Request RMAs</button> <button
<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-times"></i> Cancel</button> type="submit"
t-att-id="sale_order.id"
class="btn btn-primary"
><i class="fa fa-check" /> Request RMAs</button>
<button
type="button"
class="btn btn-danger"
data-dismiss="modal"
><i class="fa fa-times" /> Cancel</button>
</footer> </footer>
</form> </form>
</div> </div>
</div> </div>
</xpath> </xpath>
</template> </template>
<template id="sale_order_portal_content" name="Show RMAs" inherit_id="sale.sale_order_portal_content"> <template
id="sale_order_portal_content"
name="Show RMAs"
inherit_id="sale.sale_order_portal_content"
>
<xpath expr="//div[@id='introduction']/h2[hasclass('my-0')]" position="inside"> <xpath expr="//div[@id='introduction']/h2[hasclass('my-0')]" position="inside">
<span t-if="sale_order.rma_count" class="float-right"> <span t-if="sale_order.rma_count" class="float-right">
<a role="button" t-attf-href="/my/rmas?sale_id=#{sale_order.id}" class="btn btn-sm btn-secondary"> <a
<span class="fa fa-reply" role="img" aria-label="RMA" title="RMA"/> role="button"
t-attf-href="/my/rmas?sale_id=#{sale_order.id}"
class="btn btn-sm btn-secondary"
>
<span class="fa fa-reply" role="img" aria-label="RMA" title="RMA" />
<span t-esc="sale_order.rma_count" /> <span t-esc="sale_order.rma_count" />
<span>RMA</span> <span>RMA</span>
</a> </a>
@@ -135,7 +224,7 @@
<strong>Sale order</strong> <strong>Sale order</strong>
</div> </div>
<div class="col-12 col-sm-8"> <div class="col-12 col-sm-8">
<span t-field="rma.order_id"/> <span t-field="rma.order_id" />
</div> </div>
</div> </div>
</xpath> </xpath>
@@ -145,7 +234,7 @@
<strong>Requested operation</strong> <strong>Requested operation</strong>
</div> </div>
<div class="col-12 col-sm-8"> <div class="col-12 col-sm-8">
<span t-field="rma.operation_id"/> <span t-field="rma.operation_id" />
</div> </div>
</div> </div>
</xpath> </xpath>

View File

@@ -1,26 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="view_order_form" model="ir.ui.view"> <record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field> <field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field> <field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/> <field name="inherit_id" ref="sale.view_order_form" />
<field name="groups_id" eval="[(4, ref('rma.rma_group_user_own'))]"/> <field name="groups_id" eval="[(4, ref('rma.rma_group_user_own'))]" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<button name="action_done" position="after"> <button name="action_done" position="after">
<button name="action_create_rma" <button
type="object" name="action_create_rma"
string="Create RMA" type="object"
states="sale,done"/> string="Create RMA"
states="sale,done"
/>
</button> </button>
<div name="button_box"> <div name="button_box">
<button name="action_view_rma" <button
type="object" name="action_view_rma"
class="oe_stat_button" type="object"
icon="fa-reply" class="oe_stat_button"
attrs="{'invisible': [('rma_count', '=', 0)]}"> icon="fa-reply"
<field name="rma_count" attrs="{'invisible': [('rma_count', '=', 0)]}"
widget="statinfo" >
string="RMA"/> <field name="rma_count" widget="statinfo" string="RMA" />
</button> </button>
</div> </div>
</field> </field>

View File

@@ -2,29 +2,30 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models from odoo import _, api, fields, models
from odoo.addons import decimal_precision as dp from odoo.addons import decimal_precision as dp
class SaleOrderRmaWizard(models.TransientModel): class SaleOrderRmaWizard(models.TransientModel):
_name = "sale.order.rma.wizard" _name = "sale.order.rma.wizard"
_description = 'Sale Order Rma Wizard' _description = "Sale Order Rma Wizard"
def _domain_location_id(self): def _domain_location_id(self):
rma_loc = self.env['stock.warehouse'].search([]).mapped('rma_loc_id') rma_loc = self.env["stock.warehouse"].search([]).mapped("rma_loc_id")
return [('id', 'child_of', rma_loc.ids)] return [("id", "child_of", rma_loc.ids)]
order_id = fields.Many2one( order_id = fields.Many2one(
comodel_name='sale.order', comodel_name="sale.order",
default=lambda self: self.env.context.get('active_id', False), default=lambda self: self.env.context.get("active_id", False),
) )
line_ids = fields.One2many( line_ids = fields.One2many(
comodel_name='sale.order.line.rma.wizard', comodel_name="sale.order.line.rma.wizard",
inverse_name='wizard_id', inverse_name="wizard_id",
string='Lines', string="Lines",
) )
location_id = fields.Many2one( location_id = fields.Many2one(
comodel_name='stock.location', comodel_name="stock.location",
string='RMA location', string="RMA location",
domain=_domain_location_id, domain=_domain_location_id,
default=lambda r: r.order_id.warehouse_id.rma_loc_id.id, default=lambda r: r.order_id.warehouse_id.rma_loc_id.id,
) )
@@ -33,19 +34,21 @@ class SaleOrderRmaWizard(models.TransientModel):
self.ensure_one() self.ensure_one()
lines = self.line_ids.filtered(lambda r: r.quantity > 0.0) lines = self.line_ids.filtered(lambda r: r.quantity > 0.0)
val_list = [line._prepare_rma_values() for line in lines] val_list = [line._prepare_rma_values() for line in lines]
rma = self.env['rma'].create(val_list) rma = self.env["rma"].create(val_list)
# post messages # post messages
msg_list = ['<a href="#" data-oe-model="rma" data-oe-id="%d">%s</a>' msg_list = [
% (r.id, r.name) for r in rma] '<a href="#" data-oe-model="rma" data-oe-id="%d">%s</a>' % (r.id, r.name)
msg = ', '.join(msg_list) for r in rma
]
msg = ", ".join(msg_list)
if len(msg_list) == 1: if len(msg_list) == 1:
self.order_id.message_post(body=_(msg + ' has been created.')) self.order_id.message_post(body=_(msg + " has been created."))
elif len(msg_list) > 1: elif len(msg_list) > 1:
self.order_id.message_post(body=_(msg + ' have been created.')) self.order_id.message_post(body=_(msg + " have been created."))
rma.message_post_with_view( rma.message_post_with_view(
'mail.message_origin_link', "mail.message_origin_link",
values={'self': rma, 'origin': self.order_id}, values={"self": rma, "origin": self.order_id},
subtype_id=self.env.ref('mail.mt_note').id, subtype_id=self.env.ref("mail.mt_note").id,
) )
return rma return rma
@@ -54,115 +57,107 @@ class SaleOrderRmaWizard(models.TransientModel):
rma = self.create_rma() rma = self.create_rma()
for rec in rma: for rec in rma:
rec.action_confirm() rec.action_confirm()
action = self.env.ref('rma.rma_action').read()[0] action = self.env.ref("rma.rma_action").read()[0]
if len(rma) > 1: if len(rma) > 1:
action['domain'] = [('id', 'in', rma.ids)] action["domain"] = [("id", "in", rma.ids)]
elif rma: elif rma:
action.update( action.update(
res_id=rma.id, res_id=rma.id, view_mode="form", view_id=False, views=False,
view_mode="form",
view_id=False,
views=False,
) )
return action return action
class SaleOrderLineRmaWizard(models.TransientModel): class SaleOrderLineRmaWizard(models.TransientModel):
_name = "sale.order.line.rma.wizard" _name = "sale.order.line.rma.wizard"
_description = 'Sale Order Line Rma Wizard' _description = "Sale Order Line Rma Wizard"
wizard_id = fields.Many2one( wizard_id = fields.Many2one(comodel_name="sale.order.rma.wizard", string="Wizard",)
comodel_name='sale.order.rma.wizard',
string='Wizard',
)
order_id = fields.Many2one( order_id = fields.Many2one(
comodel_name='sale.order', comodel_name="sale.order",
default=lambda self: self.env['sale.order'].browse( default=lambda self: self.env["sale.order"].browse(
self.env.context.get('active_id', False)), self.env.context.get("active_id", False)
),
) )
allowed_product_ids = fields.Many2many( allowed_product_ids = fields.Many2many(
comodel_name='product.product', comodel_name="product.product", compute="_compute_allowed_product_ids"
compute='_compute_allowed_product_ids'
) )
product_id = fields.Many2one( product_id = fields.Many2one(
comodel_name='product.product', comodel_name="product.product",
string='Product', string="Product",
required=True, required=True,
domain="[('id', 'in', allowed_product_ids)]" domain="[('id', 'in', allowed_product_ids)]",
) )
uom_category_id = fields.Many2one( uom_category_id = fields.Many2one(
comodel_name='uom.category', comodel_name="uom.category", related="product_id.uom_id.category_id",
related='product_id.uom_id.category_id',
) )
quantity = fields.Float( quantity = fields.Float(
string='Quantity', string="Quantity",
digits=dp.get_precision('Product Unit of Measure'), digits=dp.get_precision("Product Unit of Measure"),
required=True, required=True,
) )
uom_id = fields.Many2one( uom_id = fields.Many2one(
comodel_name='uom.uom', comodel_name="uom.uom",
string='Unit of Measure', string="Unit of Measure",
domain="[('category_id', '=', uom_category_id)]", domain="[('category_id', '=', uom_category_id)]",
required=True, required=True,
) )
allowed_picking_ids = fields.Many2many( allowed_picking_ids = fields.Many2many(
comodel_name='stock.picking', comodel_name="stock.picking", compute="_compute_allowed_picking_ids"
compute='_compute_allowed_picking_ids'
) )
picking_id = fields.Many2one( picking_id = fields.Many2one(
comodel_name='stock.picking', comodel_name="stock.picking",
string='Delivery order', string="Delivery order",
domain="[('id', 'in', allowed_picking_ids)]" domain="[('id', 'in', allowed_picking_ids)]",
)
move_id = fields.Many2one(
comodel_name='stock.move',
compute='_compute_move_id'
) )
move_id = fields.Many2one(comodel_name="stock.move", compute="_compute_move_id")
operation_id = fields.Many2one( operation_id = fields.Many2one(
comodel_name='rma.operation', comodel_name="rma.operation", string="Requested operation",
string='Requested operation',
) )
description = fields.Text() description = fields.Text()
@api.onchange('product_id') @api.onchange("product_id")
def onchange_product_id(self): def onchange_product_id(self):
self.picking_id = False self.picking_id = False
@api.depends('picking_id') @api.depends("picking_id")
def _compute_move_id(self): def _compute_move_id(self):
for record in self: for record in self:
if record.picking_id: if record.picking_id:
record.move_id = record.picking_id.move_lines.filtered( record.move_id = record.picking_id.move_lines.filtered(
lambda r: (r.sale_line_id.product_id == record.product_id lambda r: (
and r.sale_line_id.order_id == record.order_id)) r.sale_line_id.product_id == record.product_id
and r.sale_line_id.order_id == record.order_id
)
)
@api.depends('order_id') @api.depends("order_id")
def _compute_allowed_product_ids(self): def _compute_allowed_product_ids(self):
for record in self: for record in self:
product_ids = record.order_id.order_line.mapped('product_id.id') product_ids = record.order_id.order_line.mapped("product_id.id")
record.allowed_product_ids = product_ids record.allowed_product_ids = product_ids
@api.depends('product_id') @api.depends("product_id")
def _compute_allowed_picking_ids(self): def _compute_allowed_picking_ids(self):
for record in self: for record in self:
line = record.order_id.order_line.filtered( line = record.order_id.order_line.filtered(
lambda r: r.product_id == record.product_id) lambda r: r.product_id == record.product_id
record.allowed_picking_ids = line.mapped('move_ids.picking_id') )
record.allowed_picking_ids = line.mapped("move_ids.picking_id")
def _prepare_rma_values(self): def _prepare_rma_values(self):
self.ensure_one() self.ensure_one()
return { return {
'partner_id': self.order_id.partner_id.id, "partner_id": self.order_id.partner_id.id,
'partner_invoice_id': self.order_id.partner_invoice_id.id, "partner_invoice_id": self.order_id.partner_invoice_id.id,
'origin': self.order_id.name, "origin": self.order_id.name,
'company_id': self.order_id.company_id.id, "company_id": self.order_id.company_id.id,
'location_id': self.wizard_id.location_id.id, "location_id": self.wizard_id.location_id.id,
'order_id': self.order_id.id, "order_id": self.order_id.id,
'picking_id': self.picking_id.id, "picking_id": self.picking_id.id,
'move_id': self.move_id.id, "move_id": self.move_id.id,
'product_id': self.product_id.id, "product_id": self.product_id.id,
'product_uom_qty': self.quantity, "product_uom_qty": self.quantity,
'product_uom': self.uom_id.id, "product_uom": self.uom_id.id,
'operation_id': self.operation_id.id, "operation_id": self.operation_id.id,
'description': self.description, "description": self.description,
} }

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="sale_order_create_rma_action" model="ir.actions.act_window"> <record id="sale_order_create_rma_action" model="ir.actions.act_window">
<field name="name">Create RMAs</field> <field name="name">Create RMAs</field>
@@ -7,7 +7,6 @@
<field name="view_mode">form</field> <field name="view_mode">form</field>
<field name="target">new</field> <field name="target">new</field>
</record> </record>
<record id="=sale_order_rma_wizard_form_view" model="ir.ui.view"> <record id="=sale_order_rma_wizard_form_view" model="ir.ui.view">
<field name="name">sale.order.rma.wizard.form</field> <field name="name">sale.order.rma.wizard.form</field>
<field name="model">sale.order.rma.wizard</field> <field name="model">sale.order.rma.wizard</field>
@@ -16,34 +15,38 @@
<group> <group>
<field name="line_ids" nolabel="1"> <field name="line_ids" nolabel="1">
<tree editable="bottom"> <tree editable="bottom">
<field name="order_id" invisible="1"/> <field name="order_id" invisible="1" />
<field name="allowed_product_ids" invisible="1"/> <field name="allowed_product_ids" invisible="1" />
<field name="product_id" options="{'no_create': True}"/> <field name="product_id" options="{'no_create': True}" />
<field name="quantity"/> <field name="quantity" />
<field name="uom_category_id" invisible="1"/> <field name="uom_category_id" invisible="1" />
<field name="uom_id" <field
groups="uom.group_uom" name="uom_id"
options="{'no_create': True}"/> groups="uom.group_uom"
<field name="allowed_picking_ids" invisible="1"/> options="{'no_create': True}"
<field name="picking_id" options="{'no_create': True}"/> />
<field name="operation_id"/> <field name="allowed_picking_ids" invisible="1" />
<field name="picking_id" options="{'no_create': True}" />
<field name="operation_id" />
</tree> </tree>
</field> </field>
</group> </group>
<group> <group>
<field name="location_id" <field
options="{'no_create': True, 'no_open': True}" name="location_id"
groups="stock.group_stock_multi_locations" options="{'no_create': True, 'no_open': True}"
required="1"/> groups="stock.group_stock_multi_locations"
required="1"
/>
</group> </group>
<footer> <footer>
<button name="create_and_open_rma" <button
string="Accept" name="create_and_open_rma"
type="object" string="Accept"
class="btn-primary"/> type="object"
<button string="Cancel" class="btn-primary"
class="btn-secondary" />
special="cancel" /> <button string="Cancel" class="btn-secondary" special="cancel" />
</footer> </footer>
</form> </form>
</field> </field>