[MIG] account_invoice_change: migrate to 13.0

H4386
This commit is contained in:
Cedric Collins
2021-04-01 16:00:07 -05:00
parent eb73d4f562
commit f584fc7b9e
4 changed files with 60 additions and 68 deletions

View File

@@ -6,10 +6,11 @@ class InvoiceChangeWizard(models.TransientModel):
_name = 'account.invoice.change'
_description = 'Invoice Change'
invoice_id = fields.Many2one('account.invoice', string='Invoice', readonly=True, required=True)
invoice_company_id = fields.Many2one('res.company', readonly=True, related='invoice_id.company_id')
user_id = fields.Many2one('res.users', string='Salesperson')
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')
invoice_user_id = fields.Many2one('res.users', string='Salesperson')
date = fields.Date(string='Accounting Date')
invoice_date = fields.Date(string='Invoice Date')
@api.model
def default_get(self, fields):
@@ -22,35 +23,35 @@ class InvoiceChangeWizard(models.TransientModel):
if not active_model or not active_ids:
raise UserError(
_("Programmation error: wizard action executed without active_model or active_ids in context."))
if active_model != 'account.invoice':
if active_model != 'account.move':
raise UserError(_(
"Programmation error: the expected model for this action is 'account.invoice'. The provided one is '%d'.") % active_model)
"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({
'invoice_id': invoice.id,
'user_id': invoice.user_id.id,
'move_id': invoice.id,
'invoice_user_id': invoice.invoice_user_id.id,
'date': invoice.date,
'invoice_date': invoice.invoice_date,
})
return rec
def _new_invoice_vals(self):
def _new_move_vals(self):
vals = {}
if self.invoice_id.user_id != self.user_id:
vals['user_id'] = self.user_id.id
if self.invoice_id.date != self.date:
if self.move_id.invoice_user_id != self.invoice_user_id:
vals['invoice_user_id'] = self.invoice_user_id.id
if self.move_id.date != self.date:
vals['date'] = self.date
if self.move_id.invoice_date != self.invoice_date:
vals['invoice_date'] = self.invoice_date
return vals
@api.multi
def affect_change(self):
self.ensure_one()
vals = self._new_invoice_vals()
vals = self._new_move_vals()
if vals:
self.invoice_id.write(vals)
if 'date' in vals and self.invoice_id.move_id:
self.invoice_id.move_id.write({'date': vals['date']})
self.move_id.write(vals)
return True