IMP: added init hook

This commit is contained in:
Christopher Ormaza
2022-01-28 10:23:09 -05:00
parent de2e3f5d2f
commit 77eeb3605f
3 changed files with 42 additions and 1 deletions

View File

@@ -7,4 +7,35 @@ _logger = logging.getLogger(__name__)
def post_init_hook(cr, registry):
api.Environment(cr, SUPERUSER_ID, {})
env = api.Environment(cr, SUPERUSER_ID, {})
aml_model = env["account.move.line"]
sm_model = env["stock.move"]
svl_model = env["stock.valuation.layer"]
aml_moves = aml_model.search([("rma_line_id", "!=", False)])
sm_moves = sm_model.search([("rma_line_id", "!=", False)])
for account_move in aml_moves.mapped("move_id"):
for aml_w_rma in account_move.invoice_line_ids.filtered(
lambda x: x.product_id
and x.account_id.id
!= x.product_id.categ_id.property_stock_valuation_account_id.id
and x.rma_line_id
):
invoice_lines_without_rma = account_move.invoice_line_ids.filtered(
lambda x: x.product_id.id == aml_w_rma.product_id.id
and not x.rma_line_id
and aml_w_rma.name in x.name
)
if invoice_lines_without_rma:
invoice_lines_without_rma.write(
{
"rma_line_id": aml_w_rma.rma_line_id.id,
}
)
for move in sm_moves:
current_layers = svl_model.search([("stock_move_id", "=", move.id)])
if current_layers:
for aml in current_layers.mapped("account_move_id.line_ids").filtered(
lambda x: x.account_id.id
!= move.product_id.categ_id.property_stock_valuation_account_id.id
):
aml.rma_line_id = move.rma_line_id.id

View File

@@ -16,4 +16,5 @@
"installable": True,
"maintainers": ["ChisOForgeFlow"],
"development_status": "Beta",
"post_init_hook": "post_init_hook",
}

View File

@@ -228,6 +228,9 @@ class TestAccountMoveLineRmaOrderLine(common.SavepointCase):
]
rma = self._create_rma(products2move, self.partner1)
rma_line = rma.rma_line_ids
for rma in rma_line:
if rma.price_unit == 0:
rma.price_unit = 1.0
rma_line.action_rma_approve()
wizard = self.rma_make_picking.with_context(
{
@@ -269,6 +272,12 @@ class TestAccountMoveLineRmaOrderLine(common.SavepointCase):
"description": "Test refund",
}
)
for item in make_refund.item_ids:
item.write(
{
"qty_to_refund": 1.0,
}
)
make_refund.invoice_refund()
rma_line.refund_line_ids.move_id.filtered(
lambda x: x.state != "posted"