refactor: update asset code generation logic to iterate over all stock move lines instead of only those without packages

This commit is contained in:
Suherdy Yacob 2026-05-05 14:39:57 +07:00
parent 09e2125615
commit 47e67b8c10

View File

@ -7,7 +7,7 @@ class StockPicking(models.Model):
def action_generate_asset_codes(self): def action_generate_asset_codes(self):
self.ensure_one() self.ensure_one()
for move in self.move_ids_without_package: for move in self.move_ids:
# Only generate if product creates asset (optional check, but good practice) # Only generate if product creates asset (optional check, but good practice)
# However, user wants to manually decide, so we generate for all lines that look like assets? # However, user wants to manually decide, so we generate for all lines that look like assets?
# Let's assume user triggers this button for asset receipts. # Let's assume user triggers this button for asset receipts.
@ -32,7 +32,7 @@ class StockPicking(models.Model):
for pick in self: for pick in self:
has_asset = False has_asset = False
if pick.picking_type_code == 'incoming': if pick.picking_type_code == 'incoming':
for move in pick.move_ids_without_package: for move in pick.move_ids:
# Check if product is configured to create assets # Check if product is configured to create assets
# Logic: Check Product's Expense Account or Category's Expense Account # Logic: Check Product's Expense Account or Category's Expense Account
account = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id account = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id
@ -45,7 +45,7 @@ class StockPicking(models.Model):
# Validation Check # Validation Check
for pick in self: for pick in self:
if pick.has_asset_moves: if pick.has_asset_moves:
for move in pick.move_ids_without_package: for move in pick.move_ids:
account = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id account = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id
if account and account.create_asset != 'no' and not move.asset_code: if account and account.create_asset != 'no' and not move.asset_code:
raise UserError(_( raise UserError(_(
@ -60,7 +60,7 @@ class StockPicking(models.Model):
# After validation, create assets for moves with asset_code # After validation, create assets for moves with asset_code
for pick in self: for pick in self:
for move in pick.move_ids_without_package: for move in pick.move_ids:
if move.asset_code and not move.asset_id: if move.asset_code and not move.asset_id:
# Get Account to check configuration # Get Account to check configuration
account = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id account = move.product_id.property_account_expense_id or move.product_id.categ_id.property_account_expense_categ_id