Skip to content

Commit

Permalink
[IMP] create delivery from rma group
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Apr 22, 2024
1 parent 6fd5d2f commit f7c7cda
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions rma/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ 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 @@ -184,6 +189,10 @@ def _default_warehouse_id(self):
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
1 change: 1 addition & 0 deletions rma/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
'readonly':[('state', '!=', 'draft')]}"
/>
<field name="qty_to_receive" invisible="1" />
<field name="qty_to_deliver" invisible="1" />
</group>
</group>
<group>
Expand Down
7 changes: 5 additions & 2 deletions rma/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ 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_obj = self.env["rma.order"]
active_ids = self.env.context["active_ids"] or []
Expand All @@ -47,7 +47,10 @@ def default_get(self, fields_list):
items = []
if active_model == "rma.order":
rma = rma_obj.browse(active_ids)
lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_receive > 0)
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:
lines = rma_line_obj.browse(active_ids)
if len(lines.mapped("partner_id")) > 1:
Expand Down
7 changes: 7 additions & 0 deletions rma/wizards/rma_make_picking_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@
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>
Expand Down

0 comments on commit f7c7cda

Please sign in to comment.