Skip to content

Commit

Permalink
[UPD] ssi_rma_account
Browse files Browse the repository at this point in the history
* Menambahkan info num of refund
* Menambahkan fungsionalitas untuk membuka refunds dari form rma
  • Loading branch information
andhit-r committed Nov 26, 2024
1 parent 12d482f commit 959635f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ssi_rma_account/models/rma_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ class RMAMixin(models.AbstractModel):
compute="_compute_stock_valuation_layer_ids",
store=False,
)
refund_ids = fields.Many2many(
string="Refunds",
comodel_name="account.move",
compute="_compute_refund_document_ids",
store=False,
compute_sudo=True,
)
num_of_refund = fields.Integer(
string="Num. of Refund",
compute="_compute_refund_document_ids",
store=True,
compute_sudo=True,
)

@api.depends(
"line_ids",
Expand All @@ -93,6 +106,21 @@ def _compute_stock_valuation_layer_ids(self):
"line_ids.stock_move_ids.stock_valuation_layer_ids"
)

@api.depends(
"line_ids",
"line_ids.account_move_line_ids",
"line_ids.account_move_line_ids.move_id",
"line_ids.account_move_line_ids.move_id.state",
)
def _compute_refund_document_ids(self):
for record in self:
num_of_refund = 0
record.refund_ids = record.mapped("line_ids.account_move_line_ids.move_id")
num_of_refund = len(
record.refund_ids.filtered(lambda r: r.state == "posted")
)
record.num_of_refund = num_of_refund

@api.depends(
"line_ids",
"line_ids.refund_complete",
Expand Down Expand Up @@ -198,6 +226,25 @@ def action_create_refund(self):
for record in self.sudo():
record._create_refund()

def action_open_refund(self):
for record in self.sudo():
result = record._open_refund()
return result

def _open_refund(self):
self.ensure_one()
if self._name == "rma_customer":
waction = self.env.ref("account.action_move_out_refund_type").read()[0]
elif self._name == "rma_supplier":
waction = self.env.ref("account.action_move_in_refund_type").read()[0]

waction.update(
{
"domain": [("id", "in", self.refund_ids.ids)],
}
)
return waction

def _create_refund(self):
self.ensure_one()
data = self._prepare_refund_data()
Expand Down
15 changes: 15 additions & 0 deletions ssi_rma_account/views/rma_customer_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@
<field name="inherit_id" ref="ssi_rma.rma_customer_view_form" />
<field name="arch" type="xml">
<data>
<xpath expr="//button[@name='action_open_delivery']" position="after">
<button
name="action_open_refund"
class="oe_stat_button"
type="object"
icon="fa-money"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="num_of_refund" />
</span>
<span class="o_stat_text">Refund</span>
</div>
</button>
</xpath>
<xpath expr="//field[@name='rma_state']" position="after">
<button
name="%(link_journal_item_rma_line_action)d"
Expand Down
15 changes: 15 additions & 0 deletions ssi_rma_account/views/rma_supplier_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@
<field name="inherit_id" ref="ssi_rma.rma_supplier_view_form" />
<field name="arch" type="xml">
<data>
<xpath expr="//button[@name='action_open_delivery']" position="after">
<button
name="action_open_refund"
class="oe_stat_button"
type="object"
icon="fa-money"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="num_of_refund" />
</span>
<span class="o_stat_text">Refund</span>
</div>
</button>
</xpath>
<xpath expr="//field[@name='rma_state']" position="after">
<button
name="%(link_journal_item_rma_line_action)d"
Expand Down

0 comments on commit 959635f

Please sign in to comment.