mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] rma_account: add default journal
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Copyright 2017 ForgeFlow S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
@@ -17,3 +17,26 @@ class RmaOperation(models.Model):
|
||||
string="Refund Policy",
|
||||
default="no",
|
||||
)
|
||||
|
||||
refund_journal_id = fields.Many2one(
|
||||
comodel_name="account.journal",
|
||||
string="Refund Account Journal",
|
||||
domain="[('id', 'in', valid_refund_journal_ids)]",
|
||||
)
|
||||
|
||||
valid_refund_journal_ids = fields.Many2many(
|
||||
comodel_name="account.journal",
|
||||
compute="_compute_domain_valid_journal",
|
||||
)
|
||||
|
||||
@api.onchange("type")
|
||||
def _compute_domain_valid_journal(self):
|
||||
for rec in self:
|
||||
if rec.type == "customer":
|
||||
rec.valid_refund_journal_ids = self.env["account.journal"].search(
|
||||
[("type", "=", "sale")]
|
||||
)
|
||||
else:
|
||||
rec.valid_refund_journal_ids = self.env["account.journal"].search(
|
||||
[("type", "=", "purchase")]
|
||||
)
|
||||
|
||||
@@ -26,14 +26,28 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
cls.cust_refund_op = cls.env.ref("rma_account.rma_operation_customer_refund")
|
||||
cls.sup_refund_op = cls.env.ref("rma_account.rma_operation_supplier_refund")
|
||||
cls.company_id = cls.env.user.company_id
|
||||
|
||||
# Create partners
|
||||
customer1 = customer1_obj.create({"name": "Customer 1"})
|
||||
supplier1 = customer1_obj.create({"name": "Supplier 1"})
|
||||
|
||||
# Create Journal
|
||||
cls.journal_sale = cls.env["account.journal"].create(
|
||||
{
|
||||
"name": "Test Sales Journal",
|
||||
"code": "tSAL",
|
||||
"type": "sale",
|
||||
"company_id": cls.company_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
# Create RMA group and operation:
|
||||
cls.rma_group_customer = cls.rma_obj.create(
|
||||
{"partner_id": customer1.id, "type": "customer"}
|
||||
)
|
||||
cls.rma_group_customer_2 = cls.rma_obj.create(
|
||||
{"partner_id": customer1.id, "type": "customer"}
|
||||
)
|
||||
cls.rma_group_supplier = cls.rma_obj.create(
|
||||
{"partner_id": supplier1.id, "type": "supplier"}
|
||||
)
|
||||
@@ -224,3 +238,28 @@ class TestRmaAccount(common.SingleTransactionCase):
|
||||
rma._onchange_account_move_line_id()
|
||||
self.assertEqual(rma.product_id, self.product_1)
|
||||
self.assertEqual(rma.product_qty, 3.0)
|
||||
|
||||
def test_06_default_journal(self):
|
||||
self.operation_1.write({"refund_journal_id": self.journal_sale.id})
|
||||
add_inv = self.rma_add_invoice_wiz.with_context(
|
||||
{
|
||||
"customer": True,
|
||||
"active_ids": self.rma_group_customer_2.id,
|
||||
"active_model": "rma.order",
|
||||
}
|
||||
).create({"line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]})
|
||||
add_inv.add_lines()
|
||||
rma = self.rma_group_customer_2.rma_line_ids.filtered(
|
||||
lambda r: r.product_id == self.product_2
|
||||
)
|
||||
rma.action_rma_to_approve()
|
||||
rma.action_rma_approve()
|
||||
make_refund = self.rma_refund_wiz.with_context(
|
||||
{"customer": True, "active_ids": rma.ids, "active_model": "rma.order.line"}
|
||||
).create({"description": "Test refund"})
|
||||
make_refund.invoice_refund()
|
||||
rma.refund_line_ids.move_id.post()
|
||||
rma._compute_refund_count()
|
||||
self.assertEqual(
|
||||
self.operation_1.refund_journal_id, rma.refund_line_ids.journal_id
|
||||
)
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<field name="receipt_policy" position="before">
|
||||
<field name="refund_policy" />
|
||||
<field name="valid_refund_journal_ids" invisible="1" />
|
||||
<field name="refund_journal_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -128,7 +128,9 @@ class RmaRefund(models.TransientModel):
|
||||
@api.model
|
||||
def _prepare_refund(self, wizard, rma_line):
|
||||
# origin_invoices = self._get_invoice(rma_line)
|
||||
if rma_line.type == "customer":
|
||||
if rma_line.operation_id.refund_journal_id:
|
||||
journal = rma_line.operation_id.refund_journal_id
|
||||
elif rma_line.type == "customer":
|
||||
journal = self.env["account.journal"].search(
|
||||
[("type", "=", "sale")], limit=1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user