Skip to content

Commit

Permalink
[IMP] create supplier rma from rma group
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Jun 25, 2024
1 parent c3b3a6a commit 8d59e55
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 26 deletions.
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
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: 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
6 changes: 3 additions & 3 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 @@ -35,8 +35,8 @@ def default_get(self, fields_list):
res = super().default_get(fields_list)
rma_line_obj = self.env["rma.order.line"]
rma_obj = self.env["rma.order"]
active_ids = self.env.context["active_ids"] or []
active_model = self.env.context["active_model"]
active_ids = context.get("active_ids") or []
active_model = context.get("active_model")
if not active_ids:
return res
assert active_model in [
Expand Down
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

0 comments on commit 8d59e55

Please sign in to comment.