Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] rma: create incoming shipment from rma group #508

Open
wants to merge 9 commits into
base: 16.0
Choose a base branch
from
2 changes: 1 addition & 1 deletion rma/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"views/rma_menu.xml",
"wizards/rma_make_picking_view.xml",
"wizards/rma_add_stock_move_view.xml",
"wizards/rma_order_line_make_supplier_rma_view.xml",
"wizards/rma_make_supplier_rma_view.xml",
"report/report_deliveryslip.xml",
"wizards/rma_add_serial_views.xml",
],
Expand Down
18 changes: 18 additions & 0 deletions rma/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def _compute_state(self):
state = "done"
rec.state = state

@api.depends("rma_line_ids", "rma_line_ids.qty_to_receive")
def _compute_qty_to_receive(self):
for rec in self:
rec.qty_to_receive = sum(rec.rma_line_ids.mapped("qty_to_receive"))

@api.depends("rma_line_ids", "rma_line_ids.qty_to_deliver")
def _compute_qty_to_deliver(self):
for rec in self:
rec.qty_to_deliver = sum(rec.rma_line_ids.mapped("qty_to_deliver"))

@api.model
def _default_date_rma(self):
return datetime.now()
Expand Down Expand Up @@ -175,6 +185,14 @@ def _default_warehouse_id(self):
required=False,
string="Default Operation Type",
)
qty_to_receive = fields.Float(
digits="Product Unit of Measure",
compute="_compute_qty_to_receive",
)
qty_to_deliver = fields.Float(
digits="Product Unit of Measure",
compute="_compute_qty_to_deliver",
)

@api.onchange(
"operation_default_id",
Expand Down
4 changes: 2 additions & 2 deletions rma/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ access_rma_picking_wizard_supplier,rma.order.manager,model_rma_make_picking_wiza
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_make_supplier_rma_customer_user,rma.make.supplier.rma.customer.user,model_rma_make_supplier_rma,rma.group_rma_customer_user,1,1,1,1
access_rma_make_supplier_rma_supplier_user,rma.make.supplier.rma.supplier.user,model_rma_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
Expand Down
2 changes: 1 addition & 1 deletion rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setUpClass(cls):
super(TestRma, cls).setUpClass()
# models
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.make.supplier.rma"]
cls.rma_add_stock_move = cls.env["rma_add_stock_move"]
cls.product_ctg_model = cls.env["product.category"]
cls.stockpicking = cls.env["stock.picking"]
Expand Down
2 changes: 2 additions & 0 deletions rma/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
'invisible':[('customer_to_supplier', '=', False)],
'readonly':[('state', '!=', 'draft')]}"
/>
<field name="qty_to_receive" invisible="1" />
<field name="qty_to_deliver" invisible="1" />
</group>
</group>
<group>
Expand Down
2 changes: 1 addition & 1 deletion rma/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import rma_add_stock_move
from . import rma_make_picking
from . import rma_order_line_make_supplier_rma
from . import rma_make_supplier_rma
from . import rma_add_serial
26 changes: 18 additions & 8 deletions rma/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class RmaMakePicking(models.TransientModel):
_name = "rma_make_picking.wizard"
_description = "Wizard to create pickings from rma lines"
_description = "Wizard to create Pickings from rma"

