mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
Merge pull request #262 from ForgeFlow/13.0-fp-253
[13.0][IMP] rma: add RMA reference to delivery slip report + add rma lines to group selecting serial numbers
This commit is contained in:
@@ -32,6 +32,8 @@
|
|||||||
"wizards/rma_make_picking_view.xml",
|
"wizards/rma_make_picking_view.xml",
|
||||||
"wizards/rma_add_stock_move_view.xml",
|
"wizards/rma_add_stock_move_view.xml",
|
||||||
"wizards/rma_order_line_make_supplier_rma_view.xml",
|
"wizards/rma_order_line_make_supplier_rma_view.xml",
|
||||||
|
"report/report_deliveryslip.xml",
|
||||||
|
"wizards/rma_add_serial_views.xml",
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"application": True,
|
"application": True,
|
||||||
|
|||||||
33
rma/report/report_deliveryslip.xml
Normal file
33
rma/report/report_deliveryslip.xml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<template id="report_delivery_document" inherit_id="stock.report_delivery_document">
|
||||||
|
|
||||||
|
<xpath
|
||||||
|
expr="//table[@name='stock_move_table']//th[@name='th_sm_quantity']"
|
||||||
|
position="before"
|
||||||
|
>
|
||||||
|
<t
|
||||||
|
t-set="has_rma"
|
||||||
|
t-value="bool(o.move_lines.filtered(lambda m: m.rma_line_id))"
|
||||||
|
/>
|
||||||
|
<th t-if="has_rma" name="th_sm_rma_line"><strong>RMA</strong></th>
|
||||||
|
</xpath>
|
||||||
|
<xpath expr="//table[@name='stock_move_table']/tbody//td[2]" position="before">
|
||||||
|
<td t-if="has_rma">
|
||||||
|
<span t-field="move.rma_line_id" />
|
||||||
|
</td>
|
||||||
|
</xpath>
|
||||||
|
|
||||||
|
<xpath
|
||||||
|
expr="//table[@name='stock_move_line_table']//th[@name='th_sml_quantity']"
|
||||||
|
position="before"
|
||||||
|
>
|
||||||
|
<t
|
||||||
|
t-set="sml_has_rma"
|
||||||
|
t-value="bool(o.move_line_ids.filtered(lambda m: m.move_id.rma_line_id))"
|
||||||
|
/>
|
||||||
|
<th t-if="sml_has_rma" name="th_sml_rma_line"><strong>RMA</strong></th>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
@@ -9,3 +9,17 @@ access_rma_operation_manager,access_rma_operation,model_rma_operation,group_rma_
|
|||||||
access_rma_operation_customer_user,access_rma_operation,model_rma_operation,group_rma_customer_user,1,0,0,0
|
access_rma_operation_customer_user,access_rma_operation,model_rma_operation,group_rma_customer_user,1,0,0,0
|
||||||
access_rma_operation_supplier_user,access_rma_operation,model_rma_operation,group_rma_supplier_user,1,0,0,0
|
access_rma_operation_supplier_user,access_rma_operation,model_rma_operation,group_rma_supplier_user,1,0,0,0
|
||||||
access_rma_order_line_user,access_rma_order_line,model_rma_order_line,base.group_user,1,0,0,0
|
access_rma_order_line_user,access_rma_order_line,model_rma_order_line,base.group_user,1,0,0,0
|
||||||
|
access_rma_picking_wizard,rma.order.manager,model_rma_make_picking_wizard,group_rma_manager,1,1,1,1
|
||||||
|
access_rma_picking_wizard_customer,rma.order.manager,model_rma_make_picking_wizard,group_rma_customer_user,1,1,1,1
|
||||||
|
access_rma_picking_wizard_supplier,rma.order.manager,model_rma_make_picking_wizard,group_rma_supplier_user,1,1,1,1
|
||||||
|
access_rma_picking_wizard_item,rma.order.manager,model_rma_make_picking_wizard_item,group_rma_manager,1,1,1,1
|
||||||
|
access_rma_picking_wizard_item_customer,rma.order.manager,model_rma_make_picking_wizard_item,group_rma_customer_user,1,1,1,1
|
||||||
|
access_rma_picking_wizard_item_supplier,rma.order.manager,model_rma_make_picking_wizard_item,group_rma_supplier_user,1,1,1,1
|
||||||
|
access_rma_order_line_make_supplier_rma_customer_user,rma.order.line.make.supplier.rma.customer.user,model_rma_order_line_make_supplier_rma,rma.group_rma_customer_user,1,1,1,1
|
||||||
|
access_rma_order_line_make_supplier_rmasupplier_user,rma.order.line.make.supplier.rma.supplier.user,model_rma_order_line_make_supplier_rma,rma.group_rma_supplier_user,1,1,1,1
|
||||||
|
access_rma_order_line_make_supplier_rma_customer_user_item,rma.order.line.make.supplier.rma.item.customer.user,model_rma_order_line_make_supplier_rma_item,rma.group_rma_customer_user,1,1,1,1
|
||||||
|
access_rma_order_line_make_supplier_rmasupplier_user_item,rma.order.line.make.supplier.rma.item.supplier.user,model_rma_order_line_make_supplier_rma_item,rma.group_rma_supplier_user,1,1,1,1
|
||||||
|
access_rma_add_stock_move_customer_user_item,rma.add.stock.move.customer.user,model_rma_add_stock_move,rma.group_rma_customer_user,1,1,1,1
|
||||||
|
access_rma_add_stock_move_supplier_user_item,rma.add.stock.move.supplier.user,model_rma_add_stock_move,rma.group_rma_supplier_user,1,1,1,1
|
||||||
|
access_rma_add_serial_wiz_customer,access_rma_add_serial_wiz_customer,model_rma_add_serial_wiz,rma.group_rma_customer_user,1,1,1,1
|
||||||
|
access_rma_add_serial_wiz_supplier,access_rma_add_serial_wiz_supplier,model_rma_add_serial_wiz,rma.group_rma_supplier_user,1,1,1,1
|
||||||
|
|||||||
|
@@ -1,6 +1,4 @@
|
|||||||
# Copyright (C) 2017-20 ForgeFlow S.L.
|
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
|
||||||
|
|
||||||
from . import rma_add_stock_move
|
from . import rma_add_stock_move
|
||||||
from . import rma_make_picking
|
from . import rma_make_picking
|
||||||
from . import rma_order_line_make_supplier_rma
|
from . import rma_order_line_make_supplier_rma
|
||||||
|
from . import rma_add_serial
|
||||||
|
|||||||
137
rma/wizards/rma_add_serial.py
Normal file
137
rma/wizards/rma_add_serial.py
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
# Copyright 2022 ForgeFlow S.L.
|
||||||
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class RmaAddSerialWiz(models.TransientModel):
|
||||||
|
_name = "rma.add.serial.wiz"
|
||||||
|
_description = "Wizard to add rma lines from Serial/Lot numbers"
|
||||||
|
|
||||||
|
rma_id = fields.Many2one(
|
||||||
|
comodel_name="rma.order", string="RMA Order", readonly=True, ondelete="cascade"
|
||||||
|
)
|
||||||
|
partner_id = fields.Many2one(
|
||||||
|
comodel_name="res.partner", string="Partner", readonly=True
|
||||||
|
)
|
||||||
|
partner_shipping_id = fields.Many2one(
|
||||||
|
string="Deliver To",
|
||||||
|
comodel_name="res.partner",
|
||||||
|
)
|
||||||
|
lot_ids = fields.Many2many(
|
||||||
|
comodel_name="stock.production.lot",
|
||||||
|
string="Lots/Serials selected",
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
|
res = super().default_get(fields_list)
|
||||||
|
rma_obj = self.env["rma.order"]
|
||||||
|
rma_id = self.env.context["active_ids"] or []
|
||||||
|
active_model = self.env.context["active_model"]
|
||||||
|
if not rma_id:
|
||||||
|
return res
|
||||||
|
assert active_model == "rma.order", "Bad context propagation"
|
||||||
|
|
||||||
|
rma = rma_obj.browse(rma_id)
|
||||||
|
res["rma_id"] = rma.id
|
||||||
|
res["partner_id"] = rma.partner_id.id
|
||||||
|
return res
|
||||||
|
|
||||||
|
@api.onchange("partner_id")
|
||||||
|
def onchange_partner_id(self):
|
||||||
|
if not self.partner_id:
|
||||||
|
self.update(
|
||||||
|
{
|
||||||
|
"partner_shipping_id": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
self = self.with_company(self.rma_id.company_id)
|
||||||
|
addr = self.partner_id.address_get(["delivery"])
|
||||||
|
self.update(
|
||||||
|
{
|
||||||
|
"partner_shipping_id": addr["delivery"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def _prepare_rma_line_from_lot_vals(self, lot):
|
||||||
|
if self.env.context.get("customer"):
|
||||||
|
operation = (
|
||||||
|
lot.product_id.rma_customer_operation_id
|
||||||
|
or lot.product_id.categ_id.rma_customer_operation_id
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
operation = (
|
||||||
|
lot.product_id.rma_supplier_operation_id
|
||||||
|
or lot.product_id.categ_id.rma_supplier_operation_id
|
||||||
|
)
|
||||||
|
if not operation:
|
||||||
|
operation = self.env["rma.operation"].search(
|
||||||
|
[("type", "=", self.rma_id.type)], limit=1
|
||||||
|
)
|
||||||
|
if not operation:
|
||||||
|
raise ValidationError(_("Please define an operation first"))
|
||||||
|
|
||||||
|
if not operation.in_route_id or not operation.out_route_id:
|
||||||
|
route = self.env["stock.location.route"].search(
|
||||||
|
[("rma_selectable", "=", True)], limit=1
|
||||||
|
)
|
||||||
|
if not route:
|
||||||
|
raise ValidationError(_("Please define an RMA route"))
|
||||||
|
|
||||||
|
if not operation.in_warehouse_id or not operation.out_warehouse_id:
|
||||||
|
warehouse = self.env["stock.warehouse"].search(
|
||||||
|
[
|
||||||
|
("company_id", "=", self.rma_id.company_id.id),
|
||||||
|
("lot_rma_id", "!=", False),
|
||||||
|
],
|
||||||
|
limit=1,
|
||||||
|
)
|
||||||
|
if not warehouse:
|
||||||
|
raise ValidationError(
|
||||||
|
_("Please define a warehouse with a default RMA location")
|
||||||
|
)
|
||||||
|
|
||||||
|
product_qty = 1 # serial
|
||||||
|
if lot.product_id.tracking == "lot":
|
||||||
|
# TODO: improve logic, allow to specify qty?
|
||||||
|
product_qty = 1
|
||||||
|
|
||||||
|
vals = {
|
||||||
|
"partner_id": self.partner_id.id,
|
||||||
|
"product_id": lot.product_id.id,
|
||||||
|
"lot_id": lot.id,
|
||||||
|
"uom_id": lot.product_id.uom_id.id,
|
||||||
|
"operation_id": operation.id,
|
||||||
|
"product_qty": product_qty,
|
||||||
|
"delivery_address_id": self.partner_shipping_id.id or self.partner_id.id,
|
||||||
|
"rma_id": self.rma_id.id,
|
||||||
|
"receipt_policy": operation.receipt_policy,
|
||||||
|
"delivery_policy": operation.delivery_policy,
|
||||||
|
"in_warehouse_id": operation.in_warehouse_id.id or warehouse.id,
|
||||||
|
"out_warehouse_id": operation.out_warehouse_id.id or warehouse.id,
|
||||||
|
"in_route_id": operation.in_route_id.id or route.id,
|
||||||
|
"out_route_id": operation.out_route_id.id or route.id,
|
||||||
|
"location_id": (
|
||||||
|
operation.location_id.id
|
||||||
|
or operation.in_warehouse_id.lot_rma_id.id
|
||||||
|
or warehouse.lot_rma_id.id
|
||||||
|
),
|
||||||
|
}
|
||||||
|
return vals
|
||||||
|
|
||||||
|
def action_confirm(self):
|
||||||
|
rma_line_obj = self.env["rma.order.line"]
|
||||||
|
existing_lots = self.rma_id.mapped("rma_line_ids.lot_id")
|
||||||
|
for lot in self.lot_ids:
|
||||||
|
if lot in existing_lots:
|
||||||
|
raise ValidationError(
|
||||||
|
_("Lot/Serial Number %s already added.") % lot.name
|
||||||
|
)
|
||||||
|
|
||||||
|
vals = self._prepare_rma_line_from_lot_vals(lot)
|
||||||
|
rma_line_obj.create(vals)
|
||||||
|
return {"type": "ir.actions.act_window_close"}
|
||||||
100
rma/wizards/rma_add_serial_views.xml
Normal file
100
rma/wizards/rma_add_serial_views.xml
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_rma_add_serial_wiz_customer" model="ir.ui.view">
|
||||||
|
<field name="name">rma.add.serial.wiz.customer</field>
|
||||||
|
<field name="model">rma.add.serial.wiz</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form>
|
||||||
|
<group>
|
||||||
|
<field name="partner_id" string="Customer" />
|
||||||
|
<field
|
||||||
|
name="partner_shipping_id"
|
||||||
|
groups="rma.group_rma_delivery_invoice_address"
|
||||||
|
string="Shipping Address"
|
||||||
|
/>
|
||||||
|
</group>
|
||||||
|
<separator string="Select Lot/Serial Numbers to add" />
|
||||||
|
<field name="lot_ids" />
|
||||||
|
<footer>
|
||||||
|
<button
|
||||||
|
string="Confirm"
|
||||||
|
name="action_confirm"
|
||||||
|
type="object"
|
||||||
|
class="oe_highlight"
|
||||||
|
/>
|
||||||
|
or
|
||||||
|
<button
|
||||||
|
name="action_cancel"
|
||||||
|
string="Cancel"
|
||||||
|
class="oe_link"
|
||||||
|
special="cancel"
|
||||||
|
/>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_rma_add_serial_wiz_customer" model="ir.actions.act_window">
|
||||||
|
<field name="name">Add from Lot/Serial Numbers</field>
|
||||||
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
<field name="res_model">rma.add.serial.wiz</field>
|
||||||
|
<field name="view_mode">form</field>
|
||||||
|
<field name="target">new</field>
|
||||||
|
<field name="view_id" ref="view_rma_add_serial_wiz_customer" />
|
||||||
|
<field name="groups_id" eval="[(4, ref('rma.group_rma_customer_user'))]" />
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
<record id="view_rma_add_serial_wiz_customer_form" model="ir.ui.view">
|
||||||
|
<field name="name">rma.order.form - rma.add.serial.wiz</field>
|
||||||
|
<field name="model">rma.order</field>
|
||||||
|
<field name="inherit_id" ref="rma.view_rma_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//header" position="inside">
|
||||||
|
<button
|
||||||
|
name="%(action_rma_add_serial_wiz_customer)d"
|
||||||
|
string="Add Lot/Serial Numbers"
|
||||||
|
type="action"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_rma_add_serial_wiz_supplier" model="ir.ui.view">
|
||||||
|
<field name="name">rma.add.serial.wiz.supplier</field>
|
||||||
|
<field name="model">rma.add.serial.wiz</field>
|
||||||
|
<field name="inherit_id" ref="view_rma_add_serial_wiz_customer" />
|
||||||
|
<field name="mode">primary</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="partner_id" position="attributes">
|
||||||
|
<attribute name="string">Supplier</attribute>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_rma_add_serial_wiz_supplier" model="ir.actions.act_window">
|
||||||
|
<field name="name">Add from Lot/Serial Number</field>
|
||||||
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
<field name="res_model">rma.add.serial.wiz</field>
|
||||||
|
<field name="view_mode">form</field>
|
||||||
|
<field name="target">new</field>
|
||||||
|
<field name="view_id" ref="view_rma_add_serial_wiz_supplier" />
|
||||||
|
<field name="groups_id" eval="[(4, ref('rma.group_rma_supplier_user'))]" />
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_rma_add_serial_wiz_button_supplier_form" model="ir.ui.view">
|
||||||
|
<field name="name">rma.order.supplier.form - rma.add.serial.wiz</field>
|
||||||
|
<field name="model">rma.order</field>
|
||||||
|
<field name="inherit_id" ref="rma.view_rma_supplier_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//header" position="inside">
|
||||||
|
<button
|
||||||
|
name="%(action_rma_add_serial_wiz_supplier)d"
|
||||||
|
string="Add Lot/Serial numbers"
|
||||||
|
type="action"
|
||||||
|
/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user