Match product with corresponding asset when creating bill (account.move)

This commit is contained in:
younes 2025-05-11 09:28:13 +01:00
parent 6295ee43a8
commit 97ae3e0efd
2 changed files with 10 additions and 6 deletions

View File

@ -66,11 +66,11 @@ class AccountAsset(models.Model):
string='Prorata Date',
readonly=True, states={'draft': [('readonly', False)]}, tracking=True)
account_asset_id = fields.Many2one('account.account', string='Fixed Asset Account', tracking=True,
compute='_compute_value',
help="Account used to record the purchase of the asset at its original price.",
store=True,
states={'draft': [('readonly', False)], 'model': [('readonly', False)]},
domain="[('company_id', '=', company_id), ('is_off_balance', '=', False),('internal_type','!=','view')]")
compute='_compute_value',
help="Account used to record the purchase of the asset at its original price.",
store=True,
states={'draft': [('readonly', False)], 'model': [('readonly', False)]},
domain="[('company_id', '=', company_id), ('is_off_balance', '=', False),('internal_type','!=','view')]")
account_depreciation_id = fields.Many2one('account.account', string='Depreciation Account', tracking=True,
readonly=True,
states={'draft': [('readonly', False)], 'model': [('readonly', False)]},
@ -146,6 +146,8 @@ class AccountAsset(models.Model):
first_depreciation_date_import = fields.Date(
help="In case of an import from another software, provide the first depreciation date in it.")
product_id = fields.Many2one(comodel_name='product.product', readonly=True, tracking=True)
@api.depends('depreciation_move_ids.date', 'state')
def _compute_disposal_date(self):
for asset in self:
@ -694,7 +696,8 @@ class AccountAsset(models.Model):
if changes:
asset.message_post(body=_('Asset sold or disposed. Accounting entry awaiting for validation.'),
tracking_value_ids=tracking_value_ids)
move_ids += self.env['account.move'].sudo().search([('asset_id', '=', asset.id), ('state', '=', 'draft')]).ids
move_ids += self.env['account.move'].sudo().search(
[('asset_id', '=', asset.id), ('state', '=', 'draft')]).ids
return move_ids

View File

@ -146,6 +146,7 @@ class AccountMove(models.Model):
vals = {
'name': move_line.name,
'company_id': move_line.company_id.id,
'product_id': move_line.product_id.id,
'currency_id': move_line.company_currency_id.id,
'account_analytic_id': move_line.analytic_account_id.id,
'analytic_tag_ids': [(6, False, move_line.analytic_tag_ids.ids)],