@api.returns("rma.order.line")
def _prepare_item(self, line):
Expand All @@ -32,17 +32,27 @@ def default_get(self, fields_list):
supplier.
"""
context = self._context.copy()
res = super(RmaMakePicking, self).default_get(fields_list)
res = super().default_get(fields_list)
rma_line_obj = self.env["rma.order.line"]
rma_line_ids = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"]

if not rma_line_ids:
rma_obj = self.env["rma.order"]
active_ids = context.get("active_ids") or []
active_model = context.get("active_model")
if not active_ids:
return res
assert active_model == "rma.order.line", "Bad context propagation"
assert active_model in [
"rma.order.line",
"rma.order",
], "Bad context propagation"

items = []
lines = rma_line_obj.browse(rma_line_ids)
if active_model == "rma.order":
rma = rma_obj.browse(active_ids)
if context.get("picking_type") == "incoming":
lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_receive > 0)
if context.get("picking_type") == "outgoing":
lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_deliver > 0)
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think all approved lines should always be added when coming from a group.
I'd say, if the highlighted button is pressed, then we should only get lines having a qty_to_receive > 0
(maybe passing a context on the button for instance ?)
And if the not highlighted button is pressed, then all lines with a receipt policy != 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florian-dacosta , it's done.

lines = rma_line_obj.browse(active_ids)
if len(lines.mapped("partner_id")) > 1:
raise ValidationError(
_(
Expand Down
24 changes: 24 additions & 0 deletions rma/wizards/rma_make_picking_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,28 @@
</field>
</record>

<record id="view_rma_button_form" model="ir.ui.view">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it quite confusing to have an override of rma.order view in rma_make_picking_view.xml file.
I know there is other similar cases in the rma modules but do we really want to continue this way ? Should it not go to rma_order_view.xml ? @AaronHForgeFlow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@florian-dacosta, better to have file for model, whenever possible, in the next versions some cleanup will be done, hopefully.

<field name="name">rma.order.form</field>
<field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_form" />
<field name="arch" type="xml">
<header position="inside">
<button
name="%(action_rma_picking_in)d"
string="Create Incoming Shipment"
class="oe_highlight"
attrs="{'invisible':['|', ('qty_to_receive', '=', 0), ('qty_to_receive', '&lt;', 0)]}"
type="action"
/>
<button
name="%(action_rma_picking_out)d"
string="Create Delivery"
class="oe_highlight"
attrs="{'invisible':['|', ('qty_to_deliver', '=', 0), ('qty_to_deliver', '&lt;', 0)]}"
type="action"
/>
</header>
</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from odoo.exceptions import ValidationError


class RmaLineMakeSupplierRma(models.TransientModel):
_name = "rma.order.line.make.supplier.rma"
_description = "RMA Line Make Supplier RMA"
class RmaMakeSupplierRma(models.TransientModel):
_name = "rma.make.supplier.rma"
_description = "Wizard to create Supplier RMA from rma"

partner_id = fields.Many2one(
comodel_name="res.partner",
Expand Down Expand Up @@ -50,17 +50,26 @@ def _prepare_item(self, line):

@api.model
def default_get(self, fields_list):
res = super(RmaLineMakeSupplierRma, self).default_get(fields_list)
context = self._context.copy()
res = super().default_get(fields_list)
rma_line_obj = self.env["rma.order.line"]
rma_line_ids = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"]
rma_obj = self.env["rma.order"]
active_ids = context.get("active_ids") or []
active_model = context.get("active_model")

if not rma_line_ids:
if not active_ids:
return res
assert active_model == "rma.order.line", "Bad context propagation"
assert active_model in [
"rma.order.line",
"rma.order",
], "Bad context propagation"

items = []
lines = rma_line_obj.browse(rma_line_ids)
if active_model == "rma.order":
rma = rma_obj.browse(active_ids)
lines = rma.rma_line_ids
else:
lines = rma_line_obj.browse(active_ids)
for line in lines:
items.append([0, 0, self._prepare_item(line)])
suppliers = lines.mapped(
Expand Down Expand Up @@ -177,7 +186,7 @@ class RmaLineMakeRmaOrderItem(models.TransientModel):
_description = "RMA Line Make Supplier RMA Item"

wiz_id = fields.Many2one(
"rma.order.line.make.supplier.rma",
"rma.make.supplier.rma",
string="Wizard",
required=True,
ondelete="cascade",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<odoo>
<record id="view_rma_order_line_make_supplier_rma" model="ir.ui.view">
<field name="name">RMA Line Make Supplier RMA</field>
<field name="model">rma.order.line.make.supplier.rma</field>
<field name="model">rma.make.supplier.rma</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Create Supplier RMA">
Expand Down Expand Up @@ -49,10 +49,10 @@
</field>
</record>

<record id="action_rma_order_line_make_supplier_rma" model="ir.actions.act_window">
<record id="action_make_supplier_rma" model="ir.actions.act_window">
<field name="name">Create Supplier RMA</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">rma.order.line.make.supplier.rma</field>
<field name="res_model">rma.make.supplier.rma</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_rma_order_line_make_supplier_rma" />
<field name="target">new</field>
Expand All @@ -66,7 +66,23 @@
<field name="arch" type="xml">
<header position="inside">
<button
name="%(action_rma_order_line_make_supplier_rma)d"
name="%(action_make_supplier_rma)d"
string="Create Supplier RMA"
attrs="{'invisible':['|', ('type', '!=', 'customer'), ('state', '!=', 'approved')]}"
type="action"
/>
</header>
</field>
</record>

<record id="view_rma_supplier_rma_button_form" model="ir.ui.view">
<field name="name">rma.supplier.rma.form</field>
<field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_form" />
<field name="arch" type="xml">
<header position="inside">
<button
name="%(action_make_supplier_rma)d"
string="Create Supplier RMA"
attrs="{'invisible':['|', ('type', '!=', 'customer'), ('state', '!=', 'approved')]}"
type="action"
Expand Down
2 changes: 1 addition & 1 deletion rma_account/wizards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

from . import rma_refund
from . import rma_add_account_move
from . import rma_order_line_make_supplier_rma
from . import rma_make_supplier_rma
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from odoo import api, models


class RmaLineMakeSupplierRma(models.TransientModel):
_inherit = "rma.order.line.make.supplier.rma"
class RmaMakeSupplierRma(models.TransientModel):
_inherit = "rma.make.supplier.rma"

@api.model
def _prepare_supplier_rma_line(self, rma, item):
res = super(RmaLineMakeSupplierRma, self)._prepare_supplier_rma_line(rma, item)
res = super()._prepare_supplier_rma_line(rma, item)
if res["operation_id"]:
operation = self.env["rma.operation"].browse(res["operation_id"])
res["refund_policy"] = operation.refund_policy
Expand Down
Loading