Skip to content

Commit

Permalink
[FIX] rma, rma_account and rma_sale: following the comments that were…
Browse files Browse the repository at this point in the history
… made during the review
  • Loading branch information
chafique-delli committed Sep 16, 2024
1 parent f3801fc commit 3d97216
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 82 deletions.
6 changes: 3 additions & 3 deletions rma/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ def create(self, vals_list):

def _view_shipments(self, result, shipments):
# choose the view_mode accordingly
if len(shipments) > 1:
result["domain"] = [("id", "in", shipments.ids)]
elif len(shipments) == 1:
if len(shipments) == 1:
res = self.env.ref("stock.view_picking_form", False)
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = shipments.ids[0]
else:
result["domain"] = [("id", "in", shipments.ids)]
return result

def action_view_in_shipments(self):
Expand Down
32 changes: 18 additions & 14 deletions rma/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@
attrs="{'invisible':[('state', 'in', ('done', 'cancel'))]}"
groups="rma.group_rma_customer_user"
/>
<button
name="%(rma.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="%(rma.action_rma_picking_out)d"
string="Create Delivery"
class="oe_highlight"
attrs="{'invisible':['|', ('qty_to_deliver', '=', 0), ('qty_to_deliver', '&lt;', 0)]}"
type="action"
/>
<button
name="%(rma.action_rma_add_serial_wiz_customer)d"
string="Add Lot/Serial Numbers"
Expand All @@ -104,9 +90,24 @@
type="action"
attrs="{'invisible':[('type', '!=', 'customer')]}"
/>
<button
name="%(rma.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="%(rma.action_rma_picking_out)d"
string="Create Delivery"
class="oe_highlight"
attrs="{'invisible':['|', '|', ('qty_to_deliver', '=', 0), ('qty_to_deliver', '&lt;', 0), ('state', '!=', 'approved')]}"
type="action"
/>
<button
name="%(rma.action_make_supplier_rma)d"
string="Create Supplier RMA"
class="oe_highlight"
attrs="{'invisible':['|', ('type', '!=', 'customer'), ('state', '!=', 'approved')]}"
type="action"
/>
Expand All @@ -124,6 +125,7 @@
name="action_view_in_shipments"
class="oe_stat_button"
icon="fa-truck"
attrs="{'invisible': [('in_shipment_count', '=', 0)]}"
groups="stock.group_stock_user"
>
<field
Expand All @@ -137,6 +139,7 @@
name="action_view_out_shipments"
class="oe_stat_button"
icon="fa-truck"
attrs="{'invisible': [('out_shipment_count', '=', 0)]}"
groups="stock.group_stock_user"
>
<field
Expand All @@ -150,6 +153,7 @@
name="action_view_lines"
class="oe_stat_button"
icon="fa-list"
attrs="{'invisible': [('line_count', '=', 0)]}"
groups="rma.group_rma_customer_user"
>
<field name="line_count" widget="statinfo" string="RMA Lines" />
Expand Down
29 changes: 13 additions & 16 deletions rma_account/models/rma_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2017-22 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from odoo import api, fields, models
from odoo import _, api, fields, models


class RmaOrder(models.Model):
Expand Down Expand Up @@ -104,25 +104,22 @@ def _prepare_rma_data(self, partner, origin_rma):
return res

def action_view_invoice_refund(self):
move_ids = self.mapped("rma_line_ids.move_id").ids
move_ids = self.mapped("rma_line_ids.refund_line_ids.move_id").ids
form_view_ref = self.env.ref("account.view_move_form", False)
tree_view_ref = self.env.ref("account.view_move_tree", False)

