[13.0][account_asset_management] button to navigate from the vendor bill
to the asset.
This commit is contained in:
parent
319042dc87
commit
cf6de3db86
@ -30,6 +30,14 @@ FIELDS_AFFECTS_ASSET_MOVE_LINE = {
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
asset_count = fields.Integer(compute='_compute_asset_count')
|
||||
|
||||
def _compute_asset_count(self):
|
||||
for rec in self:
|
||||
assets = self.env['account.asset.line'].search([
|
||||
('move_id', '=', self.id)]).mapped('asset_id')
|
||||
rec.asset_count = len(assets)
|
||||
|
||||
def unlink(self):
|
||||
# for move in self:
|
||||
deprs = self.env["account.asset.line"].search(
|
||||
@ -116,6 +124,21 @@ class AccountMove(models.Model):
|
||||
line_vals.update(asset_profile_id=False, asset_id=False)
|
||||
return move_vals
|
||||
|
||||
def action_view_assets(self):
|
||||
assets = self.env['account.asset.line'].search([
|
||||
('move_id', '=', self.id)]).mapped('asset_id')
|
||||
action = self.env.ref("account_asset_management.account_asset_action")
|
||||
action_dict = action.read()[0]
|
||||
if len(assets) == 1:
|
||||
res = self.env.ref("account_asset_management.account_asset_view_form", False)
|
||||
action_dict["views"] = [(res and res.id or False, "form")]
|
||||
action_dict["res_id"] = assets.id
|
||||
elif assets:
|
||||
action_dict["domain"] = [("id", "in", assets.ids)]
|
||||
else:
|
||||
action_dict = {"type": "ir.actions.act_window_close"}
|
||||
return action_dict
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
@ -378,6 +378,7 @@
|
||||
<record id="account_asset_action" model="ir.actions.act_window">
|
||||
<field name="name">Assets</field>
|
||||
<field name="res_model">account.asset</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="account_asset_view_tree" />
|
||||
<field name="search_view_id" ref="account_asset_view_search" />
|
||||
</record>
|
||||
|
@ -5,6 +5,18 @@
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[hasclass('oe_button_box')]" position="inside">
|
||||
<button name="action_view_assets"
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
icon="fa-cube"
|
||||
attrs="{'invisible': [('asset_count', '=', 0)]}">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="asset_count"/></span>
|
||||
<span class="o_stat_text"> Asset(s)</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath
|
||||
expr="//field[@name='invoice_line_ids']/tree/field[@name='quantity']"
|
||||
position="before"
|
||||
|
Loading…
Reference in New Issue
Block a user