Skip to content

Commit

Permalink
Merge PR #26 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Nov 26, 2024
2 parents 1f85949 + a88b4e0 commit e31b45b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
6 changes: 1 addition & 5 deletions ssi_rma/views/rma_mixin_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<xpath expr="//field[@name='user_id']" position="after">
<field name="type" invisible="1" />
<field name="operation_id" />
<field name="reason_id" />
<field
name="allowed_source_picking_type_category_ids"
widget="many2many_tags"
Expand Down Expand Up @@ -386,11 +387,6 @@
</group>
</group>
</page>
<page name="other" string="Other Info">
<group name="other_1" colspan="4" col="2">
<field name="reason_id" />
</group>
</page>
</xpath>
</field>
</record>
Expand Down
2 changes: 1 addition & 1 deletion ssi_rma_account/models/rma_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RMALineMixin(models.AbstractModel):
]

account_move_line_ids = fields.Many2many(
strng="Journal Item",
string="Journal Item",
comodel_name="account.move.line",
)
qty_to_refund = fields.Float(
Expand Down
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 e31b45b

Please sign in to comment.