[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

View File

@@ -7,9 +7,10 @@
<form string="Invoice Change">
<group>
<group name="group_left">
<field name="invoice_id" invisible="1"/>
<field name="invoice_company_id" invisible="1"/>
<field name="user_id"/>
<field name="move_id" invisible="1"/>
<field name="move_company_id" invisible="1"/>
<field name="invoice_user_id"/>
<field name="invoice_date"/>
<field name="date"/>
</group>
<group name="group_right"/>
@@ -26,21 +27,20 @@
<field name="name">Invoice Change Wizard</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.invoice.change</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record id="invoice_form_inherit" model="ir.ui.view">
<field name="name">account.invoice.form.inherit</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<record id="view_move_form_inherit" model="ir.ui.view">
<field name="name">account.move.form.inherit.invoice.change</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='state']" position="before">
<button name="%(action_view_account_invoice_change)d" string="Change"
type="action" class="btn-secondary"
attrs="{'invisible': [('state', 'in', ('sale', 'done', 'cancel'))]}"
context="{'default_invoice_id': id}"
attrs="{'invisible': ['|', ('state', 'in', ('sale', 'done', 'cancel')), ('type', 'not in', ('out_invoice', 'out_refund'))]}"
context="{'default_move_id': id}"
groups="account.group_account_manager" />
</xpath>
</field>