[MIG] rma_analytic: migration to 14.0

This commit is contained in:
Juany Davila
2023-03-23 14:54:04 -05:00
committed by AaronHForgeFlow
parent d6f110304c
commit d3280921cb
4 changed files with 63 additions and 53 deletions

View File

@@ -15,6 +15,6 @@ class RmaOrderLine(models.Model):
def _prepare_rma_line_from_inv_line(self, line):
res = super(RmaOrderLine, self)._prepare_rma_line_from_inv_line(line)
if line.account_analytic_id:
res.update(analytic_account_id=line.account_analytic_id.id)
if line.analytic_account_id:
res.update(analytic_account_id=line.analytic_account_id.id)
return res

View File

@@ -1,6 +1,8 @@
# Copyright 2017-23 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import fields
from odoo.addons.rma.tests import test_rma
@@ -10,6 +12,30 @@ class TestRmaAnalytic(test_rma.TestRma):
super(TestRmaAnalytic, cls).setUpClass()
cls.rma_add_invoice_wiz = cls.env["rma_add_account_move"]
cls.rma_refund_wiz = cls.env["rma.refund"]
cls.rma_obj = cls.env["rma.order"]
cls.rma_op_obj = cls.env["rma.operation"]
cls.rma_route_cust = cls.env.ref("rma.route_rma_customer")
cls.cust_refund_op = cls.env.ref("rma_account.rma_operation_customer_refund")
cls.rma_group_customer = cls.rma_obj.create(
{"partner_id": cls.partner_id.id, "type": "customer"}
)
cls.operation_1 = cls.rma_op_obj.create(
{
"code": "TEST",
"name": "Refund and receive",
"type": "customer",
"receipt_policy": "ordered",
"refund_policy": "ordered",
"in_route_id": cls.rma_route_cust.id,
"out_route_id": cls.rma_route_cust.id,
}
)
cls.product_1.update(
{
"rma_customer_operation_id": cls.operation_1.id,
"rma_supplier_operation_id": cls.cust_refund_op.id,
}
)
products2move = [
(cls.product_1, 3),
(cls.product_2, 5),
@@ -21,30 +47,28 @@ class TestRmaAnalytic(test_rma.TestRma):
cls.env.ref("base.res_partner_2"),
dropship=False,
)
receivable_type = cls.env.ref("account.data_account_type_receivable")
# Create Invoices:
customer_account = (
cls.env["account.account"]
.search([("user_type_id", "=", receivable_type.id)], limit=1)
.id
)
cls.company_id = cls.env.user.company_id
cls.anal = cls.env["account.analytic.account"].create({"name": "Name"})
cls.inv_customer = cls.env["account.move"].create(
{
"partner_id": cls.partner_id.id,
"move_type": "out_invoice",
}
)
cls.anal = cls.env["account.analytic.account"].create({"name": "Name"})
cls.inv_line_1 = cls.env["account.move.line"].create(
{
"name": cls.partner_id.name,
"product_id": cls.product_1.id,
"quantity": 12.0,
"price_unit": 100.0,
"analytic_account_id": cls.anal.id,
"move_id": cls.inv_customer.id,
"product_uom_id": cls.product_1.uom_id.id,
"account_id": customer_account,
"invoice_date": fields.Date.from_string("2023-01-01"),
"currency_id": cls.company_id.currency_id,
"invoice_line_ids": [
(
0,
None,
{
"name": cls.partner_id.name,
"product_id": cls.product_1.id,
"product_uom_id": cls.product_1.uom_id.id,
"quantity": 12.0,
"price_unit": 100.0,
"analytic_account_id": cls.anal.id,
},
),
],
}
)
@@ -86,7 +110,7 @@ class TestRmaAnalytic(test_rma.TestRma):
"out_warehouse_id": self.env.ref("stock.warehouse0"),
"location_id": self.env.ref("stock.stock_location_stock"),
"type": "customer",
"account_move_line_id": self.inv_line_1.id,
"account_move_line_id": self.inv_customer.invoice_line_ids[0].id,
"uom_id": self.product_1.uom_id.id,
}
)
@@ -94,7 +118,7 @@ class TestRmaAnalytic(test_rma.TestRma):
rma_line._onchange_account_move_line_id()
self.assertEqual(
rma_line.analytic_account_id,
self.inv_line_1.analytic_account_id,
self.inv_customer.invoice_line_ids[0].analytic_account_id,
)
def test_invoice_analytic02(self):
@@ -124,33 +148,20 @@ class TestRmaAnalytic(test_rma.TestRma):
self.assertEqual(
rma_order.mapped("rma_line_ids.analytic_account_id"),
self.inv_line_1.analytic_account_id,
self.inv_customer.invoice_line_ids[0].analytic_account_id,
)
def test_refund_analytic(self):
self.product_1.rma_customer_operation_id = self.env.ref(
"rma_account.rma_operation_customer_refund"
).id
rma_line = (
self.env["rma.order.line"]
.with_context(customer=True)
.create(
{
"partner_id": self.partner_id.id,
"product_id": self.product_1.id,
"operation_id": self.env.ref(
"rma_account.rma_operation_customer_refund"
).id,
"in_route_id": self.env.ref("rma.route_rma_customer").id,
"out_route_id": self.env.ref("rma.route_rma_customer").id,
"in_warehouse_id": self.env.ref("stock.warehouse0").id,
"out_warehouse_id": self.env.ref("stock.warehouse0").id,
"location_id": self.env.ref("stock.stock_location_stock").id,
"type": "customer",
"account_move_line_id": self.inv_line_1.id,
"uom_id": self.product_1.uom_id.id,
}
)
add_inv = self.rma_add_invoice_wiz.with_context(
{
"customer": True,
"active_ids": self.rma_group_customer.id,
"active_model": "rma.order",
}
).create({"line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]})
add_inv.add_lines()
rma_line = self.rma_group_customer.rma_line_ids.filtered(
lambda r: r.product_id == self.product_1
)
rma_line._onchange_account_move_line_id()
rma_line.action_rma_to_approve()

View File

@@ -1,13 +1,12 @@
# Copyright 2018 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, models
from odoo import models
class RmaAddStockMove(models.TransientModel):
_inherit = "rma_add_stock_move"
@api.model
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
data = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move(sm, lot)
data.update(analytic_account_id=sm.analytic_account_id.id)

View File

@@ -8,8 +8,8 @@ class RmaRefund(models.TransientModel):
_inherit = "rma.refund"
@api.model
def prepare_refund_line(self, item, refund):
res = super(RmaRefund, self).prepare_refund_line(item, refund)
def prepare_refund_line(self, item):
res = super(RmaRefund, self).prepare_refund_line(item)
if item.line_id.analytic_account_id:
res.update(account_analytic_id=item.line_id.analytic_account_id.id)
res.update(analytic_account_id=item.line_id.analytic_account_id.id)
return res