[FIX] base: allow to archive companies via stat button
Once a branch company has some data associated with it, it can't be deleted anymore. Since the branches could only be opened in a dialog, it was also impossible to archive them. In order to allow (un)archiving a branch, we added a stat button on the company form to show the branches in a list view, where people can (un)archive them. task-3503204 Part-of: odoo/odoo#138942
This commit is contained in:
@@ -33,6 +33,7 @@ class Company(models.Model):
|
||||
sequence = fields.Integer(help='Used to order Companies in the company switcher', default=10)
|
||||
parent_id = fields.Many2one('res.company', string='Parent Company', index=True)
|
||||
child_ids = fields.One2many('res.company', 'parent_id', string='Branches')
|
||||
all_child_ids = fields.One2many('res.company', 'parent_id', context={'active_test': False})
|
||||
parent_path = fields.Char(index=True, unaccent=False)
|
||||
parent_ids = fields.Many2many('res.company', compute='_compute_parent_ids', compute_sudo=True)
|
||||
root_id = fields.Many2one('res.company', compute='_compute_parent_ids', compute_sudo=True)
|
||||
@@ -393,3 +394,17 @@ class Company(models.Model):
|
||||
len(self.env.companies.root_id) == 1
|
||||
and self.env.companies == self.env['res.company'].sudo().search([('id', 'child_of', self.env.company.root_id.ids)])
|
||||
)
|
||||
|
||||
def action_all_company_branches(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Branches'),
|
||||
'res_model': 'res.company',
|
||||
'domain': [('parent_id', '=', self.id)],
|
||||
'context': {
|
||||
'active_test': False,
|
||||
'default_parent_id': self.id,
|
||||
},
|
||||
'views': [[False, 'tree'], [False, 'kanban'], [False, 'form']],
|
||||
}
|
||||
|
||||
@@ -6,7 +6,16 @@
|
||||
<field name="model">res.company</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Company" duplicate="0">
|
||||
<field name="all_child_ids" invisible="1"/>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button class="oe_stat_button"
|
||||
name="action_all_company_branches"
|
||||
type="object"
|
||||
invisible="not all_child_ids"
|
||||
icon="fa-sitemap"
|
||||
string="Branches"/>
|
||||
</div>
|
||||
<field name="logo" widget="image" class="oe_avatar"/>
|
||||
<div class="oe_title">
|
||||
<label for="name"/>
|
||||
@@ -57,11 +66,12 @@
|
||||
<field name="name">res.company.tree</field>
|
||||
<field name="model">res.company</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Companies">
|
||||
<tree string="Companies" decoration-muted="not active">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="name"/>
|
||||
<field name="partner_id" required="0"/>
|
||||
<field name="child_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
|
||||
<field name="active" column_invisible="True"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user