Skip to content

Commit

Permalink
[ADD] ssi_rma_account
Browse files Browse the repository at this point in the history
  • Loading branch information
andhit-r committed Jan 4, 2024
1 parent 23fb998 commit c3ddeee
Show file tree
Hide file tree
Showing 17 changed files with 826 additions and 0 deletions.
46 changes: 46 additions & 0 deletions ssi_rma_account/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

============================
RMA + Accounting Integration
============================


Installation
============

To install this module, you need to:

1. Clone the branch 14.0 of the repository https://github.com/open-synergy/ssi-rma
2. Add the path to this repository in your configuration (addons-path)
3. Update the module list (Must be on developer mode)
4. Go to menu *Apps -> Apps -> Main Apps*
5. Search For *RMA + Accounting Integration*
6. Install the module

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/open-synergy/ssi-rma/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.


Credits
=======

Contributors
------------

* Andhitia Rama <[email protected]>

Maintainer
----------

.. image:: https://simetri-sinergi.id/logo.png
:alt: PT. Simetri Sinergi Indonesia
:target: https://simetri-sinergi.id.com

This module is maintained by the PT. Simetri Sinergi Indonesia.
7 changes: 7 additions & 0 deletions ssi_rma_account/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
models,
)
24 changes: 24 additions & 0 deletions ssi_rma_account/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "RMA + Accounting Integration",
"version": "14.0.1.0.0",
"website": "https://simetri-sinergi.id",
"author": "PT. Simetri Sinergi Indonesia, OpenSynergy Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": ["ssi_rma", "ssi_financial_accounting"],
"data": [
"data/rma_policy_field_data.xml",
"data/rma_policy_data.xml",
"views/rma_operation_views.xml",
"views/rma_customer_views.xml",
"views/rma_supplier_views.xml",
# "data/rma_policy_field_data.xml",
# "data/rma_policy_data.xml",
],
"demo": [],
"images": [],
}
67 changes: 67 additions & 0 deletions ssi_rma_account/data/rma_policy_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 OpenSynergy Indonesia
Copyright 2023 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<record id="rma_policy_ordered_refunded" model="rma_policy">
<field name="name">Based on Ordered - Refunded Quantities</field>
<field name="code">T007</field>
<field name="active" eval="1" />
<field name="rma_type">both</field>
<field name="refund_policy_ok" eval="1" />
</record>
<record id="rma_policy_rule_ordered_refunded_1" model="rma_policy_rule">
<field name="sequence" eval="1" />
<field name="operator">+</field>
<field name="policy_field_id" ref="ssi_rma.rma_policy_field_ordered" />
<field name="policy_id" ref="rma_policy_ordered_refunded" />
</record>
<record id="rma_policy_rule_ordered_refunded_2" model="rma_policy_rule">
<field name="sequence" eval="2" />
<field name="operator">-</field>
<field name="policy_field_id" ref="rma_policy_field_refund" />
<field name="policy_id" ref="rma_policy_ordered_refunded" />
</record>

<record id="rma_policy_delivered_refunded" model="rma_policy">
<field name="name">Based on Delivered - Received Quantities</field>
<field name="code">T008</field>
<field name="active" eval="1" />
<field name="rma_type">both</field>
<field name="refund_policy_ok" eval="1" />
</record>
<record id="rma_policy_rule_delivered_refunded_1" model="rma_policy_rule">
<field name="sequence" eval="1" />
<field name="operator">+</field>
<field name="policy_field_id" ref="ssi_rma.rma_policy_field_delivered" />
<field name="policy_id" ref="rma_policy_delivered_refunded" />
</record>
<record id="rma_policy_rule_delivered_refunded_2" model="rma_policy_rule">
<field name="sequence" eval="2" />
<field name="operator">-</field>
<field name="policy_field_id" ref="rma_policy_field_refund" />
<field name="policy_id" ref="rma_policy_delivered_refunded" />
</record>

