Skip to content

Commit

Permalink
[UPD] changes from Shide
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-filament committed Dec 1, 2022
1 parent b033c60 commit aa61459
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
19 changes: 18 additions & 1 deletion account_move_update_analytic/views/account_move_line_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree" />
<field name="arch" type="xml">
<field name="analytic_account_id" position="after">
<field name="analytic_tag_ids" position="after">
<button
name="account_move_update_analytic.action_view_account_move_update_analytic"
string="Update Analytic"
type="action"
groups="analytic.group_analytic_accounting,analytic.group_analytic_tags"
attrs="{'invisible': [('parent_state', '!=', 'posted')]}"
/>
</field>
</field>
</record>

<record model="ir.ui.view" id="view_move_line_tree_grouped">
<field name="name">account.move.line.tree.grouped</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree_grouped" />
<field name="arch" type="xml">
<field name="analytic_tag_ids" position="after">
<button
name="account_move_update_analytic.action_view_account_move_update_analytic"
string="Update Analytic"
Expand Down
4 changes: 3 additions & 1 deletion account_move_update_analytic/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
expr="//field[@name='invoice_line_ids']/tree/field[@name='analytic_tag_ids']"
position="after"
>
<field name="parent_state" invisible="1" />
<button
name="account_move_update_analytic.action_view_account_move_update_analytic"
string="Update Analytic"
type="action"
groups="analytic.group_analytic_accounting,analytic.group_analytic_tags"
attrs="{'invisible': [('parent.state', '!=', 'posted'),]}"
attrs="{'invisible': [('parent.state', '!=', 'posted')]}"
/>
</xpath>
<xpath
expr="//field[@name='line_ids']/tree/field[@name='analytic_tag_ids']"
position="after"
>
<field name="parent_state" invisible="1" />
<button
name="account_move_update_analytic.action_view_account_move_update_analytic"
string="Update Analytic"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ class AccountMoveUpdateAnalytic(models.TransientModel):

@api.model
def default_get(self, fields):
rec = super(AccountMoveUpdateAnalytic, self).default_get(fields)
context = dict(self._context or {})
active_id = context.get("active_id", False)
rec = super().default_get(fields)
active_id = self.env.context.get("active_id", False)
aml = self.env["account.move.line"].browse(active_id)
rec.update(
{
Expand All @@ -40,14 +39,13 @@ def default_get(self, fields):
return rec

def update_analytic_lines(self):
self.ensure_one()
self.line_id.analytic_line_ids.unlink()
if self.user_has_groups("analytic.group_analytic_accounting"):
self.line_id.write(
{"analytic_account_id": self.new_analytic_account_id.id or False}
)
self.line_id.analytic_account_id = self.new_analytic_account_id.id
if self.user_has_groups("analytic.group_analytic_tags"):
self.line_id.write(
{"analytic_tag_ids": [(6, 0, self.new_analytic_tag_ids.ids or [])]}
{"analytic_tag_ids": [(6, 0, self.new_analytic_tag_ids.ids)]}
)
if self.new_analytic_account_id or self.new_analytic_tag_ids:
self.line_id.create_analytic_lines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
</group>
<group>
<field name="company_id" invisible="1" />
<field
name="new_analytic_account_id"
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]"
/>
<field name="new_analytic_account_id" />
</group>
</group>
<group string="Analytic Tags" groups="analytic.group_analytic_tags">
Expand All @@ -32,11 +29,7 @@
</group>
<group>
<field name="company_id" invisible="1" />
<field
name="new_analytic_tag_ids"
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]"
widget="many2many_tags"
/>
<field name="new_analytic_tag_ids" widget="many2many_tags" />
</group>
</group>
<footer>
Expand Down

0 comments on commit aa61459

Please sign in to comment.