Skip to content

Commit

Permalink
[16.0][IMP] rma: create incoming shipment from rma group
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Mar 28, 2024
1 parent 3c0e9c4 commit 0e68988
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
9 changes: 9 additions & 0 deletions rma/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def _compute_state(self):
state = "draft"
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.model
def _default_date_rma(self):
return datetime.now()
Expand Down Expand Up @@ -178,6 +183,10 @@ 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",
)

@api.onchange(
"operation_default_id",
Expand Down
1 change: 1 addition & 0 deletions rma/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
'invisible':[('customer_to_supplier', '=', False)],
'readonly':[('state', '!=', 'draft')]}"
/>
<field name="qty_to_receive" invisible="1" />
</group>
</group>
<group>
Expand Down
17 changes: 12 additions & 5 deletions rma/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ def default_get(self, fields_list):
context = self._context.copy()
res = super(RmaMakePicking, self).default_get(fields_list)
rma_line_obj = self.env["rma.order.line"]
rma_line_ids = self.env.context["active_ids"] or []
rma_obj = self.env["rma.order"]
active_ids = self.env.context["active_ids"] or []
active_model = self.env.context["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.filtered(lambda x: x.state == "approved")
else:
lines = rma_line_obj.browse(active_ids)
if len(lines.mapped("partner_id")) > 1:
raise ValidationError(
_(
Expand Down
25 changes: 24 additions & 1 deletion rma/wizards/rma_make_picking_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
name="%(action_rma_picking_in)d"
string="Create Incoming Shipment"
class="oe_highlight"
attrs="{'invisible':['|', '|', '|', ('qty_to_receive', '=', 0), ('qty_to_receive', '&lt;', 0), ('state', '!=', 'approved'), ('receipt_policy', '=', 'no')]}"
attrs="{'invisible':['|', '|', ('qty_to_receive', '&lt;', 0), ('state', '!=', 'approved'), ('receipt_policy', '=', 'no')]}"
type="action"
/>
<button
Expand All @@ -134,4 +134,27 @@
</field>
</record>

<record id="view_rma_button_form" model="ir.ui.view">
<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), ('state', '!=', 'approved')]}"
type="action"
/>
<button
name="%(action_rma_picking_in)d"
string="Create Incoming Shipment"
attrs="{'invisible':['|', '|', ('qty_to_receive', '=', 0), ('qty_to_receive', '>', 0), ('state', '!=', 'approved')]}"
type="action"
/>
</header>
</field>
</record>

</odoo>

0 comments on commit 0e68988

Please sign in to comment.