return {
"domain": [("id", "in", move_ids)],
"name": "Refunds",
"res_model": "account.move",
"views": [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")],
}
action = self.env.ref("account.action_move_in_refund_type")
result = action.sudo().read()[0]
result["domain"] = [("id", "in", move_ids)]
result["views"] = [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")]
return result

def action_view_invoice(self):
move_ids = self.mapped("rma_line_ids.move_id").ids
form_view_ref = self.env.ref("account.view_move_form", False)
tree_view_ref = self.env.ref("account.view_move_tree", False)

return {
"domain": [("id", "in", move_ids)],
"name": "Originating Invoice",
"res_model": "account.move",
"views": [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")],
}
action = self.env.ref("account.action_move_out_invoice_type")
result = action.sudo().read()[0]
result["domain"] = [("id", "in", move_ids)]
result["views"] = [(tree_view_ref.id, "tree"), (form_view_ref.id, "form")]
result["name"] = _("Originating Invoice")
return result
13 changes: 6 additions & 7 deletions rma_account/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
<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">
<xpath
expr="//header/button[@name='%(rma.action_make_supplier_rma)d']"
position="after"
>
<button
name="%(rma_account.action_rma_refund)d"
string="Create Refund"
class="oe_highlight"
attrs="{'invisible':['|', '|', ('qty_to_refund', '=', 0), ('qty_to_refund', '&lt;', 0), ('state', '!=', 'approved')]}"
type="action"
/>
<button
name="%(rma_account.action_rma_refund)d"
string="Create Refund"
attrs="{'invisible':['|', ('qty_to_refund', '>', 0), ('state', '!=', 'approved')]}"
type="action"
/>
</xpath>
<button name="action_view_out_shipments" position="after">
<button
type="object"
name="action_view_invoice_refund"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible': [('invoice_refund_count', '=', 0)]}"
groups="account.group_account_invoice"
>
<field
Expand All @@ -39,6 +37,7 @@
name="action_view_invoice"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible': [('invoice_count', '=', 0)]}"
groups="account.group_account_invoice"
>
<field name="invoice_count" widget="statinfo" string="Origin Inv" />
Expand Down
13 changes: 3 additions & 10 deletions rma_account/wizards/rma_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def default_get(self, fields_list):
items = []
if active_model == "rma.order":
rma = rma_obj.browse(active_ids)
lines = rma.rma_line_ids
lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_refund > 0)
else:
lines = rma_line_obj.browse(active_ids)
if len(lines.mapped("partner_id")) > 1:
Expand Down Expand Up @@ -105,16 +105,9 @@ def compute_refund(self):
return new_refund

def invoice_refund(self):
rma_line_obj = self.env["rma.order.line"]
rma_obj = self.env["rma.order"]
active_ids = self.env.context.get("active_ids") or []
active_model = self.env.context.get("active_model")
if active_model == "rma.order":
rma = rma_obj.browse(active_ids)
lines = rma.rma_line_ids
else:
lines = rma_line_obj.browse(active_ids)
lines = self.item_ids.line_id
for line in lines:

if line.state != "approved":
raise ValidationError(_("RMA %s is not approved") % line.name)
new_invoice = self.compute_refund()
Expand Down
10 changes: 6 additions & 4 deletions rma_sale/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ class RmaOrder(models.Model):
"rma_line_ids.sale_line_id",
"rma_line_ids.sale_line_id.order_id",
)
def _compute_sales_count(self):
def _compute_src_sale_count(self):
for rma in self:
sales = rma.mapped("rma_line_ids.sale_line_id.order_id")
rma.sale_count = len(sales)
src_sales = rma.mapped("rma_line_ids.sale_line_id.order_id")
rma.src_sale_count = len(src_sales)

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

sale_count = fields.Integer(compute="_compute_sales_count", string="# of Sales")
src_sale_count = fields.Integer(
compute="_compute_src_sale_count", string="# of Origin Sales"
)
qty_to_sell = fields.Float(
digits="Product Unit of Measure",
compute="_compute_qty_to_sell",
Expand Down
20 changes: 11 additions & 9 deletions rma_sale/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@
<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">
<xpath
expr="//header/button[@name='%(rma.action_rma_add_stock_move_customer)d']"
position="after"
>
<button
name="%(rma_sale.action_rma_add_sale)d"
string="Add From Sale Order"
type="action"
attrs="{'invisible':[('type', '!=', 'customer')]}"
/>
</xpath>
<xpath
expr="//header/button[@name='%(rma_account.action_rma_refund)d']"
position="after"
>
<button
name="%(rma_sale.action_rma_make_sale_order)d"
string="Create Sales Quotation"
class="oe_highlight"
attrs="{'invisible':['|', '|', ('qty_to_sell', '=', 0), ('qty_to_sell', '&lt;', 0), ('state', '!=', 'approved')]}"
type="action"
/>
<button
name="%(rma_sale.action_rma_make_sale_order)d"
string="Create Sales Quotation"
attrs="{'invisible':['|', ('qty_to_sell', '>', 0), ('state', '!=', 'approved')]}"
type="action"
/>
</xpath>
<div name="button_box" position="inside">
<button
Expand All @@ -33,9 +35,9 @@
class="oe_stat_button"
icon="fa-pencil-square-o"
groups="sales_team.group_sale_salesman"
attrs="{'invisible':[('type', '!=', 'customer')]}"
attrs="{'invisible':['|', ('type', '!=', 'customer'), ('src_sale_count', '=', 0)]}"
>
<field name="sale_count" widget="statinfo" string="Origin SO" />
<field name="src_sale_count" widget="statinfo" string="Origin SO" />
</button>
</div>
<xpath expr="//field[@name='rma_line_ids']/tree" position="inside">
Expand Down
21 changes: 2 additions & 19 deletions rma_sale/wizards/rma_make_sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def default_get(self, fields_list):
items = []
if active_model == "rma.order":
rma = rma_obj.browse(active_ids)
lines = rma.rma_line_ids
lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_sell > 0)
else:
lines = rma_line_obj.browse(active_ids)
for line in lines:
Expand Down Expand Up @@ -161,9 +161,7 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
_description = "RMA Line Make Sale Order Item"

wiz_id = fields.Many2one(comodel_name="rma.make.sale.order", string="Wizard")
line_id = fields.Many2one(
comodel_name="rma.order.line", string="RMA Line", compute="_compute_line_id"
)
line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA Line")
rma_id = fields.Many2one(
comodel_name="rma.order", related="line_id.rma_id", readonly=False
)
Expand All @@ -176,21 +174,6 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
)
free_of_charge = fields.Boolean(string="Free of Charge")

def _compute_line_id(self):
rma_line_obj = self.env["rma.order.line"]
rma_obj = self.env["rma.order"]
active_ids = self.env.context.get("active_ids") or []
active_model = self.env.context.get("active_model")
for rec in self:
if not active_ids:
return
if active_model == "rma.order":
rma = rma_obj.browse(active_ids)
lines = rma.rma_line_ids
else:
lines = rma_line_obj.browse(active_ids)
rec.line_id = lines[0]

@api.onchange("product_id")
def onchange_product_id(self):
if self.product_id:
Expand Down

0 comments on commit 3d97216

Please sign in to comment.