<record id="rma_policy_received_refunded" model="rma_policy">
<field name="name">Based on Received - Refunded Quantities</field>
<field name="code">T009</field>
<field name="active" eval="1" />
<field name="rma_type">both</field>
<field name="refund_policy_ok" eval="1" />
</record>
<record id="rma_policy_rule_received_refunded_1" model="rma_policy_rule">
<field name="sequence" eval="1" />
<field name="operator">+</field>
<field name="policy_field_id" ref="ssi_rma.rma_policy_field_received" />
<field name="policy_id" ref="rma_policy_received_refunded" />
</record>
<record id="rma_policy_rule_received_refunded_2" model="rma_policy_rule">
<field name="sequence" eval="2" />
<field name="operator">-</field>
<field name="policy_field_id" ref="rma_policy_field_refund" />
<field name="policy_id" ref="rma_policy_received_refunded" />
</record>
</data>
</odoo>
13 changes: 13 additions & 0 deletions ssi_rma_account/data/rma_policy_field_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 OpenSynergy Indonesia
Copyright 2023 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<record id="rma_policy_field_refund" model="rma_policy_field">
<field name="name">Refunded</field>
<field name="code">qty_refund</field>
<field name="active" eval="1" />
</record>
</data>
</odoo>
13 changes: 13 additions & 0 deletions ssi_rma_account/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
rma_operation,
rma_policy,
rma_mixin,
rma_supplier,
rma_line_mixin,
rma_customer_line,
rma_supplier_line,
)
19 changes: 19 additions & 0 deletions ssi_rma_account/models/rma_customer_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class RMACustomerLine(models.Model):
_name = "rma_customer_line"
_inherit = [
"rma_line_mixin",
"rma_customer_line",
]

account_move_line_ids = fields.Many2many(
relation="rel_rma_customer_line_2_aml",
column1="rma_line_id",
column2="account_move_line_id",
)
139 changes: 139 additions & 0 deletions ssi_rma_account/models/rma_line_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class RMALineMixin(models.AbstractModel):
_name = "rma_line_mixin"
_inherit = [
"rma_line_mixin",
]

account_move_line_ids = fields.Many2many(
strng="Journal Item",
comodel_name="account.move.line",
)
qty_to_refund = fields.Float(
string="Qty to Refund", compute="_compute_qty_to_refund", store=True
)
qty_refund = fields.Float(
string="Qty Refunded",
compute="_compute_qty_refund",
)
need_refund = fields.Boolean(
string="Need Refund",
compute="_compute_need_refund",
store=True,
)
percent_refund = fields.Float(
string="Percent Refund",
compute="_compute_percent_refund",
store=True,
)
refund_complete = fields.Boolean(
string="Refund Complete",
compute="_compute_refund_complete",
store=True,
)

@api.depends(
"uom_quantity",
"qty_refund",
)
def _compute_percent_refund(self):
for record in self:
result = 0.0
try:
result = record.qty_refund / record.uom_quantity
except ZeroDivisionError:
result = 0.0
record.percent_refund = result

@api.depends(
"order_id",
"order_id.operation_id",
)
def _compute_need_refund(self):
for record in self:
result = False
if (
record.order_id.operation_id
and record.order_id.operation_id.refund_policy_id
and len(record.order_id.operation_id.refund_policy_id.rule_ids) > 0
):
result = True
record.need_refund = result

@api.depends(
"need_refund",
"percent_refund",
)
def _compute_refund_complete(self):
for record in self:
result = False
if (
record.need_refund and record.percent_refund == 1.0
) or not record.need_refund:
result = True
record.refund_complete = result

@api.model
def _get_qty_field_trigger(self):
_super = super(RMALineMixin, self)
result = _super._get_qty_field_trigger()
result += ["qty_refund"]
return result

@api.depends(lambda self: self._get_qty_field_trigger())
def _compute_qty_to_refund(self):
for record in self:
result = 0.0
if record.order_id.operation_id.refund_policy_id:
policy = record.order_id.operation_id.refund_policy_id
result = policy._compute_quantity(record)
record.qty_to_refund = result

@api.depends(
"account_move_line_ids",
"account_move_line_ids.move_id.state",
"account_move_line_ids.quantity",
)
def _compute_qty_refund(self):
for record in self:
result = 0.0
for line in record.account_move_line_ids:
if line.move_id.state == "posted":
result += line.quantity
record.qty_refund = result

def _create_refund_line(self, move):
self.ensure_one()
data = self._prepare_refund_line(move)
AML = self.env["account.move.line"]
line = AML.with_context(check_move_validity=False).create(data)
line.move_id.with_context(
check_move_validity=False
)._move_autocomplete_invoice_lines_values()
self.write({"account_move_line_ids": [(4, line.id)]})

def _prepare_refund_line(self, move):
self.ensure_one()
account = self.product_id._get_product_account(
usage_code=self.order_id.usage_id.code
)
tax_ids = self.product_id._get_product_tax(
usage_code=self.order_id.usage_id.code
)
data = {
"move_id": move.id,
"product_id": self.product_id.id,
"name": self.name,
"account_id": account.id,
"quantity": self.uom_quantity,
"product_uom_id": self.uom_id.id,
"price_unit": self.price_unit,
"tax_ids": [(6, 0, tax_ids)],
}
return data
Loading

0 comments on commit c3ddeee

Please sign in to comment.