mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] account_invoice_change,account_invoice_change_analytic: change multiple invoices
H12964
This commit is contained in:
@@ -5,6 +5,7 @@ class InvoiceChangeWizard(models.TransientModel):
|
||||
_inherit = 'account.invoice.change'
|
||||
|
||||
analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account')
|
||||
set_analytic_account_id = fields.Boolean()
|
||||
update_tags = fields.Selection(selection=[
|
||||
('no', 'Do not update tags'),
|
||||
('add', 'Add to tags'),
|
||||
@@ -21,11 +22,14 @@ class InvoiceChangeWizard(models.TransientModel):
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
rec = super(InvoiceChangeWizard, self).default_get(fields)
|
||||
invoice = self.env['account.move'].browse(rec['move_id'])
|
||||
rec.update({
|
||||
'analytic_account_id': self._analytic_account_id(invoice),
|
||||
'analytic_tag_ids': [(6, 0, invoice.invoice_line_ids.analytic_tag_ids.ids)],
|
||||
})
|
||||
context = dict(self._context or {})
|
||||
invoices = self.env['account.move'].browse(context.get('active_ids'))
|
||||
if len(invoices) == 1:
|
||||
rec.update({
|
||||
'set_analytic_account_id': True,
|
||||
'analytic_account_id': self._analytic_account_id(invoices),
|
||||
'analytic_tag_ids': [(6, 0, invoices.invoice_line_ids.analytic_tag_ids.ids)],
|
||||
})
|
||||
return rec
|
||||
|
||||
def affect_change(self):
|
||||
@@ -34,10 +38,9 @@ class InvoiceChangeWizard(models.TransientModel):
|
||||
return res
|
||||
|
||||
def _prepare_analytic_values(self):
|
||||
vals = {
|
||||
'analytic_account_id': self.analytic_account_id.id,
|
||||
'analytic_line_ids': [(5, 0, 0)],
|
||||
}
|
||||
vals = {}
|
||||
if self.set_analytic_account_id:
|
||||
vals['analytic_account_id'] = self.analytic_account_id.id
|
||||
tag_commands = []
|
||||
if self.update_tags == 'add':
|
||||
tag_commands = [(4, tag.id, 0) for tag in self.analytic_tag_ids]
|
||||
@@ -45,9 +48,13 @@ class InvoiceChangeWizard(models.TransientModel):
|
||||
tag_commands = [(6, 0, self.analytic_tag_ids.ids)]
|
||||
if tag_commands:
|
||||
vals['analytic_tag_ids'] = tag_commands
|
||||
if vals:
|
||||
vals['analytic_line_ids'] = [(5, 0, 0)]
|
||||
return vals
|
||||
|
||||
def _affect_analytic_change(self):
|
||||
lines_to_affect = self.move_id.invoice_line_ids
|
||||
lines_to_affect.write(self._prepare_analytic_values())
|
||||
lines_to_affect.create_analytic_lines()
|
||||
lines_to_affect = self.move_ids.invoice_line_ids
|
||||
vals = self._prepare_analytic_values()
|
||||
if vals:
|
||||
lines_to_affect.write(vals)
|
||||
lines_to_affect.create_analytic_lines()
|
||||
|
||||
Reference in New Issue
Block a user