[IMP] account_asset_management: set asset_profile_id on invoice creation
This commit is contained in:
parent
e629296c09
commit
9ca30734ac
@ -93,6 +93,8 @@ class AccountMove(models.Model):
|
|||||||
raise UserError(
|
raise UserError(
|
||||||
_("Asset name must be set in the label of the line.")
|
_("Asset name must be set in the label of the line.")
|
||||||
)
|
)
|
||||||
|
if aml.asset_id:
|
||||||
|
continue
|
||||||
asset_form = Form(
|
asset_form = Form(
|
||||||
self.env["account.asset"]
|
self.env["account.asset"]
|
||||||
.with_company(move.company_id)
|
.with_company(move.company_id)
|
||||||
@ -102,7 +104,9 @@ class AccountMove(models.Model):
|
|||||||
setattr(asset_form, key, val)
|
setattr(asset_form, key, val)
|
||||||
asset = asset_form.save()
|
asset = asset_form.save()
|
||||||
asset.analytic_tag_ids = aml.analytic_tag_ids
|
asset.analytic_tag_ids = aml.analytic_tag_ids
|
||||||
aml.with_context(allow_asset=True).asset_id = asset.id
|
aml.with_context(
|
||||||
|
allow_asset=True, allow_asset_removal=True
|
||||||
|
).asset_id = asset.id
|
||||||
refs = [
|
refs = [
|
||||||
"<a href=# data-oe-model=account.asset data-oe-id=%s>%s</a>"
|
"<a href=# data-oe-model=account.asset data-oe-id=%s>%s</a>"
|
||||||
% tuple(name_get)
|
% tuple(name_get)
|
||||||
@ -157,6 +161,9 @@ class AccountMoveLine(models.Model):
|
|||||||
asset_profile_id = fields.Many2one(
|
asset_profile_id = fields.Many2one(
|
||||||
comodel_name="account.asset.profile",
|
comodel_name="account.asset.profile",
|
||||||
string="Asset Profile",
|
string="Asset Profile",
|
||||||
|
compute="_compute_asset_profile",
|
||||||
|
store=True,
|
||||||
|
readonly=False,
|
||||||
)
|
)
|
||||||
asset_id = fields.Many2one(
|
asset_id = fields.Many2one(
|
||||||
comodel_name="account.asset",
|
comodel_name="account.asset",
|
||||||
@ -164,11 +171,13 @@ class AccountMoveLine(models.Model):
|
|||||||
ondelete="restrict",
|
ondelete="restrict",
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.onchange("account_id")
|
@api.depends("account_id", "asset_id")
|
||||||
def _onchange_account_id(self):
|
def _compute_asset_profile(self):
|
||||||
if self.account_id.asset_profile_id:
|
for rec in self:
|
||||||
self.asset_profile_id = self.account_id.asset_profile_id
|
if rec.account_id.asset_profile_id and not rec.asset_id:
|
||||||
super()._onchange_account_id()
|
rec.asset_profile_id = rec.account_id.asset_profile_id
|
||||||
|
elif rec.asset_id:
|
||||||
|
rec.asset_profile_id = rec.asset_id.profile_id
|
||||||
|
|
||||||
@api.onchange("asset_profile_id")
|
@api.onchange("asset_profile_id")
|
||||||
def _onchange_asset_profile_id(self):
|
def _onchange_asset_profile_id(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user