Skip to content

Commit

Permalink
[ADD] smart button for sales in rma group
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Sep 23, 2024
1 parent 3d97216 commit 3b54408
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rma/wizards/rma_add_stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def default_get(self, fields_list):
move_ids = fields.Many2many(
comodel_name="stock.move",
string="Stock Moves",
domain="[('state', '=', 'done')]",
domain="[('state', '=', 'done'), ('partner_id', '=', partner_id)]",
)
show_lot_filter = fields.Boolean(
string="Show lot filter?",
Expand Down
20 changes: 19 additions & 1 deletion rma_sale/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def _compute_src_sale_count(self):
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.sale_line_ids",
"rma_line_ids.sale_line_ids.order_id",
)
def _compute_sale_count(self):
for rma in self:
sales = rma.mapped("rma_line_ids.sale_line_ids.order_id")
rma.sale_count = len(sales)

@api.depends("rma_line_ids", "rma_line_ids.qty_to_sell")
def _compute_qty_to_sell(self):
for rec in self:
Expand All @@ -28,6 +38,7 @@ def _compute_qty_to_sell(self):
digits="Product Unit of Measure",
compute="_compute_qty_to_sell",
)
sale_count = fields.Integer(compute="_compute_sale_count", string="# of Sales")

@api.model
def _get_line_domain(self, rma_id, line):
Expand All @@ -41,9 +52,16 @@ def _get_line_domain(self, rma_id, line):
domain = super(RmaOrder, self)._get_line_domain(rma_id, line)
return domain

def action_view_origin_sale_order(self):
action = self.env.ref("sale.action_orders")
result = action.sudo().read()[0]
so_ids = self.mapped("rma_line_ids.sale_line_id.order_id").ids
result["domain"] = [("id", "in", so_ids)]
return result

def action_view_sale_order(self):
action = self.env.ref("sale.action_quotations")
result = action.sudo().read()[0]
so_ids = self.mapped("rma_line_ids.sale_line_id.order_id").ids
so_ids = self.mapped("rma_line_ids.sale_line_ids.order_id").ids
result["domain"] = [("id", "in", so_ids)]
return result
8 changes: 4 additions & 4 deletions rma_sale/views/rma_order_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
/>
</header>
<div name='button_box' position="inside">
<button
<button
type="object"
name="action_view_sale_order"
name="action_view_origin_sale_order"
class="oe_stat_button"
icon="fa-strikethrough"
attrs="{'invisible': [('sale_id', '=', False)]}"
attrs="{'invisible': [('sale_line_id', '=', False)]}"
string="Origin Sale Order"
>
</button>
</button>
<button
type="object"
name="action_view_sale_order"
Expand Down
24 changes: 21 additions & 3 deletions rma_sale/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,31 @@
<div name="button_box" position="inside">
<button
type="object"
name="action_view_sale_order"
name="action_view_origin_sale_order"
class="oe_stat_button"
icon="fa-pencil-square-o"
groups="sales_team.group_sale_salesman"
attrs="{'invisible':['|', ('type', '!=', 'customer'), ('src_sale_count', '=', 0)]}"
attrs="{'invisible':[('src_sale_count', '=', 0)]}"
>
<field
name="src_sale_count"
widget="statinfo"
string="Origin Sale Order"
/>
</button>
<button
type="object"
name="action_view_sale_order"
class="oe_stat_button"
icon="fa-strikethrough"
attrs="{'invisible': [('sale_count', '=', 0)]}"
groups="sales_team.group_sale_salesman_all_leads"
>
<field name="src_sale_count" widget="statinfo" string="Origin SO" />
<field
name="sale_count"
widget="statinfo"
string="Sales Orders"
/>
</button>
</div>
<xpath expr="//field[@name='rma_line_ids']/tree" position="inside">
Expand Down

0 comments on commit 3b54408

Please sign in to comment.