[MIG] rma_account: Migration to 16.0

This commit is contained in:
DavidJForgeFlow
2023-02-22 15:10:07 +01:00
committed by AaronHForgeFlow
parent be491e68d8
commit 8c33885fbc
9 changed files with 41 additions and 62 deletions

View File

@@ -3,7 +3,7 @@
{
"name": "RMA Account",
"version": "15.0.1.2.0",
"version": "16.0.1.0.0",
"license": "LGPL-3",
"category": "RMA",
"summary": "Integrates RMA with Invoice Processing",

View File

@@ -47,11 +47,9 @@ class AccountMove(models.Model):
new_line.rma_line_id = rma_line
new_line.name = "%s: %s" % (
self.add_rma_line_id.name,
new_line._get_computed_name(),
new_line.name,
)
new_line.account_id = new_line._get_computed_account()
new_line._onchange_price_subtotal()
new_line._onchange_mark_recompute_taxes()
new_line.account_id = new_line.account_id
return True
@api.onchange("add_rma_line_id")
@@ -72,7 +70,6 @@ class AccountMove(models.Model):
origins = set(self.line_ids.mapped("rma_line_id.name"))
self.invoice_origin = ",".join(list(origins))
self.add_rma_line_id = False
self._onchange_currency()
rma_count = fields.Integer(compute="_compute_rma_count", string="# of RMA")
used_in_rma_count = fields.Integer(
@@ -224,7 +221,7 @@ class AccountMoveLine(models.Model):
invl.rma_line_count = len(rma_lines)
used_in_rma_line_count = fields.Integer(
compute="_compute_used_in_rma_line_count", string="# of RMA"
compute="_compute_used_in_rma_count", string="# of RMA"
)
rma_line_count = fields.Integer(compute="_compute_rma_count", string="# of RMA")
rma_line_ids = fields.One2many(

View File

@@ -82,7 +82,7 @@ class RmaOrderLine(models.Model):
string="Refund Lines",
domain=[
("move_id.move_type", "in", ["in_refund", "out_refund"]),
("exclude_from_invoice_tab", "=", False),
("display_type", "=", "product"),
],
copy=False,
index=True,
@@ -129,21 +129,19 @@ class RmaOrderLine(models.Model):
res["domain"] = {}
if not self.product_id:
domain = [
"&",
"|",
("move_id.partner_id", "=", self.partner_id.id),
("move_id.partner_id", "child_of", self.partner_id.id),
("exclude_from_invoice_tab", "=", False),
("display_type", "=", "product"),
]
res["domain"]["account_move_line_id"] = domain
else:
domain = [
"&",
"&",
"|",
("move_id.partner_id", "=", self.partner_id.id),
("move_id.partner_id", "child_of", self.partner_id.id),
("exclude_from_invoice_tab", "=", False),
("display_type", "=", "product"),
("product_id", "=", self.product_id.id),
]
res["domain"]["account_move_line_id"] = domain

View File

@@ -9,10 +9,10 @@ class StockMove(models.Model):
@api.model
def _prepare_account_move_line(
self, qty, cost, credit_account_id, debit_account_id, description
self, qty, cost, credit_account_id, debit_account_id, svl_id, description
):
res = super(StockMove, self)._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id, description
qty, cost, credit_account_id, debit_account_id, svl_id, description
)
for line in res:
if (

View File

@@ -18,7 +18,6 @@ class TestAccountMoveLineRmaOrderLine(common.TransactionCase):
cls.invoice_line_model = cls.env["account.move.line"]
cls.product_model = cls.env["product.product"]
cls.product_ctg_model = cls.env["product.category"]
cls.acc_type_model = cls.env["account.account.type"]
cls.account_model = cls.env["account.account"]
cls.aml_model = cls.env["account.move.line"]
cls.res_users_model = cls.env["res.users"]
@@ -35,21 +34,20 @@ class TestAccountMoveLineRmaOrderLine(common.TransactionCase):
cls.customer_location = cls.env.ref("stock.stock_location_customers")
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers")
# Create account for Goods Received Not Invoiced
acc_type = cls._create_account_type("equity", "other", "equity")
name = "Goods Received Not Invoiced"
code = "grni"
cls.account_grni = cls._create_account(acc_type, name, code, cls.company)
cls.account_grni = cls._create_account("equity", name, code, cls.company)
# Create account for Cost of Goods Sold
acc_type = cls._create_account_type("expense", "other", "expense")
name = "Goods Delivered Not Invoiced"
code = "gdni"
cls.account_cogs = cls._create_account(acc_type, name, code, cls.company)
cls.account_cogs = cls._create_account("expense", name, code, cls.company)
# Create account for Inventory
acc_type = cls._create_account_type("asset", "other", "asset")
name = "Inventory"
code = "inventory"
cls.account_inventory = cls._create_account(acc_type, name, code, cls.company)
cls.account_inventory = cls._create_account(
"asset_current", name, code, cls.company
) # TODO: poner asset de inventario
# Create Product
cls.product = cls._create_product()
cls.product_uom_id = cls.env.ref("uom.product_uom_unit")
@@ -81,13 +79,6 @@ class TestAccountMoveLineRmaOrderLine(common.TransactionCase):
)
return user.id
@classmethod
def _create_account_type(cls, name, account_type, internal_group):
acc_type = cls.acc_type_model.create(
{"name": name, "type": account_type, "internal_group": internal_group}
)
return acc_type
@classmethod
def _create_account(cls, acc_type, name, code, company, reconcile=False):
"""Create an account."""
@@ -95,7 +86,7 @@ class TestAccountMoveLineRmaOrderLine(common.TransactionCase):
{
"name": name,
"code": code,
"user_type_id": acc_type.id,
"account_type": acc_type,
"company_id": company.id,
"reconcile": reconcile,
}
@@ -254,7 +245,7 @@ class TestAccountMoveLineRmaOrderLine(common.TransactionCase):
else:
picking_ids = self.env["stock.picking"].search(res["domain"])
picking = self.env["stock.picking"].browse(picking_ids)
picking.move_lines.write({"quantity_done": 1.0})
picking.move_line_ids.write({"qty_done": 1.0})
picking.button_validate()
# decreasing cogs
expected_balance = -1.0

View File

@@ -24,7 +24,6 @@ class TestRmaAccount(common.SingleTransactionCase):
customer1_obj = cls.env["res.partner"]
cls.rma_route_cust = cls.env.ref("rma.route_rma_customer")
receivable_type = cls.env.ref("account.data_account_type_receivable")
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
@@ -88,7 +87,7 @@ class TestRmaAccount(common.SingleTransactionCase):
# Create Invoices:
cls.customer_account = cls.acc_obj.search(
[("user_type_id", "=", receivable_type.id)], limit=1
[("account_type", "=", "asset_receivable")], limit=1
).id
cls.invoices = cls.env["account.move"].create(
@@ -235,7 +234,8 @@ class TestRmaAccount(common.SingleTransactionCase):
def test_05_fill_rma_from_supplier_inv_line(self):
"""Test filling a RMA (line) from a invoice line."""
with Form(
self.rma_line_obj.with_context(default_type="supplier")
self.rma_line_obj.with_context(default_type="supplier"),
view="rma_account.view_rma_line_supplier_form",
) as rma_line_form:
rma_line_form.partner_id = self.inv_supplier.partner_id
rma_line_form.account_move_line_id = self.inv_supplier.line_ids[0]

View File

@@ -11,7 +11,6 @@ class TestRmaStockAccount(TestRma):
@classmethod
def setUpClass(cls):
super(TestRmaStockAccount, cls).setUpClass()
cls.acc_type_model = cls.env["account.account.type"]
cls.account_model = cls.env["account.account"]
cls.g_account_user = cls.env.ref("account.group_account_user")
cls.rma_refund_wiz = cls.env["rma.refund"]
@@ -31,21 +30,20 @@ class TestRmaStockAccount(TestRma):
# The product category created in the base module is not automated valuation
# we have to create a new category here
# Create account for Goods Received Not Invoiced
acc_type = cls._create_account_type("equity", "other")
name = "Goods Received Not Invoiced"
code = "grni"
cls.account_grni = cls._create_account(acc_type, name, code, cls.company, True)
cls.account_grni = cls._create_account("equity", name, code, cls.company, True)
# Create account for Goods Delievered
acc_type = cls._create_account_type("asset", "other")
name = "Goods Delivered Not Invoiced"
code = "gdni"
cls.account_gdni = cls._create_account(acc_type, name, code, cls.company, True)
cls.account_gdni = cls._create_account(
"asset_current", name, code, cls.company, True
)
# Create account for Inventory
acc_type = cls._create_account_type("asset", "other")
name = "Inventory"
code = "inventory"
cls.account_inventory = cls._create_account(
acc_type, name, code, cls.company, False
"asset_current", name, code, cls.company, False
)
product_ctg = cls.product_ctg_model.create(
{
@@ -65,13 +63,6 @@ class TestRmaStockAccount(TestRma):
cls.product_fifo_2.categ_id = product_ctg
cls.product_fifo_3.categ_id = product_ctg
@classmethod
def _create_account_type(cls, name, a_type):
acc_type = cls.acc_type_model.create(
{"name": name, "type": a_type, "internal_group": name}
)
return acc_type
@classmethod
def _create_account(cls, acc_type, name, code, company, reconcile):
"""Create an account."""
@@ -79,7 +70,7 @@ class TestRmaStockAccount(TestRma):
{
"name": name,
"code": code,
"user_type_id": acc_type.id,
"account_type": acc_type,
"company_id": company.id,
"reconcile": reconcile,
}
@@ -92,9 +83,9 @@ class TestRmaStockAccount(TestRma):
debit_line = account_move.mapped("line_ids").filtered(lambda l: l.debit)
credit_line = account_move.mapped("line_ids").filtered(lambda l: l.credit)
if debit_account:
self.assertEqual(debit_line.account_id.code, debit_account)
self.assertEqual(debit_line.account_id[0].code, debit_account)
if credit_account:
self.assertEqual(credit_line.account_id.code, credit_account)
self.assertEqual(credit_line.account_id[0].code, credit_account)
def test_01_cost_from_standard(self):
"""
@@ -108,8 +99,12 @@ class TestRmaStockAccount(TestRma):
rma_line = rma_line.save()
rma_line.action_rma_to_approve()
picking = self._receive_rma(rma_line)
self.assertEqual(picking.move_lines.stock_valuation_layer_ids.value, 15.0)
account_move = picking.move_lines.stock_valuation_layer_ids.account_move_id
self.assertEqual(
picking.move_line_ids.move_id.stock_valuation_layer_ids.value, 15.0
)
account_move = (
picking.move_line_ids.move_id.stock_valuation_layer_ids.account_move_id
)
self.check_accounts_used(
account_move, debit_account="inventory", credit_account="gdni"
)
@@ -145,10 +140,10 @@ class TestRmaStockAccount(TestRma):
# Test the value in the layers of the incoming stock move is used
for rma_line in rma_customer_id.rma_line_ids:
value_origin = rma_line.reference_move_id.stock_valuation_layer_ids.value
move_product = picking.move_lines.filtered(
move_product = picking.move_line_ids.filtered(
lambda l: l.product_id == rma_line.product_id
)
value_used = move_product.stock_valuation_layer_ids.value
value_used = move_product.move_id.stock_valuation_layer_ids.value
self.assertEqual(value_used, -value_origin)
# Create a refund for the first line
rma = rma_lines[0]
@@ -262,9 +257,9 @@ class TestRmaStockAccount(TestRma):
self.env.ref("rma.rule_rma_customer_out_pull").active = False
self.env.ref("rma.rule_rma_customer_in_pull").active = False
cust_in_pull_rule = self.customer_route.rule_ids.filtered(
lambda r: r.location_id == self.stock_rma_location
lambda r: r.location_dest_id == self.stock_rma_location
)
cust_in_pull_rule.location_id = self.input_location
cust_in_pull_rule.location_dest_id = self.input_location
cust_out_pull_rule = self.customer_route.rule_ids.filtered(
lambda r: r.location_src_id == self.env.ref("rma.location_rma")
)
@@ -276,7 +271,7 @@ class TestRmaStockAccount(TestRma):
"action": "pull",
"warehouse_id": self.wh.id,
"location_src_id": self.env.ref("rma.location_rma").id,
"location_id": self.output_location.id,
"location_dest_id": self.output_location.id,
"procure_method": "make_to_stock",
"route_id": self.customer_route.id,
"picking_type_id": self.env.ref("stock.picking_type_internal").id,
@@ -288,7 +283,7 @@ class TestRmaStockAccount(TestRma):
"action": "pull",
"warehouse_id": self.wh.id,
"location_src_id": self.customer_location.id,
"location_id": self.env.ref("rma.location_rma").id,
"location_dest_id": self.env.ref("rma.location_rma").id,
"procure_method": "make_to_order",
"route_id": self.customer_route.id,
"picking_type_id": self.env.ref("stock.picking_type_in").id,

View File

@@ -122,9 +122,7 @@ class RmaAddAccountMove(models.TransientModel):
def add_lines(self):
rma_line_obj = self.env["rma.order.line"]
existing_invoice_lines = self._get_existing_invoice_lines()
for line in self.line_ids.filtered(
lambda aml: aml.exclude_from_invoice_tab is False
):
for line in self.line_ids.filtered(lambda aml: aml.display_type == "product"):
# Load a PO line only once
if line not in existing_invoice_lines:
data = self._prepare_rma_line_from_inv_line(line)

View File

@@ -154,7 +154,7 @@ class RmaRefund(models.TransientModel):
"journal_id": journal.id,
"fiscal_position_id": rma_line.partner_id.property_account_position_id.id,
"state": "draft",
"currency_id": self._get_refund_currency(rma_line),
"currency_id": self._get_refund_currency(rma_line).id,
"date": wizard.date,
"invoice_date": wizard.date_invoice,
"partner_id": rma_line.invoice_address_id.id or rma_line.partner_id.id,