[FIX] runbot_merge: cancel button on staging

* split action_cancel (UI button) from cancel (internal): since the
  xhr mapping is weird, if there are available args the mapper thinks
  it should pass the call context as reason which is unexpected
* make cancel a no-op when called on already inactive stagings
* make cancel work when called on multiple statgings
* make computing the active staging work properly in an
  active_test=False context (e.g. when it's interacted with from the
  form view because that comes from the list view which is
  active_test=False, probably so we can see not just the stagings but
  recursively see deactivated batches in deactivated stagings)
* don't show the cancel button on inactive stagings
This commit is contained in:
Xavier Morel 2019-08-27 12:28:53 +02:00
parent b1b959d472
commit ef24adad88
2 changed files with 12 additions and 7 deletions

View File

@ -262,7 +262,7 @@ class Branch(models.Model):
@api.depends('staging_ids.active')
def _compute_active_staging(self):
for b in self:
b.active_staging_id = b.staging_ids
b.active_staging_id = b.with_context(active_test=True).staging_ids
def _stageable(self):
# noinspection SqlResolve
@ -1327,15 +1327,17 @@ class Stagings(models.Model):
s.state = st
@api.multi
def cancel(self, reason=None, *args):
def action_cancel(self):
self.cancel("explicitly cancelled by %s", self.env.user.display_name)
return { 'type': 'ir.actions.act_window_close' }
def cancel(self, reason, *args):
self = self.filtered('active')
if not self:
return
if reason is None:
reason = "explicitly cancelled by %s"
args = [self.env.user.display_name]
_logger.info("Cancelling staging %s: " + reason, self, *args)
self.batch_ids.write({'active': False})
self.mapped('batch_ids').write({'active': False})
self.write({
'active': False,
'state': 'cancelled',

View File

@ -189,8 +189,11 @@
<field name="model">runbot_merge.stagings</field>
<field name="arch" type="xml">
<form>
<field name="active" invisible="1"/>
<header>
<button type="object" name="cancel" string="Cancel" class="oe_highlight"/>
<button type="object" name="action_cancel" string="Cancel" class="oe_highlight"
attrs="{'invisible': [('active', '=', False)]}"
/>
</header>
<sheet>
<group>