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:
@@ -6,11 +6,15 @@ class InvoiceChangeWizard(models.TransientModel):
|
||||
_name = 'account.invoice.change'
|
||||
_description = 'Invoice Change'
|
||||
|
||||
move_id = fields.Many2one('account.move', string='Invoice', readonly=True, required=True)
|
||||
move_company_id = fields.Many2one('res.company', readonly=True, related='move_id.company_id')
|
||||
move_ids = fields.Many2many('account.move', string='Invoice', readonly=True, required=True)
|
||||
is_single_move = fields.Boolean(compute='_compute_move_company_id')
|
||||
move_company_id = fields.Many2one('res.company', readonly=True, compute='_compute_move_company_id')
|
||||
invoice_user_id = fields.Many2one('res.users', string='Salesperson')
|
||||
set_invoice_user_id = fields.Boolean()
|
||||
date = fields.Date(string='Accounting Date')
|
||||
set_date = fields.Boolean()
|
||||
invoice_date = fields.Date(string='Invoice Date')
|
||||
set_invoice_date = fields.Boolean()
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
@@ -28,24 +32,40 @@ class InvoiceChangeWizard(models.TransientModel):
|
||||
"Programmation error: the expected model for this action is 'account.move'. The provided one is '%d'.") % active_model)
|
||||
|
||||
# Checks on received invoice records
|
||||
invoice = self.env[active_model].browse(active_ids)
|
||||
if len(invoice) != 1:
|
||||
raise UserError(_("Invoice Change expects only one invoice."))
|
||||
rec.update({
|
||||
'move_id': invoice.id,
|
||||
'invoice_user_id': invoice.invoice_user_id.id,
|
||||
'date': invoice.date,
|
||||
'invoice_date': invoice.invoice_date,
|
||||
})
|
||||
invoices = self.env[active_model].browse(active_ids)
|
||||
if invoices.filtered(lambda i: not i.is_invoice()):
|
||||
raise UserError(_('Only invoices can be updated.'))
|
||||
if invoices.filtered(lambda i: i.state in ('draft', 'cancel')):
|
||||
raise UserError(_('Only posted invoices can be updated.'))
|
||||
if len(invoices.company_id) > 1:
|
||||
raise UserError(_('Selected invoices must be in the same company.'))
|
||||
rec['move_ids'] = [(6, 0, invoices.ids)]
|
||||
if len(invoices) == 1:
|
||||
rec.update({
|
||||
'set_invoice_user_id': True,
|
||||
'set_date': True,
|
||||
'set_invoice_date': True,
|
||||
'invoice_user_id': invoices.invoice_user_id.id,
|
||||
'date': invoices.date,
|
||||
'invoice_date': invoices.invoice_date,
|
||||
})
|
||||
return rec
|
||||
|
||||
@api.depends('move_ids')
|
||||
def _compute_move_company_id(self):
|
||||
for wiz in self:
|
||||
company = wiz.move_ids.company_id
|
||||
company.ensure_one()
|
||||
wiz.move_company_id = company
|
||||
wiz.is_single_move = len(wiz.move_ids) == 1
|
||||
|
||||
def _new_move_vals(self):
|
||||
vals = {}
|
||||
if self.move_id.invoice_user_id != self.invoice_user_id:
|
||||
if self.set_invoice_user_id:
|
||||
vals['invoice_user_id'] = self.invoice_user_id.id
|
||||
if self.move_id.date != self.date:
|
||||
if self.set_date:
|
||||
vals['date'] = self.date
|
||||
if self.move_id.invoice_date != self.invoice_date:
|
||||
if self.set_invoice_date:
|
||||
vals['invoice_date'] = self.invoice_date
|
||||
return vals
|
||||
|
||||
@@ -53,5 +73,5 @@ class InvoiceChangeWizard(models.TransientModel):
|
||||
self.ensure_one()
|
||||
vals = self._new_move_vals()
|
||||
if vals:
|
||||
self.move_id.write(vals)
|
||||
self.move_ids.write(vals